Skip to content

ggml : support -sm tensor for Hadamard-folded qwen35 (Bonsai 2) - #363

Merged
bri-prism merged 1 commit into
prismfrom
sm-tensor-hadamard
Oct 15, 2026
Merged

bri-prism merged 1 commit into
prismfrom
sm-tensor-hadamard

Conversation

@bri-prism

Copy link
Copy Markdown
Collaborator

Tensor split aborts on Bonsai 2 at ggml-backend-meta.cpp:1086 (GGML_ASSERT(split_state.ne[j] % div == 0)), because the Hadamard reshape tiles the activation feature axis and the meta backend has no split state for it. Same bug as #351, with a much smaller fix: 3 files, +50/-4, no new ggml.h hints and no gather path.

  • llama_mul_mat_hadamard reshapes to 4D [n, ne0/n, ne1, ne2*ne3] so the split axis survives the rotation.
  • Split blocks for rotated weights use lcm(type block, rotation block), so a shard never cuts a rotation block.
  • ssm_out gets a value_dim split when GDN V is grouped, and views of the GATED_DELTA_NET output carry the matching split.
  • Elementwise MUL/ADD/SUB/DIV of a feature-sharded activation with a full-width mirrored operand slices the operand per shard (ADD_ID excluded).

The split rules are Benjamin Brown's (@KodeMunkie), from ggml-org#29600; the ADD_ID guard is new here.

Testing

2x H200, CUDA 12.8, against prism e3de715. KLD on wikitext-2, c512, 16 chunks, reference = base build on one GPU.

Model base -sm tensor this PR, one GPU this PR, -sm tensor
Bonsai 2 27B PQ2_0 assert KLD 0, top-1 100% KLD 2.5e-4, top-1 99.3%
Bonsai 2 27B Q2_0 assert KLD 0, top-1 100% KLD 2.5e-4, top-1 99.3%
Qwen3.5-4B Q8_0 runs KLD 0 identical to base -sm tensor
Qwen3-4B Q8_0 runs KLD 0 identical to base -sm tensor

Greedy output under -sm tensor is byte-identical to base on both Qwen models, so the change is neutral off the Hadamard path. 27B PQ2_0 speed with -ts 1/1: tg128 about 112 vs 120 tok/s on one GPU, pp512 +24%. It's a capacity feature, not a speedup.

Not covered: more than 2 devices, and a real MoE split (the ADD_ID guard is untested there).

Tensor split aborted on qwen35 models with folded Hadamard rotations at
ggml-backend-meta.cpp:1086 (split_state.ne[j] % div == 0): the rotation
reshape tiles the activation feature axis, and the meta backend had no
split state for it.

- llama_mul_mat_hadamard reshapes to 4D [n, ne0/n, ne1, ne2*ne3] so the
  split axis survives the rotation, and asserts ne0 % n == 0.
- Split blocks for Hadamard-rotated weights use lcm(type block, rotation
  block) so shards never cut a rotation block.
- ssm_out uses a value_dim split when GDN V is grouped, and views of the
  GATED_DELTA_NET output carry the matching axis-1 split.
- Elementwise MUL/ADD/SUB/DIV of a feature-sharded activation with a
  full-width mirrored operand slices the operand per shard (ADD_ID is
  excluded).

Split rules by Benjamin Brown (@KodeMunkie), posted on
ggml-org#29600; ADD_ID guard added here.

Tested on 2x H200: Bonsai 2 27B PQ2_0 and Q2_0 now run under -sm tensor
with mean KLD 2.5e-4 vs single GPU (top-1 99.3%). Single-GPU CUDA output
and Qwen3-4B / Qwen3.5-4B results (single and tensor) are bit-identical
to the base commit.
@github-actions github-actions Bot added the ggml label Oct 14, 2026
@bri-prism
bri-prism merged commit 71c1473 into prism Oct 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant