Skip to content

fix(hip): time shared rows with a token a row, keep lone windows on one token - #2652

Merged
ashhart merged 2 commits into
ashhart:mainfrom
AbrahamCete:fix/hip-shared-row-tokens
Nov 9, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
AbrahamCete:fix/hip-shared-row-tokens

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

The HIP timing piece of #2605, which can go ahead on its own as agreed there.

  • Before: HIP timed every forward in its load-time cost table with all rows on token 1. The 35B's MoE routes those rows to one expert set. Shared rows come from different streams and route apart, and timed that way they cost 3-22% more (tables below).
  • After: a forward over two or more windows times a distinct token a row (fillTokens and fillRound in hip_costs.zig; the id stride is 7919, or 7927 where 7919 divides the vocabulary's span). A lone window keeps its one repeated token, so the one-stream table is unchanged; timing lone windows on distinct tokens made greedy chat at one stream 8.4% slower (this comment).
  • core/lanes is unchanged. The plain price, bounded plain rounds and row split are the maintainers' lane-core branch in HIP: sampled chat at 4 streams on Qwen3.6-35B-A3B is 6% faster with --mtp-drafts 0, because the depth rule underprices sampled drafted rounds #2605; I'll run that on gfx1151 when it's posted.
  • On its own it does not change throughput (receipt below): the rule drafts fewer rows at four sampled streams, and speed stays within the run spread.

The cost table only steers draft depth, so tokens are unchanged.

Checks on this head

  • Head commit: 89ea115. The served A/Bs below ran on 235a0f3f5 (the first two) and c80a56fc7 (the sampled four-stream one); 235a0f3f5 differs from c80a56fc7 only in the new function's doc comment. On a served vocabulary 6cb4f45 keeps the 7919 stride, so the ids are unchanged; this head's shared table matches c80a56fc7's within 0.5%, with the 33-64 row bucket 2.8% lower. The checks below ran on 89ea115.
  • Lean checker, python3 tools/zig/lean_check.py: 398 problems on the base and on this head; lean_new.py: 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test test-golden --summary all: 612/612 steps, 7991 of 8057 passed, 66 skipped.
    • zig build hip-host-test: 68/68. zig build test-qwen35-hip-host: 86 of 88 passed, 2 skipped. zig build check-native-hip-host: 6/6 steps.
    • The new host tests in hip_costs_test.zig, each failing before its change and passing after it:
      • "a lone window times one repeated token; shared rows carry a token a row inside the vocabulary";
      • "shared rows stay distinct over any vocabulary, spans 7919 or 7927 divide included" (with 7919 alone, 15,839 ids gave two);
      • "a timed round's tokens and greedy draws follow its windows: one repeated token alone, a token a row shared".
    • tf-qwen35-test check <35B> --only invariants: 51 passed, 0 failed, 1 skipped.
  • CI: running on 89ea115; I will fill this line when it ends. Before it, green on 2628baf, 8 of 8 (fmt, zig, zig-windows, zig-macos-dev-tools, pytest, release-paths, benchmark-clients on Ubuntu and Windows); the two nightly host jobs skip.
  • Not run, and why: Metal and CUDA, since the change is inside the qwen3_5 HIP family. Qwen3.8-27B, since my local checkpoint has no MTP weights and so drafts nothing the table could steer.

Receipt

  • Main against branch, the cost table. Each run is one fresh server, Qwen3.6-35B-A3B MTP --parallel 4 --context 4096 --prompt-cache-gib 0. Both arms carried a scratch-only patch that prints the table to stderr at load and changes nothing else. Milliseconds a forward:

    shared rows (bucket) main B1, B2 this PR C1, C2 PR / main
    1 11.62, 11.66 11.51, 11.55 0.99
    2 14.99, 15.00 15.40, 15.39 1.03
    3-4 19.78, 19.99 22.19, 22.25 1.12
    5-8 26.64, 27.57 32.61, 32.66 1.20
    9-16 40.18, 42.92 47.44, 48.41 1.15
    17-32 68.96, 72.11 78.26, 79.46 1.12
    33-64 121.88, 128.22 134.99, 135.92 1.08
    • The 16 lone-window entries: PR / main 0.97 to 1.01. The head step: 0.72 ms on both.
    • Load time, the loaded in startup line: 11.1 to 11.5 s on both arms.
  • The decisions, from the server's done lines and TF_LANE_TRACE, over all requests at four streams:

    • Sampled (temperature 1.0): drafted rows a stream-round 1.64 on main, 1.36 with this PR; tokens a stream-round 1.97 and 1.81; accepted/drafted 0.59 on both.
    • Greedy: drafted rows a stream-round 0.90 and 0.96; tokens a stream-round 1.63 and 1.66; accepted/drafted 0.69 and 0.68.
    • One stream: drafted rows a stream-round 1.62 and 1.61 sampled, 1.96 and 2.02 greedy.
  • Main against branch, throughput. tools/bench_concurrent.py --tokens 256 --reps 3, code and chat, one window for each temperature and level. Servers ran in the order B1 C1 C2 B2, and on each server the windows ran sampled then greedy, one stream then four. Aggregate tok/s:

    prompt T streams main B1, B2 this PR C1, C2 PR vs main
    chat 0 1 101.4, 99.8 100.2, 100.0 -0.5%
    chat 0 4 199.8, 200.8 200.0, 201.7 +0.3%
    chat 1.0 1 94.6, 96.3 95.3, 94.9 -0.4%
    chat 1.0 4 152.8, 162.0 151.3, 156.9 -2.1%
    code 0 1 123.4, 124.5 123.5, 124.6 +0.1%
    code 0 4 242.2, 242.9 242.7, 241.8 -0.1%
    code 1.0 1 105.8, 106.2 107.3, 106.9 +1.0%
    code 1.0 4 169.9, 164.8 169.1, 164.0 -0.5%
    • The sampled four-stream cell alone, on c80a56fc7: --tokens 256 --reps 5 --temperatures 1.0 --levels 4, 8 servers in the order B1 C1 C2 B2 C3 B3 B4 C4. Aggregate tok/s, one value a server:

      prompt main this PR PR vs main
      chat 152.7, 155.6, 155.0, 155.2 (mean 154.6, sd 1.3) 151.6, 155.7, 151.9, 153.7 (mean 153.2, sd 1.9) -0.9%
      code 170.2, 168.7, 168.8, 168.8 (mean 169.1, sd 0.7) 169.5, 169.5, 169.2, 163.7 (mean 168.0, sd 2.9) -0.7%
  • Boxes it reaches: HIP, the qwen3_5 family's load-time cost table at two or more served streams. A dense checkpoint reads a row's token only for its embedding row, so its table is not expected to move; not measured (see "Not run").

  • New switch? None.

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main 52427c0 against this branch (above); Zig 0.17.0; hipcc with HIP 7.1.52801 and Ubuntu clang 21.1.8; Ryzen AI Max+ 395 (gfx1151), Linux 7.0; TensorFold/Qwen3.6-35B-A3B-MLX-4bit-MTP at f84b054c5677 (the five safetensors' sha256 equal the Hub's).

  • Paths and platforms the change reaches, which I ran and which I could not: HIP shared rounds and the one-stream path on gfx1151, sampled and greedy. Not run: other AMD chips.

  • Exactness, from token_sha against main: equal in every cell, and in every request of every arm. Greedy: code 9f2923ac14d0, chat a8c28b8297b4. Sampled, one hash for each stream's seed: code 5d7effdcf06f, 306e0fe05bc2, bc55cc799f87, bd3964ef7930; chat 460edda16244, 0eba9c9d3070, 15d18697d5f1, d813ade7fc53. Drafted against serial, solo against together and resumed against fresh: the invariants above (drafted == serial and solo == together, greedy and seeded at temperature 1, 4 streams; resumed == fresh).

  • Main against this branch, same machine and checkpoint: above.

  • Decode speed before and after, from tools/bench_openai.py --tokens 256 --reps 5 --temperatures 1.0,0, servers in the order B1 C1 C2 B2, median decode tok/s:

    prompt T main B1, B2 this PR C1, C2 PR vs main tokens equal
    fibonacci-raw 0.0 125.3, 125.0 124.6, 125.0 -0.3% yes
    fibonacci-raw 1.0 107.6, 107.9 106.4, 106.0 -1.5% yes
    gpu-chat-no-think 0.0 100.2, 100.0 100.4, 100.4 +0.3% yes
    gpu-chat-no-think 1.0 99.4, 100.2 100.1, 101.0 +0.7% yes
  • Prompt speed: n/a. The change only touches the load-time table that prices draft depth; the prompt path is untouched.

  • Licence of any new weights or drafter: n/a.

  • Raw receipts, so the comparison can be repeated: https://gist.github.com/AbrahamCete/22d833227178a24391c73192b0ab586f. It holds the bench JSON files, each server's log with the printed cost table and its done lines, the lane traces, the scripts, and the print patch.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (Every cell is within its run spread. The largest move, sampled chat at four streams, is -0.9% over four servers an arm, with a standard deviation of 1.3 to 1.9 tok/s. No --drafter path changes.)

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@AbrahamCete thanks, this is a clean, contained piece of #2605, and the receipts are thorough. The change only touches the load-time table, on scratch caches, and the table only prices draft depth, so it can change which width is drafted but not which token comes out. Your equal token hashes and invariants back that up. A one-stream server times exactly as before, since every bucket there has one window.

A few things:

  1. Lone windows: a lone window's rows are a stream's distinct draft tokens, which the MoE also routes apart. Keeping its table on one repeated token means lone windows and shared buckets of the same size are now priced under different routing. Could you say why they should stay that way? A single lone table timed on distinct tokens would show whether it moves much.
  2. The step: 7919 gives distinct ids only when it doesn't divide min(vocab, 65536) − 1. Could you pick a step coprime by construction, or assert it, so a vocabulary of the wrong size can't quietly fall back to one token?
  3. Optional: the new test pins fillTokens but not that Rig.time calls it with the window count. If there's a cheap way to cover that call, it would catch a future regression.

As your receipt shows, on its own it changes the decisions but not the speed. The speed is the lane-core piece's to deliver in #2605.

None of these blocks: it goes on our landing queue now, and the CHANGELOG line is ours.

AbrahamCete and others added 2 commits November 9, 2026 06:32
…ne token

The depth rule's shared_costs came from rows of one repeated token, which
the 35B's MoE routes to one expert set. Rows of different streams route to
different experts and cost 3-22% more a forward at 2-64 rows on gfx1151
(ashhart#2605), so the table underpriced shared rounds and the rule folded the rest
into an overhead it charged plain rounds too. A forward over two or more
windows now times a distinct token a row. A lone window keeps its one
repeated token, so the one-stream timings stay as they were.
@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. All three are in, as two new commits on top of 2628baf, so nothing was force-pushed: 6cb4f45 and 89ea115.

  1. Lone windows. They stay on one token because pricing them on distinct tokens makes one stream slower.

    • I timed both on 89ea115. H is this head. L is the same build with lone windows on a token a row too (scratch only: windows > 1 becomes windows > 0 in fillTokens).

    • Setup: servers H1 L1 L2 H2, 35B --parallel 4, one stream, tools/bench_concurrent.py --tokens 256 --reps 3, sampled then greedy, each in its own window.

    • The lone table moves 7-15% from 2 rows up, against 3-22% for the shared buckets. Milliseconds a forward, two servers an arm:

      rows H (one token) L (a token a row) L / H
      1 11.56 11.62 1.00
      2 13.63 14.55 1.07
      4 18.58 20.67 1.11
      8 26.75 30.77 1.15
      12 41.40 46.11 1.11
      16 40.05 45.37 1.13
    • On one stream, L's rule drafts less when greedy: drafted rows a round fall from 1.87 to 1.40, and tokens a round from 2.14 to 1.83. Greedy chat is 8.4% slower, which is the drop the spike's prototype 2 had on 857b11b (-9.0%), and why HIP: sampled chat at 4 streams on Qwen3.6-35B-A3B is 6% faster with --mtp-drafts 0, because the depth rule underprices sampled drafted rounds #2605 kept lone windows as they were. Aggregate tok/s, with token hashes equal in every cell:

      prompt T H L L vs H
      chat 0 100.1, 100.1 91.8, 91.5 -8.4%
      chat 1.0 97.5, 93.8 99.8, 97.7 +3.2%
      code 0 123.2, 124.9 125.4, 125.4 +1.1%
      code 1.0 106.8, 106.5 105.1, 105.4 -1.3%
    • So the distinct-token lone table is closer to what a lone window's rows cost, yet the one-stream rule picks worse depths with it. I haven't found why. My guess is the overhead the rule learns from one stream's rounds, which would make it a question for the lane-core piece. Until then, the one-stream table stays as it was, and only the multi-stream buckets change.

  2. The step. In 6cb4f45 the stride is 7919, or 7927 where 7919 divides the span.

    • Their product, 62,773,913, is larger than every span, so at most one of them divides it and the stride is always coprime.
    • A served span of 65535 keeps 7919 (65535 mod 7919 = 2183), so the tables in the description still hold. This head's shared table matches them within 0.5%; the 33-64 row bucket is 2.8% lower.
    • The new test covers vocabularies of 15,839 and 15,855 ids, whose spans are twice 7919 and twice 7927. With the old stride the first gave two ids, and the test failed.
    • I first tried 65537, a prime above every span. It is coprime, but 65537 is 2 mod 65535, so a served vocabulary's ids became 1, 3, 5, … and its shared table fell up to 10% back toward main's. That's why the step switches on divisibility instead.
  3. Rig.time's call. In 89ea115 fillRound fills a round's greedy draws and tokens from its windows' widths and returns its rows, so the window count comes from the widths instead of being passed by hand.

    • Rig.time only points each window at its rows. Dropping the call would also leave its draws unset.
    • The new host test pins a lone window (one token, positions in order) and a shared round of 2 and 3 rows (distinct tokens, each window's draws from the same position).

Checks on 89ea115, in a clean archive:

  • zig build test test-golden: 612/612 steps, 7991 of 8057 passed, 66 skipped.
  • zig build hip-host-test: 68/68.
  • zig build test-qwen35-hip-host: 86 of 88 passed, 2 skipped.
  • zig build check-native-hip-host: 6/6 steps.
  • tf-qwen35-test check --only invariants: 51 passed, 0 failed, 1 skipped.
  • Lean: 398 problems on the base and on the head, 0 new.

The description is updated. The raw data for item 1 (lw-* files and lone.sh) is in the same gist.

@ashhart
ashhart force-pushed the fix/hip-shared-row-tokens branch from 89ea115 to 9f15778 Compare November 9, 2026 07:04
@ashhart
ashhart merged commit 7b07c81 into ashhart:main Nov 9, 2026
1 check failed
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@AbrahamCete

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. One thing about the landing: the force-push at 07:04 put back the branch as it was rebased at 06:32. So the two commits from your review that I pushed at 06:48 aren't on main:

  • 6cb4f45: the stride, 7919, or 7927 where 7919 divides the span;
  • 89ea115: fillRound.

main's hip_costs.zig still has the plain 7919 stride. Both commits apply cleanly on main as they are, so I'll open them as a small follow-up PR, with the checks from the reply above re-run on main.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

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.

2 participants