tsiendragon/qwen-image-finetune/qwen-image-edit-aipc-finetune-06-quantize
Claude Code and agent skill by tsiendragon/qwen-image-finetune
- community
Checking that the SKILL.md file is still in the repository.
Step 6 of 8 of the Qwen-Image-Edit AI PC fine-tuning walkthrough. Use after qwen-image-edit-aipc-finetune-05-adaptation. This is a CONDITIONAL step: perform the one-time NF4 pre-quantization of the transformer (DiT) and, on 32 GB machines, the text_encoder, then wire the quantized paths into config.yaml. On a 64 GB+ machine using online NF4 you may skip it entirely. Only use once step 5 adaptation_check passes.
Install
npx vskill@latest install tsiendragon/qwen-image-finetune/qwen-image-edit-aipc-finetune-06-quantizeSKILL.md
Step 6 — NF4 Pre-Quantization (Conditional, One-Time)
Series position: Step 6 of 8. One-time per machine; reuse across all training runs.
Prerequisites:
- Framework adaptation complete (Step 5)
config.yamlwith paths filled (Step 4)- RAM tier confirmed (Step 1); conda env active; oneAPI installed
Next step: when the quantizations that apply to your machine are done, config paths are updated, and config_check.py exits 0, proceed to skill qwen-image-edit-aipc-finetune-07-training.
6.0 Decision gate — do you need this step?
This whole step is optional/conditional. Decide before running anything:
| Your situation | §6.1 transformer NF4 | §6.2 text_encoder NF4 | |
|---|---|---|---|
| 32 GB RAM machine | Recommended (faster startup) | Recommended — relieves cache-phase RAM pressure | |
| 64 GB+ RAM machine, will train several times | Recommended (faster startup) | Optional / skip | |
| 64 GB+ RAM machine, single exploratory run | Skip — use online NF4 | Skip |
- If both columns say skip for you (64 GB+, one-off run): leave
model.transformer_pathand
model.text_encoder_path as their TODO/absent values, confirm config_check.py still passes (it treats them as "unset" and only WARNs), and go straight to Step 7 using online NF4.
- Otherwise do the applicable sections below. Neither section changes training-time memory — the
transformer one only saves per-run startup time; the text_encoder one only relieves cache-phase RAM on 32 GB machines.
Both quantizations require the conda env active and oneAPI activated (setvars.bat), because bnb's Triton-backed quantize_4bit needs the oneAPI runtime to JIT-compile the quantize kernel.
Both scripts quantize on the XPU by default. If that step fails, --device cpu runs the whole load on the CPU instead — see this step's Troubleshooting.
6.1 Pre-quantize the transformer (DiT) — optional, recommended for repeated runs
This skill always uses NF4 for the transformer — the question is how NF4 weights are loaded at each training start:
Pre-quantized (transformer_path set) | Online NF4 (transformer_path null) | ||
|---|---|---|---|
| Disk space | +~10 GB for the NF4 checkpoint dir | No extra | |
| Per-run startup | Fast — load ~10 GB NF4 directly | Slower — stream bf16 shards from the original repo and quantize on the fly; Triton quantize_4bit JIT-compiles on first use | |
| Training-time memory | Essentially the same as online NF4 | Essentially the same as pre-quantized | |
| Original model needed on disk | Still required for text_encoder, VAE, scheduler | Still required |
The bf16 transformer checkpoint on disk is ~38 GB; the NF4 output is ~10 GB (~4× smaller). During online quantization the model is loaded shard-by-shard so peak RAM is much less than 38 GB, but the process still takes meaningful time on every run start.
Save the quantize script as quantize_transformer_nf4.py in the project root:
Save the Windows launcher as quantize_xpu.bat in the project root (activates oneAPI + conda automatically). Update the oneAPI path and conda env name if yours differ:
Run either the launcher or the script directly:
After quantizing, set in config.yaml:
The qflux loader reads quantization_config from <DST>/config.json and skips online quantization automatically.
PASS: <DST> exists and contains config.json with a quantization_config field; ~10 GB total.
6.2 Pre-quantize the text_encoder (NF4) — 32 GB machines: recommended
Trigger condition (machine-judgable), by RAM tier (Step 1 --ram-tier; fallback: probe ram_gb in GiB, where the 32 GB tier is < 36):
- 32 GB tier (the minimum supported) → recommended. At this tier the cache phase loads the
~15 GB bf16 text_encoder alongside the dataset and VAE, pushing RAM near its limit and triggering virtual-memory paging that slows caching significantly.
- 64 GB+ tier → optional / not needed (extra headroom).
The Qwen2.5-VL text_encoder weighs ~15 GB at bf16 (15.4 GiB in Windows Explorer). Pre-quantizing to NF4 drops it to ~5.5 GB on disk.
Save the quantize script as quantize_text_encoder_nf4.py in the project root:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/qwen-image-edit-aipc-finetune-06-quantize/SKILL.md
Popularity
- Repository stars
- 253
- Repository forks
- 27
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tsiendragon/qwen-image-finetune/qwen-image-edit-aipc-finetune-06-quantize)