Skip to content

kolibri1: tree-attention cache offsets are signed, so a cache placed below the origin no longer overflows - #3561

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jschmied:kolibri1-offsets-signed
Nov 17, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jschmied:kolibri1-offsets-signed

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

On main (9b2f2ca12d), a Kolibri-1 server with default flags (paged full-layer caches, copy drafts, prompt cache) panics on its first request in a ReleaseSafe build:

panic: integer overflow
zig/src/families/kolibri1/forward.zig:407 in offsets
zig/src/families/kolibri1/forward.zig:505 in captureStep  (graphs on; forward.zig:370 in forward with graphs off)
zig/src/families/kolibri1/backend.zig:470 in verify

offsets computes each layer's cache offset from the tree origin as (m.k[i] + at - m.origin) / 2 in u64. With paged caches, attach frees and reallocates the sliding layers' rings after Model.init allocated origin, so a ring can land below origin, and the subtraction goes negative. Whether it does depends on where the allocator puts the rings: with linear caches (TENSORFOLD_KOLIBRI_KV_PAGES=0) main serves fine. A ReleaseFast build has no check. There the u64 wraps, and the kernel probably gets a wrong offset for those layers. I have not checked what a ReleaseFast build serves in that case.

Change: a helper, elementsFrom(origin, at), takes the difference as a wrapping u64 subtraction, bit-casts it to i64 and divides by 2 exactly. tree_attention.cu:78 already reads the offsets as long long, so a negative offset is valid there. No kernel changes and no .cu file touched. Served behaviour is unchanged wherever main didn't overflow.

Evidence on 9a8fd9b936 (GB10, sm_121):

  • Host test (forward_offsets_test.zig, run by zig build test-kolibri-host): offsets above, below and equal to the origin. test-kolibri-host gives 26 passed, 1 skipped.
  • Planted control: with elementsFrom reverted to main's unsigned arithmetic, the same test crashes: panic: integer overflow at forward_offsets_test.zig:6, the below-origin case. That gives 25 passed and 1 crashed; with the fix, 26 passed.
  • Served, default paged caches: a ReleaseSafe native build of 9a8fd9b936 (served binary md5 eae8441c) serves all 24 prompts copy-only with no empty reply. 4 and 8 concurrent streams give the same replies as solo. The control, main 9b2f2ca12d built the same way (md5 ff46eda4), panics on the first rounds with the overflow above.
  • Against main: the combined reply hash (reasoning + content + token ids over 24 prompts, greedy and seeded; an empty reply fails the gate) equals main's with TENSORFOLD_KOLIBRI_KV_PAGES=0, b3e6e511ac84e921.
  • Resume: not run separately on this head. The fix is in the per-forward offsets, so a resumed turn takes the same path. On the drafter branch (Kolibri-1: drafts from the published EAGLE-3 drafter release on the native lane core #3491), which carries this commit, resumed == fresh holds over the same 24 prompts.
  • Unchanged: no refusal, flag or kernel changes. forward.zig is 600 lines.

Found while bringing the Kolibri-1 drafters to main (#3491). That PR builds on this one.

Proposed CHANGELOG line (Fixed): Kolibri-1 on CUDA no longer panics on its first request when paged caches place a sliding layer's ring below the tree origin.

jschmied and others added 2 commits November 17, 2026 03:01
…low the origin no longer overflows

On main a copy-drafts-only server (ReleaseSafe) panics at its first one-row step graph: offsets computed
m.k[i] + at - m.origin in u64, and attach's sliding rings can be allocated below origin. The kernel reads the
offsets as long long, so a negative one is valid.
@ashhart
ashhart force-pushed the kolibri1-offsets-signed branch from 9a8fd9b to 3e1ace6 Compare November 17, 2026 03:02
@ashhart
ashhart merged commit 3f1290f into ashhart:main Nov 17, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. 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.

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