mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2179] [CLOSED] core: read the model's geometry from its GGUF metadata and refuse a shape the kernels are not compiled for #3906
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3906
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2179
Author: @gt50
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:geometry-from-gguf📝 Commits (4)
d1ec4c5core: the model's geometry is read from its GGUF metadata and checked against the shape the kernels are compiled ford49935etests: the GGUF fixture's metadata helpers set fields by name8034b09artifact: read_geometry refuses another architecture by name before reading any qwen4exp keyd759fedgenerate: the prompt-chunk sizing and the state fingerprint take their QSA shapes from qsa_shapes(g)📊 Changes
42 files changed (+668 additions, -182 deletions)
View changed files
📝
CMakeLists.txt(+4 -0)📝
include/strata/artifact/gguf_reader.hpp(+165 -24)➕
include/strata/core/geometry.hpp(+70 -0)📝
include/strata/core/layout.hpp(+15 -40)📝
include/strata/kernels/cpu/expert.hpp(+4 -0)📝
src/core/layer.cpp(+1 -3)📝
src/core/mtp.cpp(+1 -9)📝
src/core/session.cpp(+1 -6)📝
src/core/verify.cpp(+1 -9)📝
src/kernels/cuda/fused_gdn.cu(+2 -0)📝
src/kernels/cuda/fused_gr.cu(+2 -0)📝
src/kernels/cuda/native_gdn.cu(+2 -0)📝
src/kernels/cuda/native_ple_postops.cu(+2 -0)📝
src/kernels/cuda/native_qsa_indexer.cu(+3 -0)📝
src/kernels/cuda/native_qsa_score.cu(+3 -0)📝
src/kernels/cuda/qsa_decode_attn.cu(+2 -0)📝
src/kernels/cuda/qsa_prompt_attn.cu(+2 -0)📝
src/kernels/cuda/qsa_select.cu(+3 -0)📝
src/kernels/cuda/s2_expert_grouped.cu(+2 -0)📝
src/kernels/cuda/verify_kernels.cu(+2 -0)...and 22 more files
📄 Description
Title
Read the model's geometry from its GGUF metadata and refuse a shape the kernels are not compiled for
Summary
The engine took its dimensions from
ModelGeometry's defaults and read only the expert count, the experts per token and the rope keys from the model file;check_architecturecompared six keys with numbers written into the guard. Any other key was never looked at: a file that declares, say, an indexer budget of 1024 ran with the kernels' 2048 and said nothing. Now the whole geometry comes from the file'sqwen4exp.*keys, and a file of a shape the kernels are not compiled for is refused at load, naming the key. For every file the guard accepts nothing changes: the same numbers reach the same kernels, and the output is the same (measured below).This does not make another architecture run (the forward pass and kernels are still qwen4exp's); it is the step a second model would start from: one place that says what the file declares, one that says what the kernels are compiled for, and the check between them.
What changed
include/strata/core/geometry.hpp(new):ModelGeometry, moved out oflayout.hppand dependency-free so kernels can include it, with the GGUF key of each field and new fieldsn_vocab,rms_eps,n_rot,idx_block,idx_top_k,n_expert_used.kCompiledGeometryis the shape the kernels are compiled for.include/strata/artifact/gguf_reader.hpp:read_geometry(f, g)fills the geometry from the metadata shard (llama.cpp's key names). Another architecture is refused by name first. The six keys the guard always required stay required; any other absent key keeps the compiled value. Keys that state one thing twice must agree:full_attention_intervalandcompress_ratios(whose non-zero entry is the pooling block), key and value head widths, routed and shared expert widths,ssm.inner_sizeandstate_size x time_step_rank. Experts per token 1..64 and at most the expert count.geometry_unsupported(g)names the first key whose value the kernels are not compiled for, e.g.qwen4exp.attention.indexer.top_k = 1024, the kernels are compiled for 2048. Only the expert count (the GSQ-RCO Coder's 256), the experts per token and the vocabulary may differ.check_architectureis the two together;Qwen4ExpGuardis gone.static_assertit againstkCompiledGeometry(fused_gr, qsa_decode_attn, qsa_prompt_attn, qsa_select, native_qsa_indexer, native_qsa_score, fused_gdn, native_gdn, verify_kernels, s2_expert_grouped, native_ple_postops, cpu/expert.hpp; insycl/the same plus qsa_prompt_attn_xmx), so a kernel and the struct cannot drift apart without the build failing.src/program/generate.cpp: the geometry and K come fromread_geometryand are checked before any weight moves; the native embedding takesn_embd/n_vocabfrom it instead ofg0and a literal 248320.qsa_shapes(g)(layout.hpp): one function builds the QSA kernel shapes from the geometry, used by layer, mtp, session, verify, prefill, generate's prompt-chunk sizing and the state fingerprint (each built them by hand before; n_rot, idx_block and idx_top_k came from constants).sycl/: the same changes in its copies of generate, layer, mtp, session, verify and prefill.tests/core/gguf_geometry_test.cpp(synthetic GGUFs: the full key set, the six required keys, a pruned expert count, every disagreement case, unsupported shapes, a denseqwen35file, another architecture;--real SHARD1prints a real file's geometry and the verdict).gguf_fixture.hppwrites f32 and array keys.Extra Notes
--spec 4 --mtpand the server's other flags, greedy, 256 tokens; this branch andmaina0116b27both built here withtools/hip/build_windows.bat(gfx1151, engine 0.1.43.1):main421, 428, 554 tok/s; that spread is run to run on both (on the 0.1.40.2 base, two local builds read it at 404 and 411 tok/s, mean of 3).attention.indexer.top_kpatched to 1024 (only the metadata shard changed):mainloads and answers with 2048; this branch refuses in 0.5 s with the message above.--native:architecture is 'qwen35', this engine requires 'qwen4exp'in 0.5 s, asmainsays.hip_handoff(the Windows HIP failure in docs/AMD_HIP.md),ple_parity,expert_parityandpool_test(the Q2_0 model and pack fixtures). The GGUF tests also pass built with MSVC/W4 /WX.static_asserts.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.