Skip to content

Byte-LUT NF4 dequant in the JIT block stack - #35

Merged
TroyHernandez merged 5 commits into
mainfrom
perf/nf4-byte-lut-dequant
Jul 20, 2026
Merged

Byte-LUT NF4 dequant in the JIT block stack#35
TroyHernandez merged 5 commits into
mainfrom
perf/nf4-byte-lut-dequant

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

The LTX-2.3 JIT block stack dequantizes NF4 weights through a precomputed [256, 2] byte lookup table (one embedding gather in the compute dtype) instead of the int64 shift/stack/gather chain, cutting per-step dequant memory traffic ~6x. Isolated benchmark: 5.7x; the dequant was the measured per-step wall at ~4.4 s of a 6.5 s step.

Includes a merge of main to pick up the Qwen3 mask dtype fix (#34) and the corresponding 0.1.0.9 re-bump.

The nf4_lin dequant chain (shift/and to int64, stack, flatten, fp32
gather, scale, cast, cat) generated ~70 bytes of memory traffic per
half-byte parameter: ~1.4 TB per denoise step over the 19B weights,
matching the measured ~4.4 s fixed per-step cost. Replace it with a
single embedding gather through a precomputed [256, 2] byte LUT (hi
nibble, lo nibble) built in the compute dtype, absmax cast down before
the scale so nothing promotes to float32, no chunk loop, no cat.

Isolated TorchScript benchmark (100M params, CUDA): 23.4 -> 4.1 ms,
5.7x; projected ~4.4 -> ~0.8 s of dequant per step. On float32 (CPU,
CI) the math is identical to the old path; on bf16 the scale multiply
rounds once more (~0.4%, well under NF4 quantization noise).
End-to-end GPU parity and render timing to follow.
@TroyHernandez
TroyHernandez merged commit 5dfb165 into main Jul 20, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the perf/nf4-byte-lut-dequant branch July 20, 2026 17:35
@TroyHernandez

Copy link
Copy Markdown
Contributor Author

Post-merge validation (the "GPU parity and render timing to follow" from the first commit):

Render timing (768x512x49, NF4, seed 42, RTX 5060 Ti): denoise steps 6.4–6.5 s → 3.2–3.3 s (1.97x); render wall 89–96 s → 73 s. Remaining wall is transformer onload (~15 s), denoise (~26 s), video decode (12.3 s).

Real-weight dequant parity (old chain vs byte LUT, both vs fp32-exact, on artifact weights, bf16 CUDA): the LUT path's max deviation from fp32 truth is 1–2x the old path's own bf16-cast rounding (e.g. attn1.to_k: old 0.094, new 0.147, in units of tensor RMS on the worst element), orders of magnitude below NF4 quantization error. Seed-42 output video archived for QC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant