| license | apache-2.0 |
|---|
Post-training quantization (PTQ) and quantization-aware training (QAT) for Wan2.1-T2V-14B using W8A8 HiFloat8, targeting the VBench evaluation criteria.
| Item | Details |
|---|---|
| Hardware | Huawei Ascend 910B (64 GB HBM per card) |
| OS | Linux aarch64 |
| Python | 3.10 |
| PyTorch | 2.1 + torch_npu |
| Ascend toolkit | 8.2.RC1 |
| Model | Wan2.1-T2V-14B |
| Quantization format | HiFloat8 (HiF8) W8A8 |
Dependencies
external/Wan2.1/ # Wan2.1 model code
external/HiFloat8/ # HiF8 quantization kernels (hif8_npu)
external/VBench/ # VBench evaluation framework
Set up the environment before running any script:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /path/to/.venv/bin/activate
export PYTHONPATH=external/Wan2.1:external/HiFloat8/hif8_npu:external/VBench:$PYTHONPATHFive prompts, seeds 42β46 (seed = 42 + index):
| Index | Seed | Prompt |
|---|---|---|
| 0 | 42 | A majestic eagle soaring over snow-capped mountains at golden hour |
| 1 | 43 | Ocean waves crashing on a rocky shore at sunset, foam and mist |
| 2 | 44 | A bustling city street at night with neon lights and rain reflections |
| 3 | 45 | A field of sunflowers swaying gently in the breeze on a sunny day |
| 4 | 46 | A brown bear fishing for salmon in a rushing mountain stream |
Resolution: 832Γ480, 49 frames, 50 denoising steps, guide_scale=6.0.
python3 generate.py \
--ckpt-dir <checkpoint_dir> \
--model-size 14B \
--protected-blocks 0 1 37 38 39 \
--output-dir outputs/ptq_eval \
--size 832*480 --frame-num 49 --sample-steps 50 --seed 42 \
--prompts "prompt 0" "prompt 1" ...Key flags:
--no-quantβ BF16 baseline, skip quantization--qat-weights <file.pt>β load QAT fine-tuned weights--start-index Nβ offset output file index and seed (used to resume partial runs)
python3 train_qat_single.py \
--ckpt-dir <checkpoint_dir> \
--metadata data/metadata_training.json \
--protected-blocks 0 1 37 38 39 \
--finetune-blocks 2 3 4 \
--steps 1000 --lr 5e-5 --grad-accum 8Quantizes all non-protected blocks, but only fine-tunes --finetune-blocks to keep
Adam optimizer states within HBM budget. Requires precomputed latents (see below).
Encodes training videos with the VAE and T5; saves {z0, ctx, caption} per sample to data/latents/.
Edit the hardcoded CKPT, META, OUT paths at the top before running.
python3 analyze_activations.py --ckpt-dir <checkpoint_dir> --device 0 --steps 3Hooks all 40 WanAttentionBlocks during a short BF16 forward pass, records max-abs / std / kurtosis / p99 per block, and saves a bar chart to outputs/activation_stats.png.
python3 vbench_single.py \
--video outputs/ptq_eval/video_000.mp4 \
--name ptq_v000 \
--device npu:0 \
--cache-dir ~/.cache/vbench \
--output-dir outputs/vbench_resultsEvaluates four VBench dimensions: temporal_flickering, aesthetic_quality, imaging_quality, background_consistency.
VBench scores averaged over 5 videos:
| Dimension | BF16 | PTQ W8A8 HiF8 | QAT W8A8 HiF8 |
|---|---|---|---|
| temporal_flickering | 97.26% | 97.84% | 99.19% |
| aesthetic_quality | 67.43% | 70.01% | 68.01% |
| imaging_quality | 65.41 | 67.03 | 60.17 |
| background_consistency | 97.14% | 98.29% | 98.36% |
Protected blocks (kept in BF16): [0, 1, 37, 38, 39] (first two and last three transformer blocks).
Submitted method: PTQ W8A8 HiF8 β improves over BF16 baseline on all four dimensions with no fine-tuning required.