From eeeeea3c882d6a803cde8ab9518e8af20740c5dc Mon Sep 17 00:00:00 2001 From: keptn42 Date: Fri, 23 Oct 2026 21:41:06 +0200 Subject: [PATCH] recipes: Gemma 4 E4B (bf16 with DFlash, w8a8 with DFlash, w4a8 with and without) Wikitext-2 KL against the HF bf16 reference: bf16 0.0015, w8a8 0.076, w4a8 0.242 (attention and layers 19-23 int8, feed-forward int4; all int4 is 0.612). --- data/recipes/gemma4-e4b-bf16-df.recipe | 18 ++++++++ data/recipes/gemma4-e4b-bf16-w4a8-df.recipe | 46 ++++++++++++++++++++ data/recipes/gemma4-e4b-bf16-w4a8.recipe | 47 +++++++++++++++++++++ data/recipes/gemma4-e4b-bf16-w8a8-df.recipe | 23 ++++++++++ 4 files changed, 134 insertions(+) create mode 100644 data/recipes/gemma4-e4b-bf16-df.recipe create mode 100644 data/recipes/gemma4-e4b-bf16-w4a8-df.recipe create mode 100644 data/recipes/gemma4-e4b-bf16-w4a8.recipe create mode 100644 data/recipes/gemma4-e4b-bf16-w8a8-df.recipe diff --git a/data/recipes/gemma4-e4b-bf16-df.recipe b/data/recipes/gemma4-e4b-bf16-df.recipe new file mode 100644 index 00000000..d6392e50 --- /dev/null +++ b/data/recipes/gemma4-e4b-bf16-df.recipe @@ -0,0 +1,18 @@ +# gemma4-e4b-bf16-df.recipe -- Gemma 4 E4B (NVIDIA-Nemotron-3.5-Bolt-E4B-BF16) as the checkpoint holds it, +# text and vision, with NVIDIA's DFlash drafter on block FP8. Wikitext-2 KL against the HF bf16 reference +# 0.0015 (bf16 against fp32 0.0012). +# +# rad-convert --recipe data/recipes/gemma4-e4b-bf16-df.recipe --draft-model \ +# --set quantization_config.quant_method=compressed-tensors -o nemotron-3.5-bolt-e4b-bf16.rad +# +# The drafter ships as a GGUF only (nvidia/NVIDIA-Nemotron-3.5-Bolt-E4B-4GB-DFlash); --draft-model reads +# it as safetensors in the z-lab layout. DFlash1 declares its linears block FP8, so bf16 codes are refused. + +dflash.fc.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_q.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_gate_up.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_down.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 diff --git a/data/recipes/gemma4-e4b-bf16-w4a8-df.recipe b/data/recipes/gemma4-e4b-bf16-w4a8-df.recipe new file mode 100644 index 00000000..3d0d3dea --- /dev/null +++ b/data/recipes/gemma4-e4b-bf16-w4a8-df.recipe @@ -0,0 +1,46 @@ +# gemma4-e4b-bf16-w4a8-df.recipe -- Gemma 4 E4B (text) from a bf16 checkpoint, e.g. NVIDIA's +# Nemotron-3.5-Bolt-E4B: int4 codes with an f16 scale per 128 columns (w4a8) on the feed-forward, +# The same trunk as gemma4-e4b-bf16-w4a8.recipe, with NVIDIA's DFlash drafter (rad-convert --draft-model ) +# on block FP8 like the 31B's -df recipe, and its head as a block-FP8 copy of the target table. +# +# rad-convert --recipe data/recipes/gemma4-e4b-bf16-w4a8-df.recipe --draft-model \ +# --set quantization_config.quant_method=compressed-tensors -o gemma4-e4b-w4a8-df.rad + + +blk.19.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.19.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.19.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.19.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.20.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.20.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.20.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.20.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.21.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.21.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.21.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.21.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.22.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.22.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.22.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.22.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.23.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.23.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.23.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.23.ffn_down.weight rtn codes=i8 group=128 scale=f16 + +blk.*.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_q.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.*.ffn_down.weight rtn codes=i4 group=128 scale=f16 rule=search +blk.*.ffn_gate_up.weight rtn codes=i4 group=128 scale=f16 rule=search + +output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym + +dflash.fc.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_q.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_gate_up.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_down.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 diff --git a/data/recipes/gemma4-e4b-bf16-w4a8.recipe b/data/recipes/gemma4-e4b-bf16-w4a8.recipe new file mode 100644 index 00000000..6b302463 --- /dev/null +++ b/data/recipes/gemma4-e4b-bf16-w4a8.recipe @@ -0,0 +1,47 @@ +# gemma4-e4b-bf16-w4a8.recipe -- Gemma 4 E4B (text) from a bf16 checkpoint, e.g. NVIDIA's +# Nemotron-3.5-Bolt-E4B: int4 codes with an f16 scale per 128 columns (w4a8) on the feed-forward, +# int8 on the same grid (w8a8) for attention and for layers 19-23, an int8 lm_head. One card. +# +# rad-convert --recipe data/recipes/gemma4-e4b-bf16-w4a8.recipe \ +# --set quantization_config.quant_method=compressed-tensors -o gemma4-e4b-w4a8.rad +# +# blk.N.attn_qkv is q|k|v of the 24 layers that keep a cache; the 18 KV-shared layers have q only +# (blk.N.attn_q). The per-layer-embedding linears (ple_gate 256x2560, ple_proj 2560x256, the +# 10752x2560 context projection) and the two embedding tables stay bf16: they are small, or read a +# row a token from host memory. The lm_head (262144 x 2560, the largest read at decode) is int8. +# +# Why the int8 parts (wikitext-2 KL against the bf16 original, 25500 positions, KV bf16): +# everything int4 0.612 everything int8 0.076 +# attention int8, FFN int4 0.327 layers 19-23 int8 0.339 +# attention + layers 19-23 int8 0.242 <- this recipe (3.16 GiB on the card) +# Layers 19-22 amplify rounding at single tokens even in bf16; int4 there costs as much as int4 on +# every attention linear. + +blk.19.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.19.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.19.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.19.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.20.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.20.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.20.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.20.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.21.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.21.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.21.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.21.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.22.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.22.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.22.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.22.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.23.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.23.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.23.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 +blk.23.ffn_down.weight rtn codes=i8 group=128 scale=f16 + +blk.*.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_q.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.*.ffn_down.weight rtn codes=i4 group=128 scale=f16 rule=search +blk.*.ffn_gate_up.weight rtn codes=i4 group=128 scale=f16 rule=search + +output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym diff --git a/data/recipes/gemma4-e4b-bf16-w8a8-df.recipe b/data/recipes/gemma4-e4b-bf16-w8a8-df.recipe new file mode 100644 index 00000000..319fb585 --- /dev/null +++ b/data/recipes/gemma4-e4b-bf16-w8a8-df.recipe @@ -0,0 +1,23 @@ +# gemma4-e4b-bf16-w8a8-df.recipe -- Gemma 4 E4B (text, vision, NVIDIA's DFlash drafter) from a bf16 checkpoint: +# every trunk linear int8 with an f16 scale per 128 columns (w8a8), an int8 lm_head, the drafter on +# block FP8, the vision tower bf16. Wikitext-2 KL against the bf16 original 0.076 (w4a8 recipe: 0.242). +# +# rad-convert --recipe data/recipes/gemma4-e4b-bf16-w8a8-df.recipe --draft-model \ +# --set quantization_config.quant_method=compressed-tensors -o gemma4-e4b-w8a8-df.rad + +blk.*.attn_qkv.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_q.weight rtn codes=i8 group=128 scale=f16 +blk.*.attn_o.weight rtn codes=i8 group=128 scale=f16 +blk.*.ffn_down.weight rtn codes=i8 group=128 scale=f16 +blk.*.ffn_gate_up.weight rtn codes=i8 group=128 scale=f16 + +output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym + +dflash.fc.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_q.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_gate_up.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.blk.*.ffn_down.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16 +dflash.draft_head.weight rtn codes=fp8_e4m3 block=128x128 scale=bf16