Skip to content

A decode's outputs stay readable while the next is queued; a slot orders its inputs by its own events - #171

Open
joelteply wants to merge 1 commit into
fable/graph-slotsfrom
fable/output-ring
Open

joelteply wants to merge 1 commit into
fable/graph-slotsfrom
fable/output-ring

Conversation

@joelteply

Copy link
Copy Markdown

A context has one output buffer and reads it only after synchronize(), which waits for everything queued, so a
caller serving several minds could not queue mind B's step before reading mind A's. With the output ring on
(llama_set_output_ring), each decode takes the spare buffer by pointer swap before reserving its outputs and records
an event once its output copies are queued; a ticket (llama_output_ticket) reads that decode's logits after waiting
on its event alone (llama_ticket_logits). Off by default.

Queuing was still serialized one level down: a scheduler of one copy has no events, so every split input from the
CPU (the token embedding) waited for the Metal backend to drain, A's step included. ggml_backend_sched_use_events
gives such a scheduler events, so each input waits for this scheduler's own last use of its backend; graph slots
use it, a slot's last use being that mind's previous step.

Measured on the M5 (Qwen3.6-35B-A3B Q4_K_M, Q4_0 K/V, FA, core stopped, 03:24-03:27Z), test-output-ring: two minds,
each her own stream and graph slot, one token each in turn, 192 steps, serial against pipelined (B queued before A
is read):
minds at 1.2k/1.9k: 14.07 / 14.05 -> 13.56 / 13.60 ms/step (96-97%); again 14.17 -> 13.52 (95%), submit 1.35 ms
minds at 30k/30.7k: 18.34 -> 17.89 ms/step (98%), submit 1.45 ms
logits bit-identical at every step (max |diff| 0)
Without the scheduler events the pipelined arm was slower than serial (contended: 27.05 -> 30.11 ms/step).
The live core is GPU-bound now (a 10 s sample at 03:30Z: the persona-scheduler thread 95% in settle, 5% in submit),
so this plumbing's value is what it enables (a decode read by ticket, inputs ordered by events: batched decode),
not the 2-5% it saves alone.

Stacked on #170. Validator: test-output-ring -m <model> -ngl 99 (OUTPUT_RING_DEPTH sets the first mind's depth); fails on any logit difference.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…ind's slot orders its inputs by its own events

A context has one output buffer and reads it only after synchronize(), which waits for everything queued, so a
caller serving several minds could not queue mind B's step before reading mind A's. With the output ring on
(llama_set_output_ring), each decode takes the spare buffer by pointer swap before reserving its outputs and records
an event once its output copies are queued; a ticket (llama_output_ticket) reads that decode's logits after waiting
on its event alone (llama_ticket_logits). Off by default.

Queuing was still serialized one level down: a scheduler of one copy has no events, so every split input from the
CPU (the token embedding) waited for the Metal backend to drain, A's step included. ggml_backend_sched_use_events
gives such a scheduler events, so each input waits for this scheduler's own last use of its backend; graph slots
use it, a slot's last use being that mind's previous step.

Measured on the M5 (Qwen3.6-35B-A3B Q4_K_M, Q4_0 K/V, FA, core stopped, 03:24-03:27Z), test-output-ring: two minds,
each her own stream and graph slot, one token each in turn, 192 steps, serial against pipelined (B queued before A
is read):
  minds at 1.2k/1.9k: 14.07 / 14.05 -> 13.56 / 13.60 ms/step (96-97%); again 14.17 -> 13.52 (95%), submit 1.35 ms
  minds at 30k/30.7k: 18.34 -> 17.89 ms/step (98%), submit 1.45 ms
  logits bit-identical at every step (max |diff| 0)
Without the scheduler events the pipelined arm was slower than serial (contended: 27.05 -> 30.11 ms/step).
The live core is GPU-bound now (a 10 s sample at 03:30Z: the persona-scheduler thread 95% in settle, 5% in submit),
so this plumbing's value is what it enables (a decode read by ticket, inputs ordered by events: batched decode),
not the 2-5% it saves alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant