umt5-xxl-encoder-phi-lattice-v2
4-bit phi-lattice v2 pack of the UMT5EncoderModel shipped in Wan-AI/Wan2.1-T2V-1.3B-Diffusers (text_encoder/, 24 layers, d_model=4096, d_ff=10240, vocab 256384).
The Wan transformer pack is 761.65 MiB. This encoder is the remaining resident cost of the pipeline: the FP32 shards are 21,670.55 MiB (22,723,641,344 tensor bytes). Packed, the encoder is 4,349.61 MiB on disk and 4,349.48 MiB resident in low_vram_4bit.
168 linear layers (4,630,511,616 weights) are uint8 nibbles plus fp16 scales of group 64. The tied token embedding stays BF16 (2,002.72 MiB). Every quantized layer has K % 64 == 0. T5 has no linear biases, so the archive has none.
| Checkpoint | Disk | Resident | Linear weights (4.63B) |
|---|---|---|---|
| Upstream FP32 shards | 21,670.55 MiB | 21,670.55 MiB | 17,664.00 MiB |
| Same tensors in BF16 | 10,835.27 MiB | 10,835.27 MiB | 8,832.00 MiB |
umt5_xxl_encoder_phi_v2_packed_4bit.pt | 4,349.61 MiB | 4,349.48 MiB | 2,346.0 MiB (3.765x vs BF16) |
Against the original FP32 encoder weights: SQNR 19.34 dB, exact zeros 570,201,211 (12.31%). sha256: 64c9b6a0fb5e4e83389859b1d7b76fbdbaf117ce1a7ae459b0fbb7ae897d40fb (4,560,898,637 bytes). torch.load(..., weights_only=True) is safe.
low_vram_4bit builds the module tree on the meta device and allocates only the packed linears plus the BF16 embedding, so it does not pass through a 22 GB FP32 allocation.
Comparison with the original encoder
examples/compare_umt5_ltx_upstream.py matched all 242 / 242 upstream tensors. Dequantized weights versus the FP32 matrices: SQNR 19.34 dB, cosine 0.9942. The BF16 embedding and norms versus the same FP32 tensors: cosine 0.9999986.
The same four captions were then run through low_vram_4bit (BF16) and through the original FP32 encoder, one block at a time. Cosine is over non-padding tokens:
| Caption | Tokens | Hidden cosine | max |Δ| |
|---|---|---|---|
a neon alley in the rain | 8 | 0.9440 | 0.327 |
| Tokyo neon walk | 51 | 0.9694 | 0.351 |
| Snow leopard | 44 | 0.9771 | 0.485 |
| Sea turtle over coral | 42 | 0.9392 | 1.737 |
End-to-end comparison on Wan2.1-T2V-1.3B (upstream | encoder isolation | full phi pipeline)
ZeroGPU harness phi-verification-lab Tab 7, wan-benchmark protocol 1:1: 832x480, 65 frames (4.06s @ 16 fps), 25 steps, guidance 5.0, identical seeds. Side A = upstream BF16 encoder + upstream transformer; side B = this packed encoder + upstream transformer (encoder isolation); side C = packed encoder + packed wan transformer (full phi pipeline).
Tokyo neon walk (seed 77): A | B — PSNR 16.88 dB, SSIM 0.6009
Tokyo neon walk (seed 77): A | C — PSNR 14.13 dB, SSIM 0.4400
Snow leopard (seed 202): A | B — PSNR 14.30 dB, SSIM 0.5322
Snow leopard (seed 202): A | C — PSNR 12.54 dB, SSIM 0.4731
Corals and sea turtle (seed 309): A | B — PSNR 19.42 dB, SSIM 0.8317
Corals and sea turtle (seed 309): A | C — PSNR 12.74 dB, SSIM 0.6241
| Scene (seed) | B vs A (encoder isolation) | C vs A (full phi) |
|---|---|---|
| Tokyo neon walk (77) | PSNR 16.88 dB / SSIM 0.6009 / MAE 17.25 / TC 0.2820 | PSNR 14.13 dB / SSIM 0.4400 / MAE 27.72 / TC 0.1309 |
| Snow leopard (202) | PSNR 14.30 dB / SSIM 0.5322 / MAE 29.79 / TC 0.2067 | PSNR 12.54 dB / SSIM 0.4731 / MAE 40.20 / TC 0.0783 |
| Corals and sea turtle (309) | PSNR 19.42 dB / SSIM 0.8317 / MAE 8.78 / TC 0.0609 | PSNR 12.74 dB / SSIM 0.6241 / MAE 26.43 / TC 0.0302 |
Hidden states, packed encoder versus upstream FP32, non-padding tokens, ZeroGPU. Gate cosine ≥ 0.93: neon alley 0.9473, Tokyo 0.9689, snow leopard 0.9767, corals 0.9343. All four pass.
Verdict versus the pinned hypothesis (PSNR ≥ 18 and SSIM ≥ 0.85 for B vs A). Corals passes PSNR and misses SSIM by 0.018. Tokyo and snow leopard miss both. Quantizing the encoder still moves the 25-step shot. The videos stay the same kind of scene.
Resident VRAM (measured in-pipeline): A 14,033 MiB vs B 7,547 MiB vs C 5,591 MiB.
Status: all three scenes and the hidden-state check are in.
CLIPScore on eight frames (openai/clip-vit-base-patch32, 2.5 * max(cosine, 0)). This is prompt match, not distance to side A.
| Scene | A | B | C |
|---|---|---|---|
| Tokyo | 0.875 | 0.906 | 0.843 |
| snow leopard | 0.841 | 0.836 | 0.876 |
| corals | 0.644 | 0.573 | 0.770 |
Independent verification
ZeroGPU harness: phi-verification-lab (Tab 5, model umt5). 2026-11-08 run, archived in tests/verification_umt5_2026-11-08.log:
- archive sha256 vs pin:
MATCH;168quantized /74protected,K % 64 == 0on all; low_vram_4bitvsunrolled_bf16forward (batch of 8 ids): resident4349.48 MiB— matches the structural budget in the table above exactly;max |dy| = 0.000000, cosine1.00000310, top1 match; peak allocated5071.78 MiBpacked vs14876.48 MiBunrolled;- Triton selftest on real attention layers (
4096x4096): W bit-exact vs dequant reference,relL2 <= 4.8e-05vs strict cuBLAS.
The forward baseline is this archive's own unrolled_bf16 (loader-consistency check, not an upstream comparison); upstream weight-level numbers are in the section above, end-to-end Wan2.1-T2V-1.3B parity is tracked separately.
Quick start
import importlib.util
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoTokenizer
repo_id = "ununununununununununununununununununun/umt5-xxl-encoder-phi-lattice-v2"
loader_path = hf_hub_download(repo_id, "phi_loader.py")
spec = importlib.util.spec_from_file_location("phi_loader", loader_path)
phi_loader = importlib.util.module_from_spec(spec)
spec.loader.exec_module(phi_loader)
encoder = phi_loader.load_umt5_from_packed_4bit(repo_id=repo_id, mode="low_vram_4bit")
tokenizer = AutoTokenizer.from_pretrained(repo_id)
hidden = encoder(**tokenizer("a neon alley in the rain", return_tensors="pt")).last_hidden_state
mode="unrolled_bf16" materializes the full BF16 encoder (strict=True). mode="triton_4bit" swaps in PhiLUTGemmLinear on CUDA.