Create transparent image assets on your own GPU
Generate a transparent PNG with Qwen-Image 2.1, confirm its alpha channel, and keep the image pipeline on your own GPU.
Before you begin
- Difficulty
- Advanced
- Software
- Python, PyTorch, Diffusers
- Hardware
- The publisher provides a CUDA example and a CPU-offload option, but no measured minimum for the complete transformer, text encoder, and VAE. Rent a suitable GPU if your machine cannot load them.
Sources and files
Qwen-Image 2.1 official quick start and RGBA exampleChoose a model for this task
The steps below use the recommended model. Alternatives have their own package and command; open their model pages before switching.
The workflow
Prepare a CUDA Python environment
Use a recent NVIDIA CUDA machine or rented GPU with enough memory for the full image pipeline. The model card documents Python, PyTorch 2.4 or newer, Transformers 5.17 or newer, and Diffusers from source.
Install the publisher dependencies
In a fresh Python environment install the required packages. Diffusers source is needed until its released package includes QwenImage21Pipeline.
pip install "torch>=2.4.0" "transformers>=5.17" accelerate pillow && pip install git+https://github.com/huggingface/diffusersCreate a small generation script
Save the following publisher-derived example as transparent_asset.py. It requests RGBA output and writes a PNG. The first run downloads the large model components.
import torch
from diffusers import QwenImage21Pipeline
pipe = QwenImage21Pipeline.from_pretrained(
"Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16
).to("cuda")
image = pipe(
prompt="This is an RGBA image with transparency. A cute cartoon dragon sticker. The image has alpha channel and the background is transparent.",
width=2048, height=2048, num_inference_steps=40,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("transparent_asset.png")Generate the asset
Run the script on the GPU machine. Start with the publisher example before changing size, steps, or prompt.
python transparent_asset.pyVerify actual transparency
Open transparent_asset.png in an editor that shows a checkerboard background. Inspect the alpha channel as well; a white-looking background alone does not prove transparency.
python -c "from PIL import Image; im=Image.open('transparent_asset.png'); print(im.mode, im.getextrema()[-1] if im.mode=='RGBA' else 'no alpha')"Adapt for your task
Replace the dragon with your asset description while retaining the publisher’s explicit RGBA and transparent-background wording. Check the edges against dark and light backgrounds before use.
When it doesn’t go to plan
Install Diffusers from the official source as shown above and confirm the installed Transformers version is at least 5.17.
The publisher documents pipe.enable_model_cpu_offload() after loading the pipeline as an alternative to .to("cuda"). It is slower and still needs substantial system RAM; reduce other GPU load or use a larger rented GPU.
Confirm the prompt requests an RGBA image with a transparent background, save as PNG, and inspect the alpha channel rather than trusting the preview background.
The model behind this workflow
Qwen-Image 2.1Will it run on your machine?
Save your machine to see a personalized rating and its reasoning.
Add my hardwareKeep exploring
Set up a private AI chat assistant
Install a local runtime, run Qwen3.5 9B, confirm responses, and know when to choose the smaller 4B package.
Build a private local coding assistant
Connect an open coding-capable model in Ollama to Cline, run a small repository task, and review the result locally.
Generate images on your own GPU
Use the official FLUX.2 Klein 4B ComfyUI template with exact model files, a first prompt, and an output check.