Skip to content

Rounds: attention of all positions at once, lm_head of 4 positions in each block - #110

Merged
hiraditya merged 5 commits into
mainfrom
qwen36-rows
Nov 23, 2026
Merged

hiraditya merged 5 commits into
mainfrom
qwen36-rows

Conversation

@hiraditya

Copy link
Copy Markdown
Contributor

Two changes to the round kernels of run_round35, the check of a round of drafts. Each position keeps the bits of a plain step.

Attention (rounds: the attention of all positions of a round at once)

  • Before, the full attention layers ran 5 kernels for each position of a round.
  • Now 3 kernels run for all n positions:
    • pf_gated_norm_rope_and_store (the kernel of the prompt chunks) stores the k and v rows of all positions.
    • gated_attention_parts_rows and gated_attention_merge_rows do the attention of each position over the rows up to its own position.
  • Each position computes its own number of parts, as gated_attention does, so a round can cross position 2048.
  • tests/round35.vx: a new round of 8 positions at position 2044, against plain steps.

lm_head (rounds: lm_head of 4 positions in each block)

  • matvec_q6_rows does 2 vectors in each block, so a round of 3 or 4 positions reads the bits of each weight twice.
  • matvec_q6_rows4 does 4 vectors in each block. run_round35 uses it for 3 or more positions.
  • To keep 16 values of x for each vector, and not 32, a lane keeps only x scaled for the low bits. It multiplies the high bits of weight t by 16 * 4^-t over that scale. Both factors are powers of 2, so each product and each step of each sum is that of matvec_q6.
  • tests/round.vx: matvec_q6_rows4 against matvec_q6 for 1, 5, 8, 13 and 16 vectors, bit for bit.

Tests

  • tests/run.sh: all pass on the local machine (103 RUN lines).

Speed numbers come after a policy run.

🤖 Generated with Claude Code

https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw

hiraditya and others added 2 commits November 22, 2026 07:42
The full attention layers of `run_round35` ran 5 kernels for each
position: a copy of its row of `proj`, the norms and RoPE, the 2
kernels of `gated_attention`, and a copy of its output. Now 3 kernels
run for all n positions: `pf_gated_norm_rope_and_store` (the kernel of
the prompt chunks, with the arithmetic of the kernel of one token)
stores the k and v rows of all positions, then
`gated_attention_parts_rows` and `gated_attention_merge_rows` do the
attention of each position over the rows up to its own position.

Each block of the new kernels has the arithmetic of the kernel of one
token, with the parts that `gated_attention` takes at its position
(32 or 64 for each head), so each position keeps its bits.

tests/round35.vx: a round of 8 tokens after a prompt of 2,044 tokens,
so its positions take 32 and 64 parts. With the parts of the first
position for all positions, 903 logits differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
`matvec_q6_rows` does 2 vectors in each block, so a round of 3 or 4
positions takes the bits of each weight of lm_head twice, and the
second pass costs about as much as the first. `matvec_q6_rows4` does 4
vectors in each block, and `run_round35` uses it for 3 or more
positions.

To keep 16 values of x for each vector in place of 32, a lane keeps
only x scaled for the low bits, and multiplies the high bits of weight
t by 16 * 4^-t over that scale. Both factors are powers of 2, so each
product and each step of each sum is that of `matvec_q6`, and each
vector keeps its bits.

tests/round.vx: `matvec_q6_rows4` against `matvec_q6` for 1, 5, 8, 13
and 16 vectors, bit for bit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
hiraditya and others added 3 commits November 23, 2026 00:40
The entry gives the problem and the change, and "What did not help" gets the router of 4 positions in each block. The numbers come after a run that follows the benchmarking policy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
docs/optimizations.md: entry 15 of main comes before the entry of this
branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
docs/optimizations.md: entry 16 of main comes before entry 17.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
@hiraditya
hiraditya merged commit 09b01e4 into main Nov 23, 2026
1 check passed
@hiraditya
hiraditya deleted the qwen36-rows branch November 23, 2026 21:10
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.

1 participant