Skip to content

kolibri1 cuda: decode rounds of several rows replay CUDA graphs - #4884

Merged
ashhart merged 4 commits into
mainfrom
lead/kolibri-round-graphs
Nov 24, 2026
Merged

ashhart merged 4 commits into
mainfrom
lead/kolibri-round-graphs

Conversation

@ashhart

@ashhart ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

What changes

A lone Kolibri-1 row already replays its slot's captured step graph. A round of two or more rows (several streams, or a verify window) launched every layer eagerly. Such a round now replays a graph from cuda.graph_cache, captured at the first round of its shape. The key is the round's rows, its streams and tree attention's key groups. The cache's usual policy applies: at most 48 graphs, the memory floor, and TF_GRAPH_CACHE=0 runs it eagerly.

  • forward.Model.forward splits into stage and launch:
    • stage uploads ids, positions, slots, the tree plan, paths, cache offsets and the page table on the stream, as before;
    • launch, unchanged, reads only device memory ("a graph can hold them").
  • rounds.zig holds the cache, made at the first round where the backend's address is final. It replays launch over every row, which is what verify asked the eager forward for.
  • attach drops these graphs along with the step graphs.
  • With TENSORFOLD_KOLIBRI_GRAPHS=0, every round stays eager.
  • The f64 angle-table test moves unchanged to forward_rope_test.zig, which keeps forward.zig under the 600-line cap.

Exactness

A replayed round makes the same launches with the same arguments as the eager round of that shape. The rest is device-indirect:

  • a tree plan's offsets depend on its rows and streams alone, which the key holds (a host test checks this);
  • the key groups are in the key;
  • every buffer address is fixed until attach.

So every row keeps its bits.

Checked

On a Linux x86_64 host with no GPU, using Zig 0.17.0, at this head:

  • zig fmt --check and zig ast-check on every changed Zig file; python3 tools/zig/lean_check.py: 165 problems, the same count as main; the push gate's scanner: safe.
  • zig build test-kolibri-host (the new plan-offset test and the moved angle-table test): pass
  • zig build check-native-cuda-host: pass, and a compile probe in rounds.Rounds.forward confirmed the step reaches it

Not run

No device run: graph capture, replay and the device suite are unrun.

Device cells that decide it

Run each as an A/B of main against this head, with an A/A first and a balanced order, dropping run 1. Give each stream its own prompt.

Cell GPU Checkpoint What it covers
1 GB10 Kolibri-1 decode at 2, 4 and 8 streams; tokens equal to main and to TENSORFOLD_KOLIBRI_GRAPHS=0; decode tok/s
2 GB10 Kolibri-1, with copy drafts on verify windows of several rows; same rows
3 GB10 Kolibri-1 with paged KV (attach) rounds after the arena exists; tokens equal

The device suite zig/tests/cuda/kolibri_tests.zig should also pass on the GB10.

A lone row already runs its slot's captured step graph, but a round of two
or more rows (several streams, or a verify window) launched every layer
eagerly. Such a round now replays a graph from graph_cache, captured at the
first round of its shape and keyed by its rows, its streams and tree
attention's key groups.

forward() splits into stage() and launch(). stage() uploads the round's ids,
positions, slots, plan, paths, cache offsets and page table on the stream as
before. launch() reads only device memory: a tree plan's offsets depend on
its rows and streams alone, and the key groups are part of the key. So a
replayed round makes the same launches with the same arguments as the eager
round, and every row keeps its bits.

attach drops these graphs along with the step graphs. With
TENSORFOLD_KOLIBRI_GRAPHS=0 every round stays eager, and TF_GRAPH_CACHE=0
runs the cache's rounds eagerly.

The f64 angle-table test moves unchanged to forward_rope_test.zig, which
keeps forward.zig under the 600-line cap.
@ashhart
ashhart force-pushed the lead/kolibri-round-graphs branch from 2f51fd4 to 520eddf Compare November 24, 2026 21:49
@ashhart
ashhart merged commit 0652b79 into main Nov 24, 2026
11 of 12 checks passed
@ashhart
ashhart deleted the lead/kolibri-round-graphs branch November 24, 2026 21:49
ashhart added a commit that referenced this pull request Nov 25, 2026
…at a CUDA start

Kolibri-1 read it with getenv outside the registry (backend.zig's envOff): exact 0 turned the one-row step
graphs and, since #4884, the multi-row decode round graphs off, and every other text, blank, 1, "false" or
"off" included, kept them on. It is now a .cuda flag row in platform/environment.zig, read once in
Kolibri.init through the registry:
- unset, blank and 1 keep the graphs (the default, as before); 0 runs both eager (as before);
- any other text, which read as on before, is refused by name at a CUDA start, like every registered setting.
docs/environment.md documents it in the CUDA table; tokens are the same either way.

Tests: environment_kolibri_test.zig (blank and unset keep the default, 0 and 1 accepted, other text refused by
name on CUDA and ignored on Metal), and the setting in environment_test.zig's table of every row.
ashhart added a commit that referenced this pull request Nov 25, 2026
…at a CUDA start

Kolibri-1 read it with getenv outside the registry (backend.zig's envOff): exact 0 turned the one-row step
graphs and, since #4884, the multi-row decode round graphs off, and every other text, blank, 1, "false" or
"off" included, kept them on. It is now a .cuda flag row in platform/environment.zig, read once in
Kolibri.init through the registry:
- unset, blank and 1 keep the graphs (the default, as before); 0 runs both eager (as before);
- any other text, which read as on before, is refused by name at a CUDA start, like every registered setting.
docs/environment.md documents it in the CUDA table; tokens are the same either way.

Tests: environment_kolibri_test.zig (blank and unset keep the default, 0 and 1 accepted, other text refused by
name on CUDA and ignored on Metal), and the setting in environment_test.zig's table of every row.
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