Repository navigation
Rounds: attention of all positions at once, lm_head of 4 positions in each block - #110
Merged
Merged
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)pf_gated_norm_rope_and_store(the kernel of the prompt chunks) stores the k and v rows of all positions.gated_attention_parts_rowsandgated_attention_merge_rowsdo the attention of each position over the rows up to its own position.gated_attentiondoes, 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_rowsdoes 2 vectors in each block, so a round of 3 or 4 positions reads the bits of each weight twice.matvec_q6_rows4does 4 vectors in each block.run_round35uses it for 3 or more positions.matvec_q6.tests/round.vx:matvec_q6_rows4againstmatvec_q6for 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