Skip to content

fix(hip): keep the shared rows' token stride coprime to the vocabulary's span - #2661

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

ashhart merged 3 commits into
ashhart:mainfrom
AbrahamCete:fix/hip-shared-row-stride

Conversation

@AbrahamCete

@AbrahamCete AbrahamCete commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

These are the two commits from #2652's review that its landing left out (#2652 (comment)). On main, hip_costs.zig steps the shared rows' token ids by 7919. That gives distinct ids only when 7919 doesn't divide min(vocab, 65536) - 1.

  • fix(hip): keep the shared rows' token stride coprime to the vocabulary's span: the stride is 7919, or 7927 where 7919 divides the span. Their product is larger than every span, so at most one of them divides it, and the stride is always coprime.
  • refactor(hip): fill a timed round's tokens and draws from its widths in one helper: fillRound fills a round's greedy draws and tokens from its windows' widths and returns its rows. Rig.time no longer passes the window count by hand.

A served span of 65535 keeps 7919 (65535 mod 7919 = 2183), so a served vocabulary's timed ids and table stay as #2652 landed them. The table only steers draft depth, so tokens are unchanged.

Checks on this head

  • Head commit: 099ece3. Its hip_costs.zig and hip_costs_test.zig are byte-identical to fix(hip): time shared rows with a token a row, keep lone windows on one token #2652's last pushed head, 89ea115, where the receipts in the review reply ran.
  • Lean checker, python3 tools/zig/lean_check.py: 398 problems on the base (1bb0ea2) 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: 621/621 steps, 8095 of 8161 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. zig build native-hip: exit 0.
    • The two new tests in hip_costs_test.zig failed before their change and pass after it:
      • "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": it failed to compile before fillRound.
  • CI: green on 099ece3, 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:

Receipt

  • Main against branch: no served cell changes, because a served vocabulary's ids are the same. The tables and the one-stream A/B for this code are in the fix(hip): time shared rows with a token a row, keep lone windows on one token #2652 review reply above. Their raw data is in https://gist.github.com/AbrahamCete/22d833227178a24391c73192b0ab586f (lw-*).
  • Boxes it reaches: HIP, the qwen3_5 family's load-time cost table. Only a vocabulary whose span 7919 divides gets different ids.
  • New switch? None.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main 1bb0ea2 and this head; 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.
  • Paths and platforms the change reaches, which I ran and which I could not: HIP on gfx1151; other AMD chips not run.
  • Exactness: tf-qwen35-test check <35B> --only invariants: 51 passed, 0 failed, 1 skipped. The table only steers draft depth.
  • Main against this branch, same machine and checkpoint: as above.
  • Decode speed before and after: unchanged by construction for a served vocabulary (same ids); see "Not run".
  • Prompt speed: n/a. The change only touches the load-time table that prices draft depth.
  • Licence of any new weights or drafter: n/a.

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. (A served vocabulary times the same ids as main.)

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@AbrahamCete, thank you, and I'm sorry: that was our landing tool's fault, not yours. It stacked #2652 at 06:32, and at landing it put back that stacked branch without checking for your 06:48 push. These two commits are what we asked for. The stride is always coprime to the span (two primes whose product passes every span, so at most one divides it), fillRound is a clean extraction, and both tests failed before their change. It's in our landing queue now, under your name. We're also fixing the tool so a PR that moves after it's stacked is left out of that train rather than overwritten.

AbrahamCete and others added 3 commits November 9, 2026 10:49
…y's span

7919 gave distinct ids only when it did not divide min(vocab, 65536) - 1; a
vocabulary of 15839 ids gave two. Where 7919 divides the span the stride is
now 7927, the next prime. Their product passes every span, so at most one
divides it and the stride is always coprime. A served vocabulary's span of
65535 keeps 7919, so its timed table does not change.
…in one helper

Rig.time passed fillTokens the window count by hand, and no test saw that
call. fillRound now fills a round's greedy draws and tokens from the
windows' widths and returns its rows; Rig.time only points each window at
its rows, and the new host test pins a lone window and a shared round.
@ashhart
ashhart force-pushed the fix/hip-shared-row-stride branch from 099ece3 to 394f4bb Compare November 9, 2026 10:49
@ashhart
ashhart merged commit 01adfd3 into ashhart:main Nov 9, 2026
2 of 10 checks passed
@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.

@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