Repository navigation
gpu, placement, model: BF16 dense weights in their words, picked per tensor (Qwen3.8) - #592
Conversation
… (shared dense_file checker)
…sites, the embedding names it
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix defect was established; the remaining items are advisory.
Non-blocking
⚠ Complete the code-generation proof: crates/gpu/src/q8f32.rs:203.
The shared F32 walk was generalized, and hyper-connection bodies changed. The PR reports no PTX comparison. Attach the move proof for the F32 refactor and existing-entry resource and new-entry spill checks for BF16, with FAIL-first evidence per new clause. Rerun gate-gpu-hc-gated at head.
⚠ Validate the model wiring: crates/model/src/arch/qwen35moe/roles.rs:211.
The raw-BF16 placement choice enables branches in program38, wide38 and mtp38. The PR reports synthetic operation gates but no real-model BF16 oracle run. Add mixed Q8_0/BF16 prefill, decode and borrowed-head MTP validation with output and fault comparisons.
Optimization headroom
- G. Per-launch and per-sync fixed cost: crates/gpu/src/arch/qwen3moe/program38.rs:648. Same-format shared gate/up weights can use the existing
Weights::join_rowsowner and one projection, removing one launch per layer per decode token [derived].
Checked
Duplicates: F32/BF16 share RowValues and join_plane_rows. Dryer reports zero pairs in its searched crates; GPU crates were excluded.
Complexity: diagnostics flag new gate functions and growth in existing dispatch, validation and model walks; complexity alone is no finding.
Silent failure: resident-format mismatches return named errors. bf16_gemv_ids rejects IDs at or past the matrix's row count, raises TokenId and writes NaN.
Tests, static mutation: swapping BF16 halves breaks the F32-reference bit checks. Accepting id == rows bypasses the fault required by gate_bf16's invalid-ID clause.
Gates: the BF16 head/embedding admission change carries PIN(2026-10-20). The PR reports FAIL-first for norm overflow.
Escape catalog: C1–C4 do not match the retained items.
Notes
Tests were not rerun during validation. The PR reports synthetic GB10 gate passes and identifies the earlier hyper-connection run and missing PTX/model evidence.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu-gates/src/bin/gate_deepseek41_chain_glue.rs … and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
…ions held in two-byte words #592 holds the 24 BF16 indexer projections of Qwen3.8 (q_proj 2,560×512 and k_proj 2,560×128 on each of the 12 selecting layers, 19,660,800 values) on the card at 2 B a value, not as f32. Card dense falls 39,321,600 B and the heap 18 granules, so the spread holds more experts under the same room. The sum is right; the pins were stale. Every moved pin carries PIN(2026-10-21) and its derivation: qwen4exp_meta's dense, rounding, max ctx and card plans (Q4 and Q3) and the bp plain row; qwen4exp_mtp_meta's drafted bp row and max ctx; the Mac replica qwen38_cards follows the same word rule. The qwen38 fixture's recorded budget moved 9,490,661,376 -> 9,482,272,768 (4 granules) in both header files, so the plan under it is [256; 4] again. Fixes #594. Co-Authored-By: Claude Opus 5.5 <[email protected]>
체크포인트가 BF16으로 담은 dense 가중치를 Q8_0으로 바꾸지 않고 BF16 그대로 GPU에서 읽는 공통 경로를 추가하고, Qwen3.8이 텐서마다 Q8_0과 BF16 중 하나를 고르게 합니다.
Part of #495.
What and why
This adds BF16 as a resident weight format on the card. A BF16 dense matrix is uploaded as it sits in the file (two values per
u32word) and read by one BF16 site: gemv for 1 to 8 columns, a wide tile, a row-list gemv, the output head and the token embedding. Qwen3.8 chooses per tensor between the Q8_0 site and the BF16 site.prepare --keep-bf16already leaves every BF16 matrix that would become Q8_0 (head and embedding included) in BF16, so this is the reader for what that option writes.Every BF16 output equals the F32 rule over the widened values bit for bit, because the BF16 kernels walk the same lanes in the same order as the F32 kernels. Models that do not turn the new placement flag on keep their placement byte for byte.
crates/gguf/src/qtype.rs,crates/gguf/src/card.rs): the BF16 row of the shared card table namesBf16in its dense, head and embedding columns, so the entry definitions, the file type and the activation rule are table reads like every other format. Its default and routed columns stayBf16AsF32.crates/placement/src/placement.rs):ModelTensors::bf16_wordsandModelTensors::card_format. On a model that turns the flag on, a BF16 tensor of two or more dimensions in attention, hyper-connection, shared expert, dense FFN, engram dense, head or token embedding getsCardFormat::Bf16Raw. One-dimensional tensors, routers and norms stayBf16AsF32.card_format_of_roleremains the role rule, andcard_formatis the one entry every caller uses (card_segment,place_whole,whole_on_card, the plan rules andwhole_need).crates/gpu/src/weights.rs):DevWeight::Bf16, a raw upload that copies the file bytes,Weights::bf16, and onejoin_plane_rowsfor joined F32 and BF16 rows. An oddkor a length mismatch is refused by tensor name.crates/gpu/src/q8f32.rs,gemm/f32tile.rs,q38.rs,hc_gated.rs): the F32 lane walk is generalized overRowValues(F32 values or BF16 words). New entries arebf16_gemv,bf16_gemv_ids,bf16_tile_gemm,embed_rows_bf16,hc_gated_down_bf16_4x320andhc_gated_up_mix_bf16_4x320.crates/gpu/src/site.rs):SiteTy::Bf16, BF16 arms ingemv,gemmandresident_gemv, and three entry points that dispatch by resident form:resident_gemv_cols,resident_gemmandresident_quantize. GLM'sbody::gemvcallssite::resident_gemv, so GLM projections get the BF16 site as soon as itsModelTensorsturns the flag on.crates/gpu/src/head.rs):OutW::Bf16sharesargmax_finitewith Q8_0. The K-quant launches are unchanged.plan38,program38,wide38,mtp38,body38'shead_formand the embedding accept BF16 next to Q8_0 and F32. The hyper-connection mix and the embedding lookup read one resident matrix view,HcMatrixinhc_gated.rs(namedEmbedRowsinq38.rs), built fromWeights::residentand checked by oneshape. The MTP draft head can borrow a BF16 target head and embedding (bf16_gemv_ids,BorrowedHead::Bf16,HeadOut::Bf16). The draft's owneh_projand its store-walk q, k and v use the same common site.hc_gated.rs, every sum that feeds SiLU, sigmoid or a square root is checked before the nonlinearity (norm sum and epsilon sum, the four down streams, the four inject streams, in the capped and wide paths). A non-finite sum writes NaN and raises the site fault instead of a finite value such as sigmoid(infinity) = 1.model/src/arch/coverage.rs,placement/src/kernels.rsandplacement/src/accepts.rs; the BF16 mapping check intools/hf-arch-check.py; PTX shape rows for the new entries intools/ref/ptx-shapes*; agate-gpu-bf16recipe in thejustfile; the--keep-bf16usage note forprepare.Release notes: Added: BF16 dense weights, head and embedding run on the card as BF16 words through one shared site, chosen per tensor by Qwen3.8 placement. Output matches the F32 rule bit for bit.
Code shape
site::resident_gemmandsite::resident_quantize.ModelTensors, the card table and the common site. Qwen3.8 supplies tensor roles and shapes. No common owner gained a per-model branch.wide38andmtp38and the embedding's own BF16 reader are removed.k, a tilekthat is not a multiple of 64, an out-of-range row id and a non-finite sum are named refusals, faults or NaN outputs.tools/model-tax.tsvrow is thegate_bf16.rsPIN.The synthetic-file helpers (
Decl,decl,q8_0_bytes,host_rows,columns) thatgate_bf16andgate_mxfp8both needed live once incrates/gpu-gates/src/bin/shared/dense_file.rs. The store-walk helpers are merged intosite::resident_gemmandsite::resident_quantize, the down-row end of the hyper-connection kernels intohc_gated::down_row_end, and the head tensor name isweights::HEAD_TENSOR.What I ran
The PR head is
0e8644f60c4c74067f32aa2a23e493bb470b6c9bon upstream main3da32e779a76dd2f1c9c4f3a0746865fb7521586.gate_bf16ran at0e691b61bc101d1c80126078b17254f7d0394d92, which differs from the PR head in one source-tool path (tools/hf-arch-check.py) and no crate, manifest or recipe, so that result carries to the PR head.gate_mxfp8and thehf-arch-check.pyself-test ran at the PR head.gate_hc_gatedran at9c0b0c22160cdb100f053ad6f543dae5087bd32a; the later commits change host code inhc_gated.rsandq38.rs(the shared matrix view) and no device function, andgate_hc_gatedwas not rerun after them.just lintand acargo checkon the card were still running on the PR head when this was written.The oracle is the F32 rule over the widened BF16 values, plus the derived error band, on synthetic tensors with the shapes of Qwen3.8's attention, head and embedding, loaded through the placed path.
GPU card, a DGX Spark (GB10) in the dev container image
bloomery-dev:cuda13.3.1. The gate run's own record of the card is the query lineNVIDIA GB10, 595.84, 12.1(name, driver, compute capability). Rawnvidia-smioutput from the same node and image, taken at thegate_hc_gatedrun:Gate commands on that card, each recipe run with local execution enabled, and their exit lines:
gate_bf16: a 64-column GEMM on 8192x2560 against the F32 rulebloomery-placementtests (CPU host)The BF16 64-column GEMM equals the F32 rule in all 524288 outputs of the shape shown.
The
gate_bf16log also shows the BF16 gemv, the head (4099 rows, k=2560, tokens equal to the argmax) and the embedding lookup equal to the F32 rule, andgate_mxfp8shows its 16384-row tile at K=1536 equal in 1048576/1048576 outputs.gate_hc_gatedchecks both hyper-connection sites against the f64 rule within their bands and every stage bit for bit against the card rule. With the norm boundary reverted to its earlier code,gate_hc_gatedexits 1 on the new norm clauses, and with the fix restored it exits 0:tools/hf-arch-check.py --self-testpasses at the PR head, including the check thatSiteTy::Bf16resolves to the BF16 row of the card table:To reproduce, from the repository root with CUDA configured:
just gate-gpu-bf16 just gate-gpu-hc-gated just gate-gpu-mxfp8 cargo test -p bloomery-placement --libThis PR makes no speed claim and runs no PTX comparison at this head. BF16 dense reads more bytes per token than Q8_0, so decode is expected to be slower than on a Q8_0 split.
What I ran into
The following does not block this PR. I did not run a real-model BF16 oracle: the BF16 branches of
program38,wide38andmtp38are checked through the kernels' gates and through placement and admission tests, not through a model run. A same-lease prefill A/B for the existing GGUF path is also not part of this PR.Hardware
A DGX Spark (GB10) for the GPU gates (driver 595.84, CUDA 13.3 in the dev container). A separate CPU host for the placement tests and the
hf-arch-check.pyself-test.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.