Repository navigation
Conversation
…134) ggufs packed before the Q2_0_G128 -> PQ2_0 rename carry the old ftype value 142. The format did not change, only the enum did, so these files load and compute correctly but print print_info: file type = unknown, may not work which reads as a broken file. With this they print print_info: file type = PQ2_0 - 2.13 bpw (group 128, legacy ftype) Naming only. No load path, no quantizer path, and no behaviour changes; the new constant exists so the switch has a case for the value. Worth noting the collision that makes this confusing: 142 is also GGML_TYPE_PQ2_0, the tensor type id, which is current and correct. Only the ftype was renumbered, to 141. Verified on a published gguf that carries ftype 142: reports unknown on the current branch, reports PQ2_0 with this change, same output either way.
…share an input (#137) * hadamard: share the activation transform between folded weights that share an input Folded weights that consume the same activation were each building their own identical transform. ggml does no common-subexpression elimination, so the sign-multiply and the FWHT ran once per weight rather than once per activation. Three groups share an input on this architecture: ffn_gate + ffn_up build_ffn LLM_FFN_PAR, both take cur 64 redundant attn_qkv + attn_gate qwen35.cpp:237,241, both take input 48 redundant attn_q + attn_k + attn_v qwen35.cpp:270,282,285, all take cur 32 redundant That is 144 of 401 folded weights doing a transform that already exists, so 36% of the FWHT calls per token were duplicates. build_lora_mm and build_lora_mm_id now memoize on (input, rotation). Both must match for the transform to be shared: same input tensor and same rotation, which also implies the same width and therefore the same sign vector. The map lives for one graph build. Measured on M5, Metal, a folded low-bit checkpoint, three interleaved pairs on a warm machine: pp512 358.29 -> 370.74 +3.5% tg128 23.20 -> 23.91 +3.1% Run-to-run spread was at most 1.1 on pp512 and 0.11 on tg128, so the gap is well outside the noise. Greedy output is unchanged, byte for byte, on the same prompt. The size of the win matches the prediction: the transform stack was about 10% of traced GPU time, and removing 36% of it should be worth about 3.5%. * hadamard: trim the memo comment to two lines per AGENTS.md
Inverts the runtime gate from opt-in (GGML_HOPPER_Q1) to opt-out (GGML_HOPPER_Q1_DISABLE) for builds configured with GGML_CUDA_HOPPER_Q1. The build-time flag is unchanged and still off by default, since it requires a CUTLASS checkout. Validated internally: prefill improves for the shapes this path serves and decode is unaffected. A control arm with the path disabled matches baseline, so the sm_90a plus CUTLASS build costs nothing by itself. The per-128-K activation scale is coarser than q8_1's per-32, so results are not bit-identical. The deviation was measured against a same-path control; it is small and the tail is bounded.
There was a problem hiding this comment.
🟡 Changes recommended
Default dispatch can incorrectly reach unsupported Blackwell devices, and unrelated API and graph changes are incomplete or undocumented.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Enables the Hopper WGMMA prefill path by default, but also includes undocumented graph memoization and legacy ftype changes.
Changes:
- Inverts the Hopper runtime gate to opt-out.
- Adds Hadamard transform memoization.
- Adds legacy PQ2_0 ftype naming.
File summaries
| File | Description |
|---|---|
ggml/src/ggml-cuda/mmq-hopper-q1.cu |
Enables WGMMA by default and documents numerics. |
src/llama-graph.h |
Adds the Hadamard memo cache. |
src/llama-graph.cpp |
Reuses cached Hadamard transforms. |
include/llama.h |
Adds a legacy PQ2_0 ftype. |
src/llama-model-loader.cpp |
Names the legacy ftype. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| LLAMA_FTYPE_MOSTLY_Q1_0 = 40, // except 1d tensors | ||
| LLAMA_FTYPE_MOSTLY_Q2_0 = 41, // except 1d tensors | ||
| LLAMA_FTYPE_MOSTLY_PQ2_0 = 141, // except 1d tensors (Prism group-128 Q2_0; matches published PQ2_0 ggufs) | ||
| LLAMA_FTYPE_MOSTLY_PQ2_0_LEGACY = 142, // pre-rename value for the same format, still found in published ggufs |
| // Activations are quantized fp32 -> int8 with a per-128-K absmax scale, coarser than q8_1's | ||
| // per-32, so this path is NOT bit-identical to standard MMQ. The deviation has been measured | ||
| // against the same build with the path disabled, using a same-path control to establish the | ||
| // floor: it is small, the tail is bounded, and only a small fraction of tokens change their | ||
| // argmax. Figures are recorded in the internal notes. If you need bit-exact output, set | ||
| // GGML_HOPPER_Q1_DISABLE. |
There was a problem hiding this comment.
Fixed in d5f32d9. Trimmed to three single-statement lines: what the path is, that it is default-on under GGML_CUDA_HOPPER_Q1 with GGML_HOPPER_Q1_DISABLE as the opt-out, and that it is not bit-identical because activations use a per-128-K int8 absmax scale rather than q8_1's per-32.
The pointer to internal notes is gone, since it was unreadable for anyone outside the org.
| // Transforms shared by folded weights on the same activation. Key is (input, rotation); | ||
| // both must match. Valid for one graph build only. | ||
| mutable std::map<std::pair<const ggml_tensor *, const ggml_tensor *>, ggml_tensor *> hadamard_memo; |
There was a problem hiding this comment.
No longer applies. This PR was retargeted from prism to prism-v7, and the diff is now one file, ggml/src/ggml-cuda/mmq-hopper-q1.cu at +7/-7. The llama.h ftype and the Hadamard graph memoization were never part of this change; they came from diffing against the wrong base.
The observation stands on its own merits for whenever that ftype does land: a public llama_ftype value needs mirroring in gguf-py/gguf/constants.py and adding to llama_ftype_get_default_type.
…ment GGML_CUDA_CC_BLACKWELL is 1200, the sm120 family, not the start of Blackwell. Blackwell spans CC 1000, 1100 and 1200, so the old cc >= GGML_CUDA_CC_BLACKWELL bound let sm_100 and sm_110 reach an sm_90a wgmma kernel. That was unreachable while the path was opt-in and becomes reachable once it defaults on, so bound the dispatch to the 900 series. Also use GGML_CUDA_CC_HOPPER instead of a literal 900. The macro does exist in this tree, contrary to the comment that was there. The file comment is shortened to the concise form AGENTS.md asks for and no longer points at notes a reader of this repo cannot open.
This PR targets Test notes from our side (L40S, sm_89, CUDA 12.8, the two commits cherry-picked onto
We have no Hopper here, so the H100 numerics behind the flip are unverified by us; the unticked re-run after the gate inversion would be good to have in the retargeted PR. Nothing in shipped release binaries changes, since the build option stays off. |
|
Superseded by #171, which is the re-branch you asked for: fresh branch off Closing this one rather than repairing it. Changing the base here in place did exactly what you predicted: it pulled in Also worth flagging for anyone who lands here from search: the branch name |
What
Flips the runtime gate on the Hopper (sm_90a) wgmma prefill path from opt-in to opt-out. In a build configured with
GGML_CUDA_HOPPER_Q1, the path is now active unlessGGML_HOPPER_Q1_DISABLEis set.The build-time option is deliberately left off by default, because it requires a CUTLASS checkout via
GGML_CUDA_CUTLASS_DIRand would otherwise break configuration for everyone else. See "Scope" below for what that means in practice.Lineage
Supersedes #106, which was opened against the now-closed
prismbase. Its head branchhad fallen 1131 commits behind that base, so the PR rendered as a 118-file diff of fork
divergence rather than this change. This PR targets
prism-v7from a cherry-pick of thesame commit, and the resulting diff is the one file below.
ggml/src/ggml-cuda/mmq-hopper-q1.cu, +13/-6: the gate inversion at line 452 plus theheader comment that documents the new default and the non-bit-exact activation
quantization. The group-128 rename to
PQ2_0was already in place onprism-v7, sonothing else needed touching.
Why
The path had never been built or exercised. It turns out to work, and to be worth having on for the shapes it serves.
Validated internally on Hopper with a three-arm comparison: baseline build, this build with the path off, and this build with the path on. The path-off arm matches baseline closely on every measurement, so the sm_90a plus CUTLASS build costs nothing by itself and the improvement is attributable to the path rather than to the build. Prefill improves; decode is unaffected, which is the expected behaviour for a prefill-only path and a useful check that nothing leaked into the wrong dispatch.
The gain is larger for the wider of the two low-bit types, consistent with it having more unpack work for int8 wgmma to absorb, and shrinks as the token count grows, so standard MMQ closes the gap on long prompts. Numbers are in the internal notes rather than here.
Numerics
This path is not bit-identical to standard MMQ. It quantizes activations to int8 with a coarser per-128-K absmax scale where q8_1 uses per-32, and the original source comment flagged it for validation. That validation has now been done, using the same binary with only the env flag differing, against a same-path control to establish the floor.
The deviation is small and the tail is bounded. Perplexity moves well inside its error bar, and a small fraction of tokens change their argmax. It is acceptable for the prefill gain, but it is a behaviour change rather than a pure optimization, which is why the opt-out exists and why the measured figures are recorded in the source comment for whoever reads this next.
Scope and what is not changed
GGML_CUDA_HOPPER_Q1still defaults off at configure time. Shipping this in release binaries is a separate CI question, since the build image would need CUTLASS. Happy to do that as a follow-up if we want it in prebuilt artifacts.Test plan
arch=compute_90a,code=[compute_90a,sm_90a]with CUTLASS includes.test-backend-ops test -b CUDA0, zero failures in both arms.