Repository navigation
Refuse a head count of 0 by name before any division: HIP Qwen3.5, nemotron, gemma4 Metal DFlash, DeepSeek V4.1 Metal vision - #3777
Conversation
|
@ashhart The bisect for the Metal memcpy link check that fails on main (body, "Gates") is done. It's not from this PR.
|
|
Thanks @jschmied. Refusing a zero head count by name where the division happens is the right place for it:
Each has a test that panics or admits on main and refuses here. Importing It applies to current main as it is. Its
|
…ision HIP's config path divided by num_attention_heads (hidden / heads without head_dim) and by num_key_value_heads / linear_num_key_heads (checks.products) before any check, so a 0 panicked; a linear_num_value_heads of 0 was admitted. Metal 27B, Metal 2B and CUDA already refuse a count below 1 in their readers; the host test pins all four.
…ad count of 0 before dividing Each reader took 0: nemotron divided hidden / heads without head_dim (and admitted heads 0 with it), gemma4's Metal drafter config took heads % kv_heads, DeepSeek V4.1's Metal vision tower took dim / heads. Each now refuses with its family's word.
…so its refusal tests run
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Head
b2cf452260(on main8cbef9777b). Found while building #3716: a config.json with a head count of 0 panicked on main (integer division by zero) instead of being refused. A correction to #3716's body: it named qwen27'shidden / headsas one of the panics, but Metal 27B already refuses 0; thehidden / headspanic is in the HIP Qwen3.5 path below.What panicked, and the fix
weights/config.Config.parse→qwen3_5/config.geometrynum_attention_heads: 0withouthead_dim:hidden / headspanics (config.zig:342).num_key_value_heads/linear_num_key_heads: 0:checks.products%panics (config_checks.zig:79).linear_num_value_heads: 0was admitted.error.ZeroHeadCount(new), fromconfig_checks.heads.geometrycalls it beforehidden / heads, andproductscalls it on all four counts. The oldattn_heads == 0→InvalidConfigline is gone because the new check covers it earlier.config.parsenum_attention_heads: 0withouthead_dim:hidden / headspanics (config.zig:407). Withhead_dim,heads: 0andkv_heads: 0were admitted.error.BadConfig(the family's word), plus awhy: "config.json declares 0 attention and 2 key/value heads; both must be positive".dflash_weights.Config.parsenum_key_value_heads: 0panics inheads % kv_heads.heads: 0was admitted.error.BadDraftConfig, as the CUDA twin (cuda_dflash.zig'ssize) already refuses a count below 1.vision.Config.parse→checkvision_config.num_attention_heads: 0panics inheadDim()(dim / heads).error.UnsupportedVision. The zero-count row now runs beforeheadDim().These were already safe, so nothing changed there: Metal 27B
qwen27/config.parse(requiredrefuses < 1 asBadConfig), Metal 2Bqwen3_5/config.parseand CUDAcuda_geometry.parse(both refuse < 1 asBadQwenConfig). The new host test pins all four Qwen3.5 entry points.Code sharing: main has no core refusal for head counts. Each family reads its counts with its own reader, and most readers already refuse 0. The fix therefore lives where the division is: in
config_checksfor the Qwen3.5 HIP path, which every caller ofproductsshares, and inline in the three family parsers.Grep across families and backends. I checked every
/and%by a head count in config parsing against the reader that feeds it. These read with a reader that refuses 0, or check for 0 first: qwen27 (Metal, dflash), qwen3 (+Metal), qwen4 (+cuda_attention), step5, llama, minimax_m3 (config, dflash2, dspark), flint, flashnext, kolibri1, dory, lighton_ocr, dots_mocr, lfm2, radio, ling, gemma4 CUDA (dflash, assistants), deepseek_v41 config, qwen3_5 drafters (CUDA, HIP), coredspine/joint_schema/qwen_vl,cluster/model. These accept 0 but never divide by it: glm, glm_dsa, kimi_k3.Evidence
A refusal test per entry point. Every test also passes on head 0 for each head count:
zig/qwen35_rules_host.zig"a head count of 0 is refused by name at every entry point, before any division". It covers every real Qwen3.5 config in the tree (layers_host.reals), withhead_dimas declared and removed, times the 4 head counts, times every entry point that admits the base. That is 136 cases: CUDA 28, Metal 27B 32, Metal 2B 4, HIP 72. 13 of the bases have nohead_dim, which is thehidden / headspath. The counts are pinned.config_checks.zig"sizes: … zero head counts are refused": each of the four counts at 0 →ZeroHeadCount.nemotron/config_test.zig"a head count of 0 is refused by name before hidden / heads": heads 0 and kv_heads 0, each with and withouthead_dim. Each givesBadConfig, and thewhynames the counts.gemma4/dflash_weights.ziganddeepseek_v41/metal/vision.zig: the zero rows are in the existing config tests.Nothing is loaded or queued before a refusal. Each refusal fires inside the config parse, which reads only config.json (and generation_config.json for HIP) bytes, before any weights file is opened. The tests call
parseon bytes withstd.testing.allocator, whose leak check shows the HIP arena and the nemotron/gemma4 JSON trees are freed on the refusal path.Red on main. I ran the same test files against main's sources:
thread … panic: division by zeroatqwen3_5/config_checks.zig:79(s.heads % s.kv_heads), viageometry←weights/config.parse. With the counts reordered:panic: division by zeroatqwen3_5/config.zig:342(model_width / attn_heads). Run as written, the test first fails by name (expected error.ZeroHeadCount, found error.InvalidConfigfor heads 0 withhead_dim).panic: division by zeroatnemotron/config.zig:407withouthead_dim. Withhead_dim, main returns a Config with.heads = 0(expected error.BadConfig).Snapshot (#3716's harness). The harness runs every real Qwen3.5 config, and 16,066 mutations of it (24 keys × 15 values, root and text_config), through all four entry points. Its output is byte-identical between main and this head: sha256
550e535d…32b5, the same digest #3716 recorded. Then I removed the harness's "skip 0 for the four head counts" line and ran it on head only. It adds 940 lines and no panic. Every zero on the text tower is refused: HIPZeroHeadCount76, CUDABadQwenConfig72, Metal 27BBadConfig64, Metal 2BBadQwenConfig8, and the rest by an earlier row such as quantization or a tied head. A zero at the root of a config that hastext_configis ignored, as every other root key is. Main cannot run those rows; it panics on the first one.Gates:
test-qwen35-rules-host test-qwen35-layers-host test-qwen35-formats-host test-qwen35-metal-scope-host test-nemotron-mtp-policy-host test-nemotron-draw-host: 20/20 steps, 53/53 tests.config.zig14/14,config_checks.zig6/6, nemotronconfig.zig13 passed and 1 skipped (as on main).pr_check.py: 0 errors. Lean: 221 vs 221 on main, 0 new.zig fmt --checkpasses.-Dfixed-cpu test,test-host, golden, kernel-contract, security, fuzz, release paths, x86 cuda-host):ci,release-paths,x86-cuda-host, fmt,pr_checkand lean pass.test: 10273/10352 tests with 1 failure;test-host: 2 failures. All three arecli_config_test"serve --config: expand reads the file…", which fails the same way in this x86 box's main-only runs (core: typed config field readers and named EOS policies; Qwen 3.5 CUDA, HIP and qwen27 Metal read through them (#2460 item 4) #3716 noted it oncf4555373and4ddc28cfc). It doesn't touch these files.b2cf452260, no local edits):zig build nativepasses, andzig build testpasses with no filters: 14886 of 14999 tests passed, 113 skipped, 0 failed. Both changed config tests pass on head.division by zeroinheadDim()(vision.zig:219). The gemma4 zero case getsheads = 0admitted instead ofBadDraftConfig.8cbef9777b: the libSystem memcpy link check atzig/build/metal_targets.zig:87. It passed on038e4a278, so something between the two pulled compiler-rt's memcpy intotensorfold-native. A bisect is running and I'll post the commit.deepseek_v41/metal/vision.zigwas reached by no test root. Its tests, the new zero case included, never ran in CI or inzig build test.zig/src/tensorfold.zig's test block now imports it, besidedeepseek_v41/metal/glue.zig, which is there for the same reason. Both existing vision tests (the defaults parse and the 2D RoPE table) pass.Served path. None of this reaches served code for a valid config. The snapshot shows every admitted config parses to the same Spec/Config bytes as on main, and no kernel or engine file is touched. I made no served A/B because there are no served-token or speed rows to show. Seeded, resume and concurrency rows don't apply either: the change only refuses configs that main panicked on (or that main admitted with a zero head count).
Overlap with #3716. Both PRs touch
zig/src/families/qwen3_5/config_checks.zig, in different hunks.git merge-treeof the two heads is clean, andtest-qwen35-rules-hostplus-layers-hostpass on the merge (7/7 steps, 12/12 tests). Whichever lands second rebases trivially. This PR does not need #3716's field layer.Proposed CHANGELOG line (Fixed): "A config.json head count of 0 is refused by name (HIP Qwen3.5
ZeroHeadCount, nemotron, gemma4 Metal DFlash, DeepSeek V4.1 Metal vision) instead of panicking on a division by zero."