Skip to content

feat(quant)!: compress bf16 weights to df11 at load with --online-quant - #891

Merged
jason-fxz merged 3 commits into
mainfrom
df11-online-quant
Nov 11, 2026
Merged

jason-fxz merged 3 commits into
mainfrom
df11-online-quant

Conversation

@jason-fxz

@jason-fxz jason-fxz commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

GLM-4.7 hardwired DF11 (lossless bf16 compression, about 11 bits per weight, decoded bit-for-bit on use) into its attention linears and token embedding through two model-local modules. This moves DF11 into the quantization framework as an online method that any model can turn on.

  • --online-quant df11 converts the Linear layers and input embedding tables that the checkpoint stores in bf16 at load. Layers the checkpoint quantizes stay as they are, and so do:
    • layers the online method refuses or has no usable kernel for: DF11 refuses the LM head, which would decode its whole weight every step, and its table kernel needs TP = 1 (both logged);
    • a table tied to the LM head (logged);
    • layers a model builds with without_online(quant_config): the Qwen VL vision tower, whose blocks stream to the GPU in one shared layout, and GLM-5.x kv_b_proj and the DeepSeek-V4 compressors, whose weights the model reads directly.
  • --online-quant-modules limits it to checkpoint module names or glob patterns, e.g. model.layers.*.self_attn,model.embed_tokens. A fused layer (qkv_proj) must be covered in all of its checkpoint parts. A name that selects no convertible layer, or a flag that converts nothing, is refused at startup.
  • QuantMethod.online marks a method that declares the bf16 weight and converts it in finalize; QuantMethod.refuses(layer) lets it decline a layer. QuantConfig.with_online(kind, modules) returns a copy that serves the online kind for layers the checkpoint leaves unquantized, and falls back to the plain method when the online one refuses the layer or has no usable kernel. Df11LinearMethod and Df11EmbeddingMethod register like any other method. The DF11 kernels are unchanged.
  • The engine loads the weights of online methods to host RAM first, so finalize compresses them one at a time and the GPU never holds the whole bf16 set.
  • glm4_moe builds plain LinearReplicated / VocabParallelEmbedding; glm4_moe/df11_linear.py and glm4_moe/df11_embedding.py are removed.

Breaking

  • GLM-4.7 serves its attention and embedding in bf16 unless --online-quant df11 is passed: about 8 GiB more VRAM, faster decode (table below).
  • GLM-4.7 FTW files written before this change store the DF11 tensors, which the model no longer declares; loading one fails with a message to reconvert it with ft checkpoint.

Known issues

--online-quant is off by default; these are left for a follow-up.

  • Online weights are compressed only after the whole checkpoint has loaded. The engine keeps every bf16 weight it will convert in host RAM until load_state_dict returns, then finalize_quant copies each one back to the GPU and compresses it there. The whole bf16 set sits in host RAM during load, and each compression's temporary GPU memory comes on top of the loaded model.
  • df11_compress, used for Linear weights, allocates about 60x the weight in temporary GPU memory; df11_compress_rows, used for embedding tables, works in row blocks. Extra peak allocated memory over the input weight, one H100 80GB, torch 2.14.1:
Weight Function Weight size Extra peak
12288 x 5120 (GLM-4.7 q_proj) df11_compress 120 MiB 7264 MiB
34816 x 5120 (Qwen3.6-27B gate_up_proj) df11_compress 340 MiB 20581 MiB
151552 x 5120 (GLM-4.7 embed_tokens) df11_compress_rows 1480 MiB 6022 MiB
  • An MTP draft read from a safetensors checkpoint (Qwen3.5 / Qwen3.6 / Qwen3.8) builds with the target's quant config, so --online-quant converts its bf16 layers too. The startup log line does not count them, and --online-quant-modules does not match them.

Tested

RTX PRO 6000 Blackwell Server Edition 96 GB (one GPU), Xeon Platinum 8559C, 500 GB RAM, driver 595.91.07, CUDA 13.0, torch 2.14.1. Measured on the first commit (7042b84). The second commit does not change which GLM-4.7 layers convert: a meta-device build gives the same 369 DF11 layers on both.

nvidia/GLM-4.7-NVFP4, expert offload with 2048 LRU slots, naive cache, one request at a time, greedy, 3 chat prompts x 512 tokens after a warm-up request:

Load peak Resident after load Decode tok/s
main 0ad521d 24.75 GiB 19.82 GiB 4.85 / 5.18 / 5.45
this PR, --online-quant df11 27.06 GiB 19.93 GiB 5.16 / 5.17 / 5.49
this PR, no flag 27.84 GiB 27.84 GiB 7.26 / 7.27 / 7.83

All three runs produce the same 3 x 512 tokens.

LLM(model_path="nvidia/GLM-4.7-NVFP4", dtype=torch.bfloat16, moe_strategy="offload", moe_cache_size=2048, moe_cache_policy="lru",
    cache_type="naive", max_running_req=1, max_extend_tokens=8192, max_seq_len_override=8192, cuda_graph_max_bs=1, memory_ratio=0.9,
    online_quant="df11")  # left out for main and for "no flag"

Server path:

ft serve --model nvidia/GLM-4.7-NVFP4 --online-quant df11 --moe-strategy offload --moe-cache-size 2048 --cache-type naive --max-seq-len-override 8192

logs --online-quant df11: converting 369 weights at load and answers "What is 17 * 23? Answer with the number only." with 391.

With a name that selects nothing, --online-quant-modules 'model.layers.*.self_atn', startup fails with ValueError: --online-quant-modules: no layer --online-quant df11 converts matches model.layers.*.self_atn; give the checkpoint's module names, e.g. 'model.embed_tokens'.

Unit tests: pytest tests/models tests/engine tests/layers tests/kernels tests/spec tests/checkpoint tests/server -m "not slow": 1708 passed, 251 skipped.

H100, head of this PR

H100 80GB HBM3 (one GPU), Xeon Platinum 8480+, 221 GB RAM, driver 580.95.05, CUDA 13.0, torch 2.14.1.

Unit tests: the same command, 1676 passed, 298 skipped. tests/models/test_quant_config.py pointed at local checkpoints passes, including the df11 rows for GLM-4.7, Qwen3.8-Flash-Next, Gemma-4 12B (its tied table stays bf16) and DeepSeek-V4-Flash (its compressors stay bf16).

AIME25 problem 1 as a chat prompt, greedy, max_tokens=1024, one request. Every run uses LLM(model_path=..., dtype=torch.bfloat16, attention_backend="auto", max_running_req=1, max_extend_tokens=8192) plus the arguments in the tables. OFFLOAD below is moe_strategy="offload", moe_cache_size=4096, moe_cache_policy="lru", kv_reserve_tokens=4096, memory_ratio=0.9, max_seq_len_override=4096, cuda_graph_max_bs=1.

No flag, main 0ad521d and this PR: the same token ids on every row.

Checkpoint Extra LLM arguments
Qwen/Qwen3.5-2B (embedding tied to the LM head) none
openai/gpt-oss-20b none
gemma-4-12B-it-BF16.gguf (GGUF general.name "Gemma 4 12B It", BF16; tied embedding) none
nvidia/Qwen3.6-35B-A3B-NVFP4 OFFLOAD, embed_weights="host"
nvidia/Qwen3.6-35B-A3B-NVFP4 speculative_algorithm="mtp" (accept length 3.58 on both sides)

--online-quant df11 and no flag, this PR: the same token ids on every row.

Checkpoint Extra LLM arguments Startup log
Qwen/Qwen3.5-2B none converting 96 weights; leaves model.embed_tokens as stored, the LM head is tied to it
nvidia/Qwen3.6-35B-A3B-NVFP4 OFFLOAD converting 31 weights
nvidia/Qwen3.6-35B-A3B-NVFP4 speculative_algorithm="mtp" (accept length 3.58 on both sides) converting 31 weights

Meta-device builds of 26 local checkpoints (Qwen3 / Qwen3.5 / Qwen3.6 / Qwen3.8 in bf16, FP8 and NVFP4, Qwen3.8-Flash-Next, Muse-Glimmer, Gemma-4 including a GGUF, MiniMax-M2.5, DeepSeek-V4-Flash, gpt-oss, GLM-4.7) give every layer the same quant method on main and this PR without the flag, except GLM-4.7's 369 attention and embedding layers, which now build as bf16. With --online-quant df11 all 26 build.

GLM-4.7 no longer hardwires DF11 attention and embedding; it serves them
bf16 unless --online-quant df11 is passed, and FTW files converted with the
old DF11 tensors must be reconverted.
@jason-fxz jason-fxz added the quant LLM quantization label Nov 11, 2026
@jason-fxz
jason-fxz merged commit 56e7f3a into main Nov 11, 2026
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Nov 21, 2026
Upstream FlashML-org#894 (fp8/int8 per-token-head KV formats) and FlashML-org#920 (fp8_ds_mla /
nvfp4_ds_mla) bring the KVFormat framework (kvcache/format.py,
kernel/triton/kv_rows.py, BackendInfo.kv_formats, kv_format on the pools).
It replaces the plumbing of the adopted FlashML-org#354 (fp8 KV) and FlashML-org#408 (nvfp4 KV):
kv_quant, supports_fp8_kv/supports_nvfp4_kv, kernel/triton/kv_quant.py and
kernel/triton/kv_nvfp4.py are gone, with their tests.

--kv-cache-dtype keeps 'fp8' as an alias of fp8_per_token_head and 'bf16' as
an alias of auto, so existing launch lines keep working. nvfp4 is unavailable
at this commit; its port onto the KVFormat framework follows in the next
commit.

Also taken from upstream where it superseded fork code: kv_shared_layers
(FlashML-org#898) replaces the fork's kv_sharing for Gemma-4 E2B/E4B, and the online
DF11 (FlashML-org#891) replaces the GLM-4 hardwired DF11 (the forecast now prices
--online-quant df11 weights).

Assisted-by: Claude Opus 5.5
KarrAcaRn pushed a commit to KarrAcaRn/FreeToken-ByAI that referenced this pull request Nov 21, 2026
…1 flag

next added --online-quant df11 (FlashML-org#891) next to next-speed's own --online-quant flag, so
argparse refused the duplicate and every parse_args caller failed. One flag now takes
none, fp8 and df11: fp8 stays the default (an explicit linear --quant-backend entry or
--online-quant-modules opts out) and becomes the linear.none=fp8 entry; only df11 reaches
EngineConfig.online_quant. record_expert_profile.py passes kv_cache_dtype instead of the
removed kv_quant.

Assisted-by: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quant LLM quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant