Skip to content

glm5next prompt GEMM front by weight type; qwen38 K-quant embedding, Q5_K head and dense sites by name - #851

Closed
midagedev wants to merge 5 commits into
mainfrom
qfront
Closed

midagedev wants to merge 5 commits into
mainfrom
qfront

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Stacked on #841 (its 3 commits are the first ones here); merge #841 first.

GLM-5.3-Flash prompt front. A prompt batch projects each mixer site through the GEMM front of its weight type (Q8_0, K-quant, BF16); split weights go through a stage buffer and a strided copy. No new kernel (ptx 478 = 478). Derived: pp +28…40 % on a K-quant mixer file against the chunked gemv; not measured (no such file on the box). The mixer variants are remade under new tags (glmmixk, glmmix4) because the front raises the recorded budget; the sets are keyed by path, so no file a set names changed.

Qwen3.8. K-quant embedding rows, a Q5_K head (up to eight rows through the common head), and the dense sites by name through site::ByName. The head's launches per row count have one owner, head::HeadLaunches; the gates count from it. Opens the dense side of Unsloth's UD-IQ1_S, IQ1_M, Q2_K_XL and IQ3_XXS files (proven on fixture variants q38glue and q38dense, not on the real files).

Evidence (box): FAIL-first per new clause (q38glue verify node count was red at 117 vs 116 before HeadLaunches); the train 3 fixture batch on main 511262a + #841 + this + #835 + #843 + #844 + #848: DONE total=272 red=0 tier=fixture wall=3961s.

Implemented by Sonnet rounds, reviewed and finished by the lead (Claude Opus).

🤖 Generated with Claude Code

midagedev and others added 5 commits October 27, 2026 05:42
…file's K-quant, BF16 and F32 attention, ssm, indexer and NextN weights open

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s, and glm's coverage row allows its absorbed-pair pin

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…heir own pins, so a type its gemv does not read is refused at plan; a BF16 position table loads widened

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ont of its weight type (Q8_0, K-quant, BF16), split weights through a stage and a strided copy

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…me; the common head counts its launches per row count; the GLM mixer variants under new tags

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 26, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: scatter is copied byte for byte into two crates; one owner must serve both.

Must fix

1. scatter is defined twice (kind B, duplicate of an existing owner)

gemm.rs:946 and site.rs:1029 are the same function: same (rows, m) and (at, stride) arguments, same dtod_2d call with the same Pitched fields. The only difference is gpu.stream() against a stream argument. A fix to the pitch rule in one copy would leave the other wrong.
Cost: the fix removes a function and two imports, and adds one pub.
Fix: in crates/gpu/src/site.rs make the existing one public (pub fn scatter(, body unchanged). In crates/gpu-glm5next/src/gemm.rs delete fn scatter, change the call at line 857 and the import at line 71:

                    site::scatter(gpu.stream(), &*q, (n, m), y, (p.at, stride))?;
use bloomery_gpu::{Gpu, GpuError};

Non-blocking

⚠ site.rs:300: resident_gemv_cols_on went from pub(crate) to pub, and its only caller outside site.rs is program38.rs in the same crate. Keep it pub(crate).

Optimization headroom

  • E Less work: gemm.rs:855-858. A part of an unjoined projection is written to the stage, then copied. Per part, per layer, per prompt batch: 1 launch and 2·m·rows·4 bytes (read and write) [derived]. A GEMM output stride would remove both. This needs a kernel change, so it is its own piece of work.

Checked

  • Duplicates: 24 new items checked; hit: scatter (finding 1). dryer: 0 pairs.
  • Complexity: GemmFront::project 17→31 and check 11→17 are new type dispatch in one owner; PromptProgram::mla 50→64 is more by-name branches, no split asked; ByName::gemv_on 29 is a type match, one owner. No #[kernel] body touched.
  • Silent failure: 6 sites followed (m and at + rows guards, Dst::Query with a stride, missing q8_1 form, Q5_0, unjoined parts, HC fn type). Each gives a named error. dtod_2d checks its bounds.
  • Tests: head unit test (three-row Q5_K head against the one-row head, bit for bit). Mutant: swap self.m and self.n_vocab in token_major.enqueue; the test turns red. by_name_extra table: mutant RowMajor to ColMajor turns it red. Gate g4: all-NaN start buffers mean an unwritten row fails.
  • Gates: pins moved with a dated PIN(2026-10-26) and a reason (act_rule BF16, coverage TypePins and RowPins, model-tax rows, g4 error text). The new g4 band NEAR has a derivation.
  • Performance: touches the prompt path (GEMM front). project builds three small Vecs per call, about 100 per prompt batch; the term is negligible beside the GEMM. No new sync point. Class: new type dispatch on an existing GEMM, no new kernel (ptx 478 = 478 per the PR body).
  • Escape catalog: fixture-requant.sh was read for C1 to C4. The case and the array expansion are fine. No match.

Notes

  • The PR body gives a derived +28…40 % pp and says it is not measured. CONTRIBUTING.md asks for the nvidia-smi line, both commit hashes, the model file and the just gate-* commands with output. The body has a batch summary only. Please add it so the gate result can be read on its card.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/act_rule.rs, crates/gpu-gates/src/bin/gate_glm5next_e2e.rs, crates/gpu-gates/src/bin/gate_glm5next_gemm.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

(Dst::Query, _) => gemm(gpu, &k, dense, (w, p), &x_in, m, q)?,
(Dst::Caller(y), stride) => {
gemm(gpu, &k, dense, (w, p), &x_in, m, q)?;
scatter(gpu, &*q, (n, m), y, (p.at, stride))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

site::scatter in crates/gpu/src/site.rs is the same function; make it pub and call it here, then delete fn scatter below and the Pitched, dtod_2d import.

Suggested change
scatter(gpu, &*q, (n, m), y, (p.at, stride))?;
site::scatter(gpu.stream(), &*q, (n, m), y, (p.at, stride))?;

@midagedev

Copy link
Copy Markdown
Owner Author

Superseded by #853 (rebased onto main after #841, with the scatter must-fix).

@midagedev midagedev closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card placement Placement planning: crates/placement tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant