Skip to content

Qwen3.5: one layer-pattern reader for every backend (#1863, part 2) - #2086

Merged
ashhart merged 11 commits into
mainfrom
lead/1863-layer-pattern
Nov 4, 2026
Merged

ashhart merged 11 commits into
mainfrom
lead/1863-layer-pattern

Conversation

@ashhart

@ashhart ashhart commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Part 2 of #1863, the last part: one reader for Qwen3.5's attention-layer pattern. Before this, the pattern was read four ways across backends.

What changes

zig/src/core/qwen35_layers.zig (111 lines, std only) reads layer_types, full_attention_interval and their absence into one entry per layer. Metal (the 27B and 2B config readers), HIP, CUDA and XPU now call it, so the same config.json gets the same answer, or the same refusal, everywhere:

config.json Every backend
no layer_types the interval rule: every n-th layer full, with n = 4 when the key is absent. An interval of 0, null or false is refused (BadFullAttentionInterval)
"layer_types": null the same as absent
layer_types given, interval 0 / null / false layer_types as written
layer_types contradicting the interval refused, LayerTypesContradictFullAttentionInterval (names both keys)
  • Malformed lists: BadLayerTypes or UnsupportedLayerTypes on every backend. sliding_attention stays refused for targets, as all three backends already did.
  • A non-whole interval (4.5, "4", -1, true) is refused rather than truncated or ignored. 4.0 is still read as 4. No real config has a non-whole interval.
  • XPU: its 27B runner now checks config.json's shape and layer pattern when the file is present, as its comment said it did. A folder without one, Hadamard-rotated or not, keeps today's fixed every-fourth schedule, so no existing XPU setup changes.
  • The DFlash2 drafter's sliding rule is unchanged. Metal and CUDA already accept the same set (use_sliding_window: true, every layer sliding_attention).

Exactness

  • Real configs: a host test scans the repo's 16 real Qwen3.5 configs (the 2B's config.json, the 27B and 35B-A3B geometry fixtures, the NVFP4 recipe and the rest). It checks every config against verbatim ports of Metal 27B's, Metal 2B's, HIP's and CUDA's old rules, which serve as oracles. The oracles were first committed and checked equal to the old entry points, before any backend changed.
  • Old outcomes: a dump of every (config, backend) outcome before and after is identical for all 64 Metal/HIP/CUDA pairs, down to the error name of each unrelated refusal.
  • One case per table row: a table test runs each row through Metal 27B's, Metal 2B's, HIP's, CUDA's and XPU's entry points. All 56 cells give the row's answer.
  • Tests: zig build test passes apart from the two HTTPS tunnel-count tests, which tests: the benchmark proxy-tunnel tests don't read the host's certificate store #2071 fixed on main. test-qwen35-layers-host, test-qwen27-config-xpu-host, test-qwen-dense-geometry-host (96, one new), the Qwen3.5 Metal, formats and draft-config steps, and -Dhip=true all pass. Lean adds 0 problems against main.

Host-only change: no kernel, no served token path, no device run needed.

Closes #1863.

@ashhart
ashhart force-pushed the lead/1863-layer-pattern branch from 3e7fd88 to e5bf420 Compare November 4, 2026 05:27
ashhart added a commit that referenced this pull request Nov 4, 2026
ashhart added a commit that referenced this pull request Nov 4, 2026
@ashhart
ashhart force-pushed the lead/1863-layer-pattern branch 2 times, most recently from 5d7ea7d to 1dfd9bd Compare November 4, 2026 09:29
ashhart added a commit that referenced this pull request Nov 4, 2026
…inst full_attention_interval

An interval that is not a positive whole number is refused, even beside layer_types.
That refuses one config every backend but Metal's 2B engine accepted: layer_types every fourth
with "full_attention_interval": 4.5. Metal's 27B engine and CUDA ignored the interval beside a list,
HIP truncated it to 4 and XPU read no config.json; Metal's 2B engine already refused it.
It is now BadFullAttentionInterval. No real config has such an interval; 4.0 is still read as 4.
…der; an unset interval beside layer_types is no longer refused
…ader, so a config without layer_types reads the interval
… and the real configs against the shared reader
@ashhart
ashhart force-pushed the lead/1863-layer-pattern branch from 3f00142 to 7331d04 Compare November 4, 2026 11:12
@ashhart
ashhart merged commit df7ba29 into main Nov 4, 2026
1 of 7 checks passed
ashhart added a commit that referenced this pull request Nov 4, 2026
@ashhart
ashhart deleted the lead/1863-layer-pattern branch November 10, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Host fp32→bf16 copies: 59 panic on negative NaNs in Debug; Qwen3.5's layer pattern is read four ways across backends

1 participant