Skip to content

Do not merge: broken copies of the decode attention parts - #88

Draft
hiraditya wants to merge 92 commits into
vx-attention-parts-2from
vx-attention-parts-sabotage
Draft

hiraditya wants to merge 92 commits into
vx-attention-parts-2from
vx-attention-parts-sabotage

Conversation

@hiraditya

@hiraditya hiraditya commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

5 broken copies of vec_attention_parts, each with one bug, run through the checks of tests/decode_attention.vx. Not to merge: it shows that the checks of #87 catch each bug.

Copy Bug Positions with values off (of 0, 40, 1000, 2100, 8000)
parts_no_mask The rows after pos keep their score. 40, 1000, 2100, 8000
parts_no_clamp The rows after pos are read. all 5
parts_no_rescale The sums of V are not scaled when the largest score grows. 2100, 8000
parts_own_weight Each row of V gets the weight of the lane's own row. all 5
parts_swapped_stats The largest score and the sum of the weights change places. all 5

The copies are now of the kernel of Vx v0.0.6 in #87, which calls the functions of src/simd.vx. The test is not in the package qwen, so it has private copies of those functions and of fused. Before, the RUN line failed on purpose, so that CI printed the counts. Now it passes when each copy has values off at one or more positions, and fails when the checks miss a bug.

With the release vxc 0.0.6 (afb0f45e), on an M4, tests/run.sh passes, all 124 lines. The counts of parts_no_clamp to parts_swapped_stats are those of the CI run of 2026-11-20.

A merge with -s ours keeps the old commit of this branch in the history, so the branch moved on without a force push.

🤖 Generated with Claude Code

https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw

hiraditya and others added 4 commits November 19, 2026 21:25
The Python packages were in three places with no versions. requirements.txt (the scripts),
requirements-test.txt (the tests, which CI installs) and requirements-mlx.txt
(check_against_mlx.py) pin them. VX_VERSION names the Vx release that CI tests, and CI checks
that vxc --version gives it. The README names z3, which the Vx toolchain needs on macOS.

Part of #79.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Six pieces follow the design of llama.cpp (MIT License): the decode, round and prompt attention,
the expert product of the prompt, the block shape of the Q4_0 products, and the Q4_0 rounding of
qwen_weights.py. The file lists each with its upstream kernel, and has the MIT text. The README
links it, and says that model weights and tokenizers keep the license of their model.

Fixes #80.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Each copy breaks one part of vec_attention_parts, and runs the checks of
tests/decode_attention.vx. Each must show values off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 8 kernels of round_attention_parts, one for each number of queries
n, were mlir! blocks. scripts/round_attention.py now prints them as Vx
code, in the form of vec_attention_parts: the same small mlir!
functions, the same order of operations for each query, and each row
of K and V read once for all n queries. Each query keeps its values in
variables of its own, so that they stay in registers. Vx v0.0.5 keeps
a tile in threadgroup memory on Metal, so one kernel with a tile for n
queries would be slower. The script moved out of scripts/mlir_kernels/.

The score of a row is now 4 calls of half_at and a dot product in Vx,
in both kernels, not dot4. dot4 had its own load, so the kernel for n
queries loaded each row of K n times. Vx merges the 4 loads of half_at
into one, as it does for V. The sum keeps its order:
((k0 q0 + k1 q1) + k2 q2) + k3 q3. dot4 is gone.

The Metal code of the kernel for 2 queries has one half4 load for each
row of K and of V, as the mlir! block had.

With this commit and the 2 before it, 11 of the 13 mlir! blocks are gone. 2 are
left: the prefill attention and the prefill expert product.

Part of #76.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hiraditya and others added 25 commits November 20, 2026 00:15
Declare and pin the dependencies, and add THIRD_PARTY_NOTICES
…d tiny model

This is the Python side of the move to Qwen3.6-35B-A3B. Its architecture
is Qwen3.5 MoE, arch 1 in the weight file. Three of every four layers
have a Gated DeltaNet, a linear attention. The fourth layer has full
attention with a gate on its output. Each layer also has a shared expert.

- qwen_weights.py: version 2 of the weight file, with room for 32 config
  integers. Files of the older models keep version 1 and the same bytes.
- convert.py: converts the Hugging Face folder. It stores each norm that
  multiplies by 1 + w as 1 + w in f32, so a program uses a plain RMSNorm.
- reference.py: computes the new layers in float32. --dump-layer writes
  each stage of one DeltaNet layer, for the checks of the Vx kernels.
- make_tiny_model.py --qwen35: a tiny model with the head sizes of the
  real model, so that it runs the same kernels.

On the tiny model, reference.py matches MLX within 5.3e-4 of a logit,
with the same 16 greedy tokens.

Refs: #89
src/weights.vx reads version 1 and version 2 of the weight file.
load_qwen35_weights loads a Qwen3.5 MoE model (arch 1) into
Qwen35Weights, with one Qwen35Layer for each layer. Its norms stay f32,
as 1 + w. weight_file_arch reads only the header, so that a program can
choose the loader. load_weights and its structs do not change for the
older models.

tests/print_qwen35_weights.vx prints every tensor of the tiny Qwen3.5
model after it reaches GPU memory: in bf16, and in Q4_0 with a 6-bit
lm_head. Its lines equal those of reference.py --tensors.

Refs: #89
src/deltanet.vx runs the linear attention of a Qwen3.5/Qwen3.6 layer
for one token, between the products linear_in and linear_out, with the
math of transformers' modeling_qwen3_5_moe.py: the causal depthwise
convolution of width 4 and SiLU, the L2 norms of q and k, beta and the
decay, the update of the state S and q . S, and the gated RMS norm.

Four kernels. In the update, a SIMD group does 32 values of v of one
head, and lane l owns 4 values of k, so that the lanes read a row of S
in one load. The state is [v_heads, v, k], k last.

tests/deltanet.vx checks 6 tokens against the same math on the CPU, at
the shapes of Qwen3.6-35B-A3B. Breaking the head map, the decay, the
order of the taps or the scale of q makes it fail.

On the M4, 30 layers take about 1.7 ms a token; the update of the state
is 1.5 ms of it (2 MB read and written for each layer, about 80 GB/s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
src/gated_attention.vx runs the full attention of a Qwen3.5/Qwen3.6
layer for one token, between the products qkv and attn_out:

- gated_norm_rope_and_store: the RMS norms of the q and k heads (256
  values, weights stored as 1 + w), RoPE on the first `rot` values of
  each head, and the store of k and v into the f16 caches.
- gated_attention: the attention with the scale 1/16, in the design of
  vec_attention (llama.cpp's kernel_flash_attn_ext_vec) for 256 values a
  head, with 8 values for each lane; then the merge, which multiplies by
  sigmoid(gate).

src/simd.vx holds the small mlir! functions of both new files (a sum, a
largest value and a value across the lanes, a load of 4 halves, the
logarithm). They are those of #87, under other names.

tests/gated_attention.vx checks positions 0, 37, 700, 2047 and 2100
against the same math on the CPU, at the shapes of Qwen3.6-35B-A3B. A
wrong RoPE sign, head map, gate offset or norm weight makes it fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
… as weight file v2 stores it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
…planned for weight file v2 (#89, #90)

It does not compile yet: Qwen35Weights, Qwen35Layer and the new Config
fields come with the v2 loader of #90.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Qwen3.6-35B-A3B: weight file version 2, converter, NumPy reference and tiny model
…nd to end (#89)

main.vx reads the arch in the header of the weight file. For arch 1 it
loads the model with load_qwen35_weights and runs run_qwen35: the prompt
one token at a time (no chunked prefill and no drafts yet), then the
generated tokens, with the same output as for arch 0.

src/qwen35.vx: the experts of a layer can now also be bf16, and the
token loop asserts that the full attention layers are where the config
puts them.

tests/generate_qwen35.vx compares the tiny Qwen3.5 model with
reference.py: the bf16 file, the Q4_0 file with a 6-bit lm_head, and
the Q4_0 file after a prompt of 2,100 tokens. The tokens are the same,
and the largest logit difference is 5.7e-5, 5.0e-5 and 4.3e-5.
tests/run.sh: all 85 checks pass with vxc 0.0.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
src/prefill35.vx runs the prompt of an arch 1 model in chunks of up to
2048 tokens, as src/prefill.vx does for arch 0. The products and the
sort of the experts are those of src/prefill.vx. New here:

- The DeltaNet of a chunk: the convolution and the norms of all the
  tokens at once, then pf_dn_recur, which runs the tokens in order and
  keeps S in registers for the whole chunk, 8 values of v for each SIMD
  group. scripts/deltanet_chunk.py prints that kernel.
- The gated attention of a chunk, 64 tokens at a time, with 8 SIMD
  groups for each head and token.
- The shared expert, as a dense SwiGLU over the chunk, times its gate.

main.vx uses it in place of one token at a time. The clock of the
generated tokens now starts after the tokens of step 0, which compile
the kernels of a step: a token cannot run twice to warm up, because the
DeltaNet would update its state twice.

tests/generate_qwen35.vx: the bf16 file matches reference.py within
5.5e-5 after a short prompt and 4.8e-5 after 2,100 tokens (2 chunks).
The products of a chunk round each Q4_0 weight to f16, as for arch 0,
so the Q4_0 files get 0.003, as in tests/prefill.vx (1.85e-3 and
2.83e-3, the same tokens). tests/run.sh: all 89 checks pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Qwen3.6-35B-A3B: load weight file version 2 into GPU memory
Qwen3.6: DeltaNet and gated attention kernels, the token loop, and the prompt in chunks
pf_gated_flash_attention is pf_flash_attention for heads of 256 values,
with the output gate sigmoid(gate) in its last step. A threadgroup does
8 tokens of one query head, in steps of 64 positions, with simdgroup
matrices for Q K^T and P V. scripts/mlir_kernels/gated_flash_attention.py
writes it.

It replaces the parts-and-merge kernels of the chunk, which read K and V
again for each token. The KV caches of arch 1 now have a multiple of 64
rows, as those of arch 0.

The long bf16 test (2,100 tokens, 2 chunks) matches reference.py within
4.6e-5 (4.8e-5 before). All 89 checks pass. On the real
Qwen3.6-35B-A3B Q4_0 file, the 24 greedy tokens of "def fibonacci(n):"
are those of reference.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
The pre-tokenizer regex of Qwen3.5 and Qwen3.6 adds the Unicode marks
(\p{M}) to the class of letters. convert_tokenizer.py now accepts this
regex and writes the marks in the table of letters. tokenizer.vx then
splits the text as the new regex does, with no change to its code. Only
its comments change.

Files of the older tokenizers are byte-identical to those of main.

Tests:
- test_tokenizer.py also compares the Qwen3.6 tokenizer with the
  tokenizers package, when the model folder is present.
- The class test checks each regex of the model folders against the
  regex engine of tokenizers, for every code point.
- A new test, which CI runs, checks the table of letters of each regex
  and that the script refuses another regex.

Part of #89.
convert_tokenizer.py takes the classes of the regex and the NFC tables
from the unicodedata module of Python. They give the ids of the
tokenizers package only when Python has its Unicode version, 16.0. The
venv here has Python 3.13 with Unicode 15.1. Its tables put new
characters such as U+140B5 in another class, so test_tokenizer.py
failed 4 of its tests.

The script now refuses another Unicode version. Python 3.14 has 16.0.
--any-unicode turns the check off for the tiny tokenizers of the RUN
lines, because CI runs them with Python 3.15.

test_tokenizer.py makes the tokenizer files and the Unicode tables with
a Python of Unicode 16.0: itself, or python3.14 on PATH. In the venv,
all 7 of its tests now pass. A new test checks the refusal.

Part of #89.
The chat template of Qwen3.5 and Qwen3.6 opens the reply with a <think>
block, and the models think by default. With --chat on an arch 1 file,
the prompt now ends with "<think>\n\n</think>\n\n", as the template does
with enable_thinking=false, so the reply comes at once. --think ends it
with "<think>\n", and the model thinks first. <think> and </think> are
not special tokens, so they do not stop the run.

With --chat, run_qwen35 now prints only the reply, as `main` does for
arch 0.

On the real Qwen3.6-35B-A3B Q4_0 file, "Write a short Python function
that checks whether a number is prime." gives a correct is_prime in a
code block and stops at <|im_end|>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
A round of arch 1 (src/round35.vx) runs the last token and up to 15
draft tokens through the model with one read of the weights, as
`run_round` does for arch 0. Each position gets the result of the
kernels of one token bit for bit, so the tokens are those of plain
greedy decoding.

A DeltaNet layer changes its state with each token, and a round does not
know which positions it keeps until the CPU reads the tokens. So the
round reads S and the convolution inputs and writes neither. It keeps
q, k, v, beta, decay and the outputs of linear_in of each position.
Then commit_round35 runs the update of S again for the kept positions
and writes S and the last 3 convolution inputs. That costs one more
read of S per layer for each round.

The full attention layers run the kernels of one token for each
position, in order. The products use nn_matvec_q4_rows and a residual
add, which give the bits of nn_matvec_q4_add. The experts use row
versions of moe_swiglu_q4_blocks and moe_down_q4_add_blocks.

generate_with_drafts35 is generate_with_drafts with a commit after each
round. Its first step is a plain step, which compiles the kernels of a
token, so the clock starts after it.

tests/round35.vx checks rounds of 6, 4, 2 and 5 tokens that keep 3, 1,
2 and 5 of them: every logit, and the DeltaNet states after each
commit, equal those of plain decoding bit for bit. tests/
generate_qwen35.vx checks that --draft 7 gives the lines of plain
decoding on a prompt that makes a round. All 98 checks pass.

On the real Qwen3.6-35B-A3B Q4_0 file, 96 lines of "def fibonacci(n):"
with --draft 7 equal those without it, and a chat prompt that asks for
type hints on a function gives the same text with and without drafts,
with 79 of 81 draft tokens accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
vxc compiles the code that runs on the CPU at -O0 by default, and no
command here passed -O. At -O0, a zeroed CPU tensor of 98 MB takes about
52 ms; at -O2 it takes about 1 ms. The tensors of a chunk of the prompt
are about 220 MB at 512 tokens, so the prompt of the real Qwen3.6 file
is about 8% faster with -O2 (informal reading, not under the policy).
The time of a generated token does not change, and neither do the
tokens.

The README, the header of src/main.vx, scripts/chat.py,
examples/run.sh and decode/profile_decode.vx now run vxc -O2. The
README says to use -O2 for every run that is timed. The tests keep the
default, so they compile faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
--prompt-runs K (Qwen3.5 and Qwen3.6) runs the prompt K times, each on a
fresh state made before its clock starts, and prints `time prompt_ms=` for
each run. The first run includes the first launch of each kernel. The runs
use the same chunk tensors (new prefill_qwen35_with), made before the first
clock starts, as llama.cpp makes its buffers when it loads the model. The
tokens and the decode come from the last run.

--ignore-eos does not stop the text at a special token or EOS, as
llama.cpp's --ignore-eos, so a run gives --steps tokens. It works for both
architectures, with and without --draft.

tests/generate_qwen35.vx: --prompt-runs 3 gives 3 prompt times and the step
lines of the file without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
An expert of Qwen3.6-35B-A3B gets about 16 of the 4,096 choices of a
512-token chunk, and its tokens are padded to blocks of 32, so about half
of the positions of the expert products were padding. The tokens of a
block come before its padding, so when token 16 of a block is padding, the
two SIMD groups of tokens 16 to 31 now skip their multiplies (an scf.if
around them in scripts/mlir_kernels/expert_product.py).

The down product reads the positions themselves (e_ident), so the new
pf_live_positions gives -1 to the positions of padding after each sort.

Informal, -O2, the real model, one chunk of 512 tokens, interleaved: the
experts take 622 ms in place of 777 (gate_up 352 in place of 452, down 196
in place of 250).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
A SIMD group of the Q4_0 product of a chunk makes 2 rows of 8 tokens. It
now skips the multiplies of each row whose first token is padding, in place
of only the 16 tokens of a half block, so the multiplies of an expert go
by 8 tokens and not 32.

Informal, -O2, the real model, one chunk of 512 tokens, interleaved: the
experts take 595 ms in place of 623 (gate_up 331 in place of 353, down 190
in place of 196).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
…89)

The router of a chunk (257 rows of bf16) took 47 ms of a 512-token prompt
of Qwen3.6-35B-A3B in pf_mm_bf16. expert_product.py --bf16 now prints
pf_mm_bf16_mlir: the product of pf_mm_q4_mlir, with bf16 weights that go
to f16 in shared memory. Rows need not be a multiple of 64; `router` gets
the columns of whole blocks of 64. The router weights of the model are
below 0.4, and the f16 of a weight below 6.1e-5 is off by 3e-8 at most.
pf35_experts uses it when the experts are Q4_0, whose products round to
f16 already. A bf16 file keeps the f32 router (the long bf16 test of
tests/generate_qwen35.vx found 0.004 with the f16 router).

pf_silu_mul_live skips the positions of padding (e_ident -1): the SwiGLU
of the experts ran on all 12,032 positions of the chunk for 4,096 choices.

Informal, -O2, the real model, interleaved: router 21 ms in place of 47,
SiLU 32 in place of 42; a prompt of 512 tokens 1,180 ms in place of 1,212.
The tokens of the reference prompt and of a 48-step code-edit prompt stay
the same. The logits of the code-edit prompt move by 0.02 to 0.2 (0.46 at
most), as the f16 of the router moves near ties.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
expert_product.py --t64 prints pf_mm_q4_mlir64: pf_mm_q4_mlir with blocks
of 64 tokens x 64 rows, so each weight that a block decodes serves 64
tokens in place of 32. Each SIMD group makes 32 tokens x 32 rows, with 16
sums. It does not skip padding, so it is for the dense products: the new
pf35_mm uses it for the Q4_0 matrices of whole blocks of 64 rows (qkv,
attn_out, linear_in, linear_out and the shared expert). new_prefill35 makes
the tensors of the chunk for whole blocks of 64 tokens.

The sums go in the same order, so the logits stay the same: a 48-step
code-edit prompt gives the same tokens and logits as before.

Informal, -O2, the real model, interleaved: linear_in 251 ms in place of
270; a prompt of 512 tokens about 1,148 ms in place of 1,180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
tokenizer: read the tokenizer of Qwen3.5 and Qwen3.6
The pull requests of Qwen3.6 (#95 and #97) stopped at the limit of 30
minutes with no failed test: #95 passed 90 RUN lines and #97 passed
95 before the cancel. A RUN line that compiles the app takes 90 to 115 s
on the macOS runner, so the whole suite needs more than 30 minutes now.

Issue: #89
hiraditya and others added 29 commits November 23, 2026 07:51
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Drafts from the MTP layer of Qwen3.6 (--mtp K)
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Rounds: attention of all positions at once, lm_head of 4 positions in each block
After a round that keeps j drafts, the MTP layer ran j rows, one at a
time, with the true h of the model, and the next round then ran the
row of its first draft. These j + 1 rows have all their inputs after
the round: row i takes r.xn[i] and r.next[i], the token that the round
gives after position start + i. `mtp35_rows` now runs them in one pass
with the kernels of the round (`nn_matvec_q4_rows`, the attention of
all positions, and the experts of each row), and the last row gives
the first draft of the next round.

The kernels of the round have the bits of the kernels of one token, so
the drafts do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
With --mtp K,L, a round drafts L tokens while the running mean of the
kept drafts is at least MTP_LONGER_SHARE (0.95), K tokens while it is at
least MTP_LONG_SHARE (0.85), and 1 token otherwise. A third number,
--mtp K,L,P, sets the first share to P percent. --mtp K is as before.

tests/generate_qwen35.vx: --mtp 3,5,0 drafts 5 tokens in each round,
and gives the steps of plain decoding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
MTP drafts: the rows after a round in one pass, and --mtp K,L
Rounds: lm_head of the rows that can be the greedy token
… --mtp)

With --mtp and --draft D, a round first looks for the longest match in
the context. When the match has at least M tokens (default 12), the
round takes up to D drafts from the tokens after the match. Otherwise
the round takes MTP drafts as before. Only MTP rounds change the
kept-share average. The MTP rows still run after every round, so the
next MTP draft is ready.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
A shorter match often gives drafts that the round does not keep, and
such a round costs more than the MTP round that it replaces. On the
tuning prompts, matches of 12 made complete1 and write2 slower, and
matches of 16 found only the repeats of the edit prompts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
…unctions of Vx

In Vx after v0.0.5, a function with no level is private to its file. pkg
makes it visible to the files of its package (qwen, the files in src/),
and pub to every file. So this gives 64 functions pub and 53 pkg, each
the narrowest level that its callers need. src/main.vx, tests/ and
decode/ are not in the package qwen, so a function that they call is pub.
The C functions strlen and write, which two files declare, are pkg.

Vx now also needs unsafe around an mlir! block, so the 21 blocks of
attention, prefill, prefill35, round and simd are inside unsafe { }.

core::ptr now has a pub write_bytes, which clashed with the private
write_bytes of tokenizer.vx in tests/tokenize.vx. The tokenizer's function
is now pub print_bytes. tests/tokenize.vx compares C strings with
string_length of std::string, not with the pkg strlen of the package.

With the vxc of Vx PR #3975 (main d3ed6cf0b and root.args), the 114 RUN
lines of tests/ and the 43 Python tests of scripts/ pass. VX_VERSION
stays v0.0.5 until a Vx release has these rules.
The README had 538 lines. It now has 100: the models, the installation, how to run
Qwen3.6-35B-A3B, the options, the tests, and a table of the documentation.

The sections of the old README move to four files of docs/, with their text unchanged:
- docs/usage.md: the installation, how to prepare and run a model, sessions and the prompt
  cache, the scripts, the Vx code and the tests, and the licenses of the models.
- docs/weights.md: the fp8, Q4_0 and 6-bit formats, and the MoE model.
- docs/internals.md: the prompt in chunks, long contexts, and the tokenizer.
- docs/checks.md: the checks of the Vx program and of the reference.

The moved links now start from docs/, and "this README" is now "the README of that time".
The license of the code stays in LICENSE and THIRD_PARTY_NOTICES, not in the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
A run that follows the benchmarking policy of the Vx repository, on an M4 with 32 GB. It measures
qwen-vx at 730f1b7 without drafts, with --draft 11, with --mtp 3,5 and with --mtp 3,5 --draft 11,
against llama-completion and llama-speculative-simple with ngram-mod and draft-mtp (3 tokens),
llama.cpp b1b770d. Tables A and P and llama-bench too.

docs/benchmarks/2026-11-25-qwen36-m4-mtp/ has the report, the scripts, the inputs, env.txt,
log.txt, runs.csv, summary.md and the logs of each run. run.sh and parse.py come from the
2026-11-20 run, with the programs of the app with --mtp, an idle check that checks again after
the cooling, and RERUN for the runs that another job overlapped.

The README gets a short table of the speeds, and entries 16 to 19 of docs/optimizations.md get
their results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
README: a short page, with the details in docs/
Benchmark of 2026-11-25: qwen-vx with MTP drafts against llama.cpp
qwen app: drafts from the context in the rounds of --mtp
…ights

In Vx after v0.0.5, main can take the rights of the program:
fn main(root : Root, args : Vec<String>). File::open of std::fs needs a
&Files, and Stdout::write_all needs the Stdout. So the app and the tests
now:

- take Root and the words of the command line in main, in place of argc
  and argv. The options are Strings.
- open and map the weight, tokenizer, prompt and cache files with
  File::open and File::map. A mapping ends when its Reader, Tokenizer or
  cache load ends.
- print the tokens with the Stdout, and write the replies and the cache
  files of a session through a File.
- declare no extern function. open, lseek, mmap, read, write, fopen,
  fwrite, strlen and strcmp are gone. strlen and strcmp are now
  string_length and string_compare of std::string.

vxc -a audit of src/main.vx lists 7 extern functions fewer and 31 unsafe
blocks fewer in main, session, tokenizer and weights.

Two changes in behavior:
- A load request for a cache file that does not open gets an error
  reply, as a save request does. Before, the session stopped.
- The file of replies opens with OpenMode::Write, which creates it when
  it is not there.

Tested with the vxc of Vx main c1bf025ea:
- tests/run.sh: all 120 RUN lines and the Python tests of scripts/ pass.
- Qwen3.6-35B-A3B q4-q6-mtp, held-out prompts complete1, edit1 and
  write1, 512 tokens: the same text as dec965c on vxc 0.0.5, with and
  without --mtp 3,5 --draft 11. The same speed: 22.08 to 22.48 ms a token
  against 22.11 to 22.56, and with drafts 11.99 to 16.76 against 11.97 to
  16.81.

VX_VERSION stays v0.0.5 until a Vx release has Root.
Vx v0.0.6 makes a function with no pub private to its file, and adds
pkg fn. This branch uses both, so CI needs v0.0.6 to compile it.
VX_VERSION and the install notes in README.md and docs/usage.md now
name v0.0.6.
The branch now has main, #114 and #117. The two conflicts were the
mlir! blocks of vec_attention_merge and round_attention_merge, which
#114 put inside unsafe { } and this branch replaces with Vx code. The
Vx code stays. tests/attention_merge.vx is not in the package qwen, so
vec_attention_merge and round_attention_merge are now pub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
The #86 branch now has main, #114 and #117. The conflicts were the
mlir! blocks of the decode and round attention parts, which #114 put
inside unsafe { } and this branch replaces with Vx code. The Vx code
stays.

main has src/simd.vx (#89), with simd_sum, simd_max, simd_value and
half4_at: the same functions as lane_sum, lane_max, lane_value and
half_at of this branch. In Vx v0.0.6 a function with no level is
private to its file, so round.vx could no longer call the copies in
attention.vx. The copies are gone, and the kernels and
scripts/round_attention.py call the functions of src/simd.vx. The
script prints the functions of src/round.vx as they are.

fused stays an mlir! block, now inside unsafe { } and pkg: mul_add of
Vx v0.0.6 has no ensures writes_only(), so a kernel cannot call it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
5 copies of vec_attention_parts of src/attention.vx, each with one bug,
run through the checks of tests/decode_attention.vx:

- parts_no_mask: the rows after pos keep their score.
- parts_no_clamp: the rows after pos are read.
- parts_no_rescale: the sums of V are not scaled when the largest score
  grows.
- parts_own_weight: each row of V gets the weight of the lane's own row.
- parts_swapped_stats: the largest score and the sum of the weights
  change places.

The copies are of the kernel of Vx v0.0.6, which calls the functions of
src/simd.vx. The test is not in the package qwen, so it has private
copies of those functions and of fused. The RUN line passes when each
kernel has values off at one or more of the positions 0, 40, 1000, 2100
and 8000, and fails when the checks miss a bug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
…ithout a force push

The old commit had copies of the decode kernel of Vx v0.0.5, with dot4
and the lane functions of src/attention.vx. The commit before this one
has new copies of the kernel of Vx v0.0.6. This merge keeps that tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
hiraditya added a commit that referenced this pull request Dec 3, 2026
The runs of #117, #86, #87 and #88 stopped at the limit of 60 minutes, in
tests/session.vx, RUN line 4. That line compiles the app 5 times. The run
of #114 took 51 minutes, and the run of #117 at the same time took about
40% more on each test. tests/session.vx passes on #117 with Vx v0.0.6 on
a local Mac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014U9gTxfQzAEpmg4WJhYQqw
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