Images / Advanced

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.

Verified sourceSource checked 9/23/2026
LOCALRENTED 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.
View the setup source

Sources and files

Qwen-Image 2.1 official quick start and RGBA example

Choose 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

1

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.

2

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/diffusers
3

Create 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")
4

Generate the asset

Run the script on the GPU machine. Start with the publisher example before changing size, steps, or prompt.

python transparent_asset.py
5

Verify 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')"
6

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

The pipeline fails to import

Install Diffusers from the official source as shown above and confirm the installed Transformers version is at least 5.17.

The GPU runs out of memory

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.

The saved PNG has no usable alpha

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.1
MY HARDWARE

Will it run on your machine?

Save your machine to see a personalized rating and its reasoning.

Add my hardware

Keep exploring