ReadonlydisposedWhether this branch has been disposed
ReadonlyhandleInternal handle (for debugging)
ReadonlyperplexityBranch's perplexity
ReadonlypositionBranch's current position
ReadonlyseqBranch's sequence ID
Accept token for repeat-penalty tracking
Freeze the current logit distribution into this branch. Essential before fork().
Accept and advance — write token to KV and update branch state.
Decode a single token, write to KV, and capture resulting logits
Release handle but keep KV entries intact (use for winners, continue with raw ops)
Fork this branch to a new sequence
The child shares the parent's KV prefix in memory (metadata-only under unified KV, no KV buffer copy). Logits, sampler state, and perplexity tracker are cloned so the child can diverge independently. Fork from any branch — root or intermediate — to build arbitrarily deep trees.
Sequence ID for the forked branch
Sample next token without advancing state. Inspect before committing.
Discard branch — remove its divergent KV entries and free the handle (use for losers)
Reseed the sampler's PRNG for diversity after fork()
CRITICAL for parallel generation: Without reseeding, all forked branches produce identical outputs because they share the same PRNG state.
Only affects stochastic samplers (temperature > 0). Greedy samplers are unchanged.
New seed for the PRNG
Sample next token from branch's frozen logits snapshot
StaticcreateCreate a root branch at the given position
The branch takes ownership of the sequence and creates its own sampler chain from the provided params. Call captureLogits() after prefill to freeze the logit distribution before forking.
SessionContext to create branch on
Sequence ID for this branch
Starting position (typically prompt token count)
Optionalparams: SamplingParamsSampling parameters (temperature, topP, etc.)
Forkable inference handle for covalent generation
A Branch owns everything needed for independent generation: a KV cache sequence, sampler chain, logits snapshot, and perplexity tracker.
Forking is cheap — the KV prefix is shared in memory (metadata-only operation under unified KV — no KV tensor buffers are copied), so sibling branches read from the same physical KV entries. Only tokens decoded after the fork point are exclusive to each branch.
Branches form trees, not just flat lists. Fork from root for best-of-N, fork from children for MCTS/beam search, fork from a draft for speculative decoding.
The produce/commit protocol separates sampling from state advancement: produce() samples without writing to KV, letting you inspect the result before deciding to commit().
Example: Best-of-N with perplexity selection