feat(bfp-quant): serve attention+GDN projection weights as bfloat4_b (#62) #99
No reviewers
Labels
No labels
cards:go
hermes-approved
human-approved
human-approved
iter
0
iter
1
iter
2
iter
3
prio:high
prio:low
prio:med
priority/high
state
blocked
state
doing
state
done
state
review
state
todo
x280
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitpartner/tt-stack!99
Loading…
Reference in a new issue
No description provided.
Delete branch "bfp4-overlay"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lands the bf4 weight overlay on master, split out of the WIP deploy branch
deploy/g2-prefix-0019so it is not blocked behind that one.Why
Master has none of
QWEN36_ATTN_GDN_BF4. Serving a grid-snapped "G2" checkpoint on master therefore produces 256 BFLOAT4_B tensors (the four MLP projections) against 128 BFLOAT8_B (attention and GDN) across all 64 layers — G2's re-rounded values at the stock dtype mix. That is the worst of both, and it means no bfp4 serving measurement currently exists. This flag is the precondition for one.Re-derived over the validated byte accounting, it is worth 3.72 ms/token of weight read (20.24 -> 16.52) and ~1.8 GiB/card.
What it does, precisely
QWEN36_ATTN_GDN_BF4=1switches 5 weight sites inattention/tp.py(wqkv-fused / wqkv / wk / wv / wo) and 5 ingdn/tp.py(qkvzab / qkvz / ab / out / out.colpar) frombfloat8_btobfloat4_b. Default off; unset, both files are byte-identical in behaviour to master.Weights only. Activations, the KV cache and the GDN state are untouched. In particular the
ttnn.typecast(q|k|v, bfloat8_b)sites on theQWEN_SDPA_BF8path keepbfloat8_bexplicitly — a blanket dtype substitution would have caught the query cast atattention/tp.py:766and silently made activations bf4.It is a weight-format switch, not a quantiser: it says how the loader packs whatever the checkpoint holds. Over a checkpoint not rounded onto the bfp4_b grid it degrades to round-to-nearest bf4 and is measurably worse than production (KL 0.176 vs 0.111). Pair it only with a grid-snapped checkpoint; G2 is the measured pairing (KL 0.085, top-1 0.944, GSM8K 58/60).
Two things worth reviewing
1.
gdn/tp.pywas rebuilt on master's copy, not carried over. The development branch predates #86, and a direct copy would have silently deleted master's column-parallel prefill out-projection,_silu_mul, the guardedrecurrent_gated_delta_rule_decode_packed_ttnnimport and the loguru logger — 66 deletions. The hunk here is re-applied onto master's file instead; the diff is +23/-10 and touches nothing else.2.
out_colpartakes the same dtype as the other four. It did not exist when the overlay was written. If it had been left atbfloat8_b, runningQWEN36_GDN_OUTPROJ_COLPARtogether with bf4 would serve that one projection at bf8 while the banner claimed all-bf4. Flagging it explicitly since it is the one judgement call in the patch rather than a mechanical re-apply.Scope / inertness
weight_mapping.pyandbfp4_unpack.pyadd bfp4-packed-v1 checkpoint loading. They key offbfp4:safetensors metadata and are inert without it. Master'smodel_config.pyalready imports the five symbols these provide (is_fp8_checkpoint,is_nvfp4_checkpoint,load_qwen36_state_dict_fp8,load_qwen36_state_dict_nvfp4,remap_qwen36_state_dict) — all present.modules/tenstorrent-serving.nixmount lines and theweightsBf4/bfp4Packedoptions stay on the deploy branch; landing them here would put myweight_mapping.pyover the in-image copy on the FP8 path too, which is a behaviour change this PR should not smuggle in.model.pyandtp_common.pydiffer between the branches purely from master-side drift (#85, #76, #87, #86). The development branch never touched them and neither does this PR.Pre-existing hazard, not introduced here
The tensor cache names bins by tensor + dtype, never by checkpoint. Two checkpoints sharing a dtype therefore collide. That is unchanged by this PR but it bites bf4 arms in practice — use a distinct
cache_dirper checkpoint.Licensing
ThinkingCap is PolyForm Small Business 1.0.0. This change ships code only; no weights are published or redistributed, and the use case is internal serving. Recorded here so it is on file.
Refs #62.
🤖 Generated with Claude Code
agent-gateway closeout (merged): cleared
agent:*labels.Hermes kanban card (if any) is left for Hermes to archive/complete.