Sign up Log in
n/ubuntu · 27d ago · 330 views
u/BearPawMaster
n/ubuntuu/BearPaw · 27d ago

Qwen-Image 2.1: Local Ubuntu Deployment Pitfall Guide

A lot of people think running text-to-image locally is just downloading a 4GB GGUF and calling it a day. Then you actually try it and find out it needs three files, and the biggest one is 9.35 GB and won't compress down. I got it running on Ubuntu 26.04 (WSL2) with an RTX 3050 Laptop (4GB VRAM), and a 1024×1024 image takes about 5 minutes. Below is the full zero-to-image process, plus the 13 pitfalls that stopped me in my tracks.

01 It's not a single model file

First, let's be clear about what we're dealing with. Qwen-Image 2.1 is the image model Alibaba's Qwen team open-sourced on September 20. Text-to-image and image editing share the same weights; the visual generation part is a 7B-parameter, 32-layer single-stream DiT, while text and conditioning images are encoded by Qwen3-VL-8B. It natively supports transparent RGBA output, up to 10 reference images, and 2K resolution. The license isn't the old Apache 2.0 but the Qwen Research License, which only covers research and personal use.

For local deployment, the key is its structure. It consists of three files, and you need all of them:

  • qwen-image-2.1-UC-Q4_0.gguf

    (4.15 GB): the main DiT model, the actual "artist"; 4-bit quantized, goes into VRAM

  • qwen3vl_8b_int8_convrot.safetensors

    (9.35 GB): text encoder, turns prompts into semantic vectors, lives in system RAM

  • qwen_image_2.1_vae_bf16.safetensors

    (0.68 GB): VAE, encodes/decodes between latent space and pixels, goes into VRAM

GGUF quantization only compresses the main model. There's no GGUF version of the 8B text encoder, so it has to be stored whole: bf16 is 17.5 GB, int8 is 9.35 GB.

So "running images on 4GB of VRAM" really means the main model runs in 4GB VRAM + the encoder sits in 9GB of system RAM. Once that clicks, you don't have to memorize all the later parameters.

02 Check your driver before installing

Three commands tell you what you're working with:

nvidia-smi          # 记下 Driver Version 和 CUDA Version
free -h             # 文本编码器要放内存,建议 >=16GB
df -h /             # 三个模型 + torch + CUDA 库,约 30GB

The driver version determines which torch you can use. Get this wrong and everything after is wasted effort:

  • Driver ≥ 580: can use cu130 / cu129

  • Driver ≥ 525 and < 580: only cu128. In this guide's case, driver 572.60

  • Lower: have to fall back to an older version like cu121

My machine is on 572.60, so it's in the second bucket.

03 The fastest way to download the three files

Install the basic tools first:

sudo apt update
sudo apt install -y 
git git-lfs curl aria2
git lfs install 
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"

uv is used to pull in a standalone Python. Ubuntu 26.04 ships /usr/bin/python3 as 3.14, and PyTorch has no wheel for it at all—install directly and it's guaranteed to fail. Use uv to pull a separate 3.12 so you don't pollute the system:

uv venv --python 3.12 venv

Then downloads. This deserves its own section: using hf download directly, or git clone followed by git lfs pull, only gets you 0.5–3 MB/s. Switch to aria2c with 16 threads and the same source can hit 25–30 MB/s.

export HF_ENDPOINT=https://hf-mirror.com
mkdir -p /root/qwen_models/{text_encoders,vae}
BASE="https://hf-mirror.com/abenzerps/Qwen-Image-2.1-Uncensored-Quantized/resolve/main" 

aria2c -x16 -s16 -k5M -c --file-allocation=none \
  -d /root/qwen_models -o
 qwen-image-2.1-UC-Q4_0.gguf \
"$BASE/qwen-image-2.1-UC-Q4_0.gguf" 

aria2c -x16 -s16 -k5M -c --file-allocation=none \
  -d /root/qwen_models/text_encoders -o qwen3vl_8b_int8_convrot.safetensors\
"$BASE/text_encoders/qwen3vl_8b_int8_convrot.safetensors" 

aria2c -x16 -s16 -k5M -c --file-allocation=none \  -d /root/qwen_models/vae -o qwen_image_2.1_vae_bf16.safetensors \
"$BASE/vae/qwen_image_2.1_vae_bf16.safetensors"

Use a separate command for each file; don't combine them. aria2's -o only applies to the single URI that follows it. If you cram three files into one command and interleave them, the download sizes get mismatched—the gguf will be downloaded at the encoder's size.

After downloading, verify the byte counts. Get the authoritative values from the repo's HTTP headers:

cd /root/qwen_models
for f in qwen-image-2.1-UC-Q4_0.gguf \
         text_encoders/qwen3vl_8b_int8_convrot.safetensors \
         vae/qwen_image_2.1_vae_bf16.safetensors; do
echo -n "$f -> "; curl -sIL "$BASE/$f" | grep -i content-length | tail -1
done

sha256sum qwen-image-2.1-UC-Q4_0.gguf \
          text_encoders/qwen3vl_8b_int8_convrot.safetensors \
          vae/qwen_image_2.1_vae_bf16.safetensors

Expected: 4,151,573,280 / 9,350,798,360 / 675,509,688 bytes.

The .gguf and .safetensors files in the repo are stored via Git LFS. If you git clone, the files are just 135-byte pointers by default; without git lfs pull, they're empty shells. The direct resolve links above let you skip that layer entirely.

04 The hardest step is pinning torch to cu128

This is the most failure-prone section in the whole guide—four pitfalls chained together.

First, pip install torch gives you a CUDA 13 build by default. CUDA 13 requires driver 580+, and my machine is on 572.60. Install it and torch.cuda.is_available() returns False, or initialization just errors out.

Second, torch in the cu128 index only goes up to 2.11.0. Newer versions are only published for cu129 / cu130, so there's no "newer torch with an older driver" path.

Third, if you also add the Tsinghua mirror as --extra-index-url when installing with uv, uv's default first-index strategy will prefer the default CUDA 13 build on the Tsinghua mirror, silently replacing the version tagged +cu128. Pin the version explicitly and add --index-strategy unsafe-best-match.

Fourth, when you later install ComfyUI's requirements.txt, the torch entry has no version constraint, so it gets resolved again and will swap your cu128 for cu13 just the same. Either strip it out beforehand or catch it with a constraints file.

Here's how to do it:

cd /root/ComfyUI && uv venv --python 3.12 venv
export VIRTUAL_ENV=/root/ComfyUI/venv
export UV_HTTP_TIMEOUT=180
printf'torch==2.11.0+cu128\ntorchvision==0.26.0+cu128\n' > 
/tmp/torch_constraints.txt

 # 只解析、不下载,先看它到底要拉什么
uv pip install --dry-
run "torch==2.11.0+cu128""torchvision==0.26.0+cu128" \
  --index-url https://download.pytorch.org/whl/cu128 \
  --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple \
  --index-strategy unsafe-best-match

The output shows the full dependency list. On my machine it resolved to cuda-toolkit==12.8.1, nvidia-cudnn-cu12==9.19.0.56, nvidia-cublas-cu12==12.8.4.1, nvidia-cusparse-cu12==12.5.8.93, nvidia-nccl-cu12==2.28.9, triton==3.6.0—32 packages total.

If your network is decent, you can skip the next part. But pypi.nvidia.com often times out in mainland China, so the safer approach is to download all the wheels with aria2 first, then install offline locally:

# 把 dry-run 解析出的每个包,抓精确 wheel 链接写进 /root/wheel_urls.txt
aria2c -i /root/wheel_urls.txt -x16 -s16 -k5M -j8 --file-
allocation=none -d /root/wheels 

uv pip install --no-index --find-links /root/wheels \
"torch==2.11.0+cu128""torchvision==0.26.0+cu128" 

# 验证务必用 venv 的绝对路径
/root/ComfyUI/venv/bin/python -c \
"import torch;print(torch.__version__, torch.cuda.is_available(), torch.cuda.get_device_name(0))"

Expected output: 2.11.0+cu128 True NVIDIA GeForce RTX 3050 Laptop GPU.

Don't use bare python or bare pip. In WSL, PATH often includes a Windows-side shim, so typing python drops you into /mnt/c/.../pyenv-win/shims/python and throws /bin/sh^M: bad interpreter. Use the venv's absolute paths throughout.

05 ComfyUI and the GGUF node

cd /root
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI 
# 装依赖时把 torch / torchvision 剔掉,防止被换回 cu13
grep -vE '^torch$|^torchvision$' requirements.txt > /tmp/req_notorch.txt
export VIRTUAL_ENV=/root/ComfyUI/venv
uv pip install -r /tmp/req_notorch.txt --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple 

# GGUF 加载节点
cd custom_nodes
git clone https://github.com/leejet/ComfyUI-GGUF.git
cd ..
uv pip install gguf sentencepiece protobuf

There's a fork trap with the GGUF node. The well-known city96/ComfyUI-GGUF last commit was in January this year, and the repo has no architecture template for Qwen-Image 2.1, so loading it throws Unknown model architecture!. leejet's fork added the missing template on September 20, and the September 21 commit added qwen_image21 to the recognized architecture list. You must use leejet's version.

After installing, double-check that torch hasn't been touched:

/root/ComfyUI/venv/bin/python -c "import torch;print(torch.__version__)"

Put the models in place:

cd /root/ComfyUI/models
mv /root/qwen_models/qwen-image-2.1-UC-Q4_0.gguf diffusion_models/
mv /root/qwen_models/text_encoders/qwen3vl_8b_int8_convrot.safetensors text_encoders/
mv /root/qwen_models/vae/qwen_image_2.1_vae_bf16.safetensors vae/

Start it:

cd /root/ComfyUI
./venv/bin/python main.py --lowvram --listen 0.0.0.0 --port 8188

With 4GB VRAM, --lowvram is mandatory, and don't push resolution past 1024×1024.

06 Get the first image out

Open http://localhost:8188 in your browser and wire up the nodes with these parameters:

  • Unet Loader (GGUF)

    choose qwen-image-2.1-UC-Q4_0.gguf

  • CLIPLoader

    choose qwen3vl_8b_int8_convrot.safetensors, set type to qwen_image, change device to cpu

  • VAELoader

    choose qwen_image_2.1_vae_bf16.safetensors

  • EmptySD3LatentImage

    set 1024×1024

  • ModelSamplingAuraFlow

    set shift to 3.1

  • KSampler

    use euler / simple, steps=20, cfg=4

Two things matter most. CLIPLoader's type must be qwen_image, because the text encoder is Qwen3-VL-8B and internally follows the qwen_image21 path; pick the wrong one and you get an architecture error.

The other is device. Set CLIPLoader's device to cpu so the 9.35 GB encoder goes into system RAM. It's only used once per image, so it barely affects generation speed, but it saves nearly 9GB of VRAM. That's the trick that makes a 4GB card work.

Verify the service and model are ready:

curl -s http://127.0.0.1:8188/object_info/UnetLoaderGGUF | head -c 100 
curl -s http://127.0.0.1:8188/object_info/UnetLoaderGGUF \
  | python3 -c "import sys,json;print(json.load(sys.stdin)['UnetLoaderGGUF']['input']['required']['unet_name'][0])"

On a normal startup, these lines show up in the log:

Total VRAM 4096 MB ... Set vram stateto: LOW_VRAM
Device: cuda:0 NVIDIA GeForce RTX 3050 Laptop GPU
CLIP/text encoder model load device: cpu ...
Requested toload QwenImage21
loaded partially; 2072 MB usable, 1990 MB loaded, 2097 MB offloaded
Prompt executed in304.66 seconds

The loaded partially line is normal paging under lowvram, not an error. Output images land in /root/ComfyUI/output/.

07 Pitfall quick reference

# Symptom Root cause Fix
1 pip can't install torch System Python 3.14 is too new; no wheel uv venv --python 3.12
2 Model downloads are painfully slow hf / pip downloaders only do 0.5–3 MB/s aria2c -x16 -s16
3 Downloaded file sizes are wrong Multiple -o flags in one command One command per file
4 gguf is only 135 bytes Git LFS pointer wasn't pulled Use resolve direct links, or git lfs pull
5 cuda: False or it just errors out torch installed as CUDA 13, driver only supports 12.8
6 torch gets silently swapped uv's first-index strategy Pin the version + --index-strategy unsafe-best-match
7 nvidia dependency downloads time out pypi.nvidia.com unstable
8 python throws bad interpreter Hits the Windows pyenv shim in WSL
9 Unknown model architecture! GGUF node is the city96 version Switch to leejet/ComfyUI-GGUF
10 OOM or broken output 4GB VRAM can't handle default parameters --lowvram
11 Encoder load throws architecture error Wrong CLIPLoader type Set type to qwen_image
12 Not enough VRAM Encoder takes nearly 9GB Set CLIPLoader device to cpu
13 requirements resolution fails Mixed PyTorch indexes Use default PyPI + Tsinghua mirror, remove torch

08 Performance, license, and limits

Real-world numbers on a 4GB card: 1024×1024, 20 steps, about 5 minutes per image, or 12.5 seconds per step. Peak VRAM sits between 3.7 / 4.0 GB, which is normal offload behavior. Want it faster? Drop steps to 12–16. Want more detail? Raise them to 40–50; time goes up linearly. The community also offers optional companion LoRAs—mount them with LoraLoader when needed.

Finally, let's be clear about the license. This quantized repo inherits the Qwen Research License, which allows research and personal-use deployment and does not cover commercial use. The "Uncensored" in the repo name only means there's no extra filter layer in the inference pipeline; what you generate and distribute is your responsibility. Tinkering locally is fine—just don't use it to generate illegal content or content that infringes on others' rights.

Translated by AI from 简体中文

5
1
Log into join the discussion.
海外原生IP VPS,稳定访问全球网络

还在为IP不纯、平台风控、频繁验证而烦恼? 丽萨主机海外原生IP VPS,双ISP住宅IP,覆盖美国、香港、日本、新加坡、台湾、德国、越南、英国等热门地区,适合跨境电商、社媒运营、AI工具、流媒体及海外业务使用。

lisahost.com Learn more

1 replies

Sort order
  1. FrancisLiu Gold 3 YEARS 26d ago

    Good read

    Translated by AI from 简体中文

    1