Skip to content

feat(qwen4): source-precision KLD teacher (kld_teacher.py) - #815

Open
fivetide wants to merge 2 commits into
warpfront:betafrom
fivetide:feat/qwen38-flash-next-kld
Open

fivetide wants to merge 2 commits into
warpfront:betafrom
fivetide:feat/qwen38-flash-next-kld

Conversation

@fivetide

@fivetide fivetide commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

qwen4_kld.rs on beta documents reference_oracle/kld_teacher.py as the source-precision teacher whose logits qwen4_kld import turns into a reference, but the script never landed. This adds it.

Why

The engine admits Qwen4 routed experts only as MQ4, so an engine-built teacher (e.g. a BF16-trunk HFQM) cancels expert quantization out of every KLD measurement. This teacher runs the pinned upstream operators (upstream.PinnedQwen4Operators, BF16 weights, F32 activations) on a local copy of the pinned checkpoint.

What

  • crates/hipfire-arch-qwen4/reference_oracle/kld_teacher.py: layer-major over every chunk of an existing HFKLDR v3 reference (each checkpoint byte read once per run); writes raw F32 logits [chunk][scored position][vocab], the layout qwen4_kld import reads. import keeps owning top-k, teacher NLL, the plausibility gate and the HFKLDR format.
  • Refuses a checkpoint directory whose index/config do not match the pinned revision (MODEL_INDEX_SHA256, MODEL_CONFIG_SHA256).
  • PLE n-gram rows are discovered in a first pass, then streamed shard by shard: on NAS-backed storage (~250 random reads/s) row-by-row lookups took 36 min vs 15 min streamed.
  • CHANGELOG entry under v0.4.1 Internal & CI.

Evidence

Measured on gfx1151 (WikiText-2 slice, 32 × 512, window [256, 511)): teacher PPL 5.4541, ~62 min per reference, NFS-bandwidth bound. After the rebase onto beta: py_compile passes and every upstream / quality / schema symbol it imports exists on beta. Not re-run end-to-end after the rebase.

Usage

python3 kld_teacher.py --checkpoint DIR --tokens-from REF.kldref --output TEACHER.logits [--max-chunks N] [--device cuda]
qwen4_kld import --logits TEACHER.logits --ref REF.kldref --teacher ID_FILE --output SRC.kldref

Bjoern Agent added 2 commits October 4, 2026 13:42
…point

The engine only admits MQ4 routed experts, so an engine-built teacher
cancels expert quantization out of every KLD measurement. kld_teacher.py
runs the pinned upstream operators (BF16 weights, F32 activations) on a
local copy of the pinned Qwen3.8-Flash-Next checkpoint, layer-major over
every chunk of an HFKLDR v3 reference so each checkpoint byte is read
once, and writes raw F32 logits for the scored window.

The checkpoint directory is refused unless its index and config match the
pinned revision. PLE n-gram rows are discovered in a first pass and then
streamed shard by shard: the NAS backing the checkpoint serves ~250 random
reads/s, so row-by-row lookups took 36 min versus 15 min streamed.

Measured on gfx1151 (wikitext2 slice, 32 x 512, window [256, 511)):
teacher PPL 5.4541; ~62 min per reference, NFS-bandwidth bound.
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