Repository navigation
lanes: an external drafter behind any target backend - #455
Conversation
|
Thank you, @jschmied. An external drafter in front of any target, with the target's own draft left unused, is the right split. Drafts off never reaching the drafter is the property we will keep. The host tests you describe, drafted rounds equal to one-token rounds, a shifted row failing, and a whole restore starting one round late, are the gate for the interface. Two answers. features on the backend is the boundary we want. verify stays the target's check of tokens. The wrapper already turns held drafts into host tokens before that call. Putting the state handoff inside verify would give verify a second job. Host tokens are the right first path. One device-to-host copy a round is acceptable until a CUDA target measures it. A device buffer on the window can wait for that measurement. We will re-run the host tests on the current tip. Each comment has to be one line before we land the interface under your name, and that includes the file headers. backend.zig, drafter.zig, drafted.zig, and drafted_test.zig have comment runs of two or more lines. The check reports 30 places where a comment continues on the next line. The files are under 600 lines. drafted_test.zig is 509, so more tests belong in a second file. Nothing in the served families calls it yet. A Kolibri or Laguna drafter is a later change, and it will use this hook rather than a private copy of the round loop. Chains only, as you scoped it. Trees stay with a head built into a family. deinit frees the scratch lists and does not release a stream still in the map. Callers release first. Worth one line in the header so the next adapter does not miss it. |
4ed2640 to
a419512
Compare
a419512 to
8941933
Compare
A drafter that reads the target's tapped states (EAGLE-3, a DFlash block, an MTP head loaded on its own) now sits in front of any backend that exposes `features`: - backend.Features and an optional Backend.features: the tapped states of cache rows the target still holds (the prompt's, the last verify's). - drafter.Drafter: taps, depth, open, absorb (rows from `start`, the token after each; a rollback is the next absorb's start), hold, held, release. - drafted.Drafted: target + drafter as one Backend. Prefill absorbs the prompt's rows, each round's kept rows are absorbed before holding drafts, held drafts reach the target as host tokens. Chains only; trees and early speculation stay with heads built into a family. facts() derives the round loop's Model from the target's. No family changes: the target's own draft is never called, Nemotron's MTP path is untouched. Tests on the fake target: drafted == one-token rounds (greedy, sampled, shared), and the drafter's drafts land far above chance; shifting the absorbed rows by one fails both.
With prompt reuse a restored prefix never runs through the target, so it has no tapped states: Drafted absorbs the prompt from s.cached, and a drafter's first absorb may start past 0 (it drafts without the restored rows). Test: a prompt restored from a kept state, greedy and sampled, equals the one-token decode, and the drafter's first row is the restored one.
- Drafts off: a stream with drafts off never reaches the drafter, so the wrapped backend's "draft": false is the target alone. - Lifecycle: the wrapper tracks the streams it opened; a failure after the target's prompt pass releases target and drafter there (the core releases only a cancelled pass, and then the drafter was never opened). - Drafter facts: depth, step cost, prior, plain guard and batching come from the drafter, not the target (whose own head may not exist). - A prompt restored whole: no feature row is asked for; the drafter still holds drafts after the pending token, and the target rejects what does not land. - Batched calls: one absorb, one hold and one readback for a round's streams. - Features: space, device, dtype, a readiness handle and the validity interval are part of the contract. - keep() matches windows by position and checks the streams; draft storage grows with the windows instead of a fixed width. Tests: drafts off makes no drafter call; injected failures (open, absorb, missing features, a cancelled pass) clean up once; a prompt restored in part and whole decodes exactly; the drafter's facts reach the depth rule; a shared round is one hold of both streams. Removing the drafts-off bypass, the cleanup or the whole-restore check fails its test.
- Features lifetime matches the round loop: a single-stream round keeps before it drafts, so the rows a keep retains stay readable until the next verify, prefill or release. A strict test target holds its own state snapshot, overwrites what a keep drops and refuses anything outside the contract; all drafted tests run on it. - A prompt restored whole: the drafter is never asked to draft without the row before its pending token; that one round takes fillers (the pending token, which the target rejects) and the drafter starts after the first verify. - The stream's slot is reserved before the drafter opens it, so a failed insert cannot leak an opened stream. - A steady round allocates nothing: the per-round lists are kept. - Features.ready is a tagged fence (none, cuda_event, metal_event). Reading the verify's rows shifted by one fails three tests on the strict target (RowsNotHeld); dropping the fillers fails the restore test.
- A new draft request clears the stream's bootstrap fillers: after a whole restore a copy round can take the place of the filler round, and the stale fillers then replaced the drafter's first real drafts. Regression test drives that sequence through the wrapper. - Backend.prepare_features(taps): the target learns the drafter's layers once, before any forward (Drafted.init); features() must ask for that set. A target without the hook is built with its taps. The strict test target refuses an unprepared or different tap set. Dropping the filler reset fails the regression test; skipping the preparation fails four drafted tests.
Every comment in backend.zig, drafter.zig, drafted.zig and drafted_test.zig is one line (tools/zig/lean_check.py reports none there); the Features contract moves to a one-line struct doc and one line a field. drafted.zig's header says deinit releases no stream still in the map, so callers release first. Rebased on zig-flashnext 7ae6df7; zig build test passes.
Drafter.Facts.stream_bytes: device bytes each opened stream holds (an EAGLE drafter's context cache); Drafted.streamBytes(target) gives what an admitted stream takes in all, for a family adapter to report as its stream_bytes so the native server's fail-closed admission does not undercount. Test: the facts test checks the sum; returning the target's bytes alone fails it.
fcef055 to
0bdaff5
Compare
|
Thank you @jschmied. Merged into main (41d4b5c) as reviewed: the external drafter interface in the lane core, where a stream with drafts off never reaches the drafter. Your host tests pass on the current tip on macOS and Linux. Kolibri and Laguna drafters can plug in through it next, rather than through a private copy of the round loop. |
…the lane core Thanks @jschmied.
Today a drafter lives inside its family's backend:
Backend.draftis that family's MTP head. Drafters that read thetarget's hidden states from outside (EAGLE-3, a DFlash block, an MTP head loaded on its own) have no place to go. Two
cases I know of: Kolibri-1, which has no MTP head and which we serve on our fork with an EAGLE-3 drafter
(
josch15366/Kolibri-1-EAGLE3-drafter, about +25 % single-stream decode, byte-identical), and Laguna-S-2.1 withpoolside's published DFlash drafter (#312).
This PR adds the interface in the lane core only. No family changes; Nemotron's and Flash Next's own heads are untouched.
What changes
backend.zig:Featuresand an optionalBackend.features(s, taps, start, count), the tapped states of cache rowsthe target still holds: the prompt rows its pass computed (from
s.cached) until the first verify, then the lastverify's rows, and after a keep the rows it retained (a single-stream round keeps before it drafts), until the next
verify, prefill or release. Packed rows in the drafter's
tapsorder,space(host, or a device pointer ondevice,which the drafter must run on),
dtype, andready, a tagged fence (none,cuda_event,metal_event). Null bydefault (
error.NoFeatures).backend.zig: optionalBackend.prepare_features(taps): the target learns the drafter's layers once, before anyforward (
Drafted.initcalls it), and keeps those layers' states and no others;features()must ask for that set.A target without the hook is built with its taps.
drafter.zig(new):Draftervtabletaps,facts,open,absorb,hold,held,release. Every call takes around's streams together (
[]Absorb,[]Hold, oneheldreadback), so a GPU drafter runs them as one batch.Factscarries the drafter's own depth, step cost, prior, plain guard, batching and per-stream device bytes(
Drafted.streamBytes(target)sums them for the native server's memory admission).drafted.zig(new):Drafted, a target backend plus a drafter as oneBackend, so the round loop is unchanged."draft": falseon the wrapped backend is the target alone.reach the target as host tokens.
that one round takes fillers (the pending token repeated, which the target rejects), and the drafter starts after
the first verify. A new draft request clears unused fillers (a copy round can take the filler round's place).
open); a failure after thetarget's prompt pass releases target and drafter there (the core releases only a cancelled pass, and then the
drafter was never opened).
facts()takes the depth rule's step cost, prior, plain guard and batching from the drafter, not the target.fake.zig: the fake target exposesfeatures(a row's state is its token).Tests (
drafted_test.zig, host only)All drafted runs go through a strict test target: the fake with its own state snapshot, holding exactly what
Featurespromises (a keep overwrites the rows it drops) and refusing anything else. The fake drafter refuses to draft without
the row before its pending token.
one hold of both streams, at most one readback a verify).
mistake would drop it to about 1 in 97). Shifting the absorbed rows by one fails.
rows.
each released once, the drafter only if it was opened.
drafter, not stale fillers. The strict target refuses an unprepared or different tap set.
Removing the drafts-off bypass, the cleanup, the whole-restore check, the fillers, the filler reset or the tap
preparation each fails its test; reading the
verify's rows shifted by one fails three tests on the strict target (
RowsNotHeld).zig build testpasses onzig-flashnext 7742ddd (GB10, Zig 0.17.0).
Not in this PR
featuresyet. The first would be a Kolibri-1 adapter on the CUDA registry (RFC: zig cuda: serve through tensorfold-native, with a CUDA family registry (Nemotron first) #443) with ourdrafter behind it; a registry hook so an entry can load a drafter belongs with it.
step_ms x drafts); a block drafter (DFlash) costs one pass for any depth, soa cost-by-depth table in
depth.zigshould come with the first measured block drafter.them (3 taps x 4096 x bf16 at 128K tokens is about 3 GiB). Streaming prefill chunks into
absorbshould come with aCUDA adapter that needs it.
a whole restore it starts one round late. Keeping the last tapped row with a kept prompt state would close that.
Questions
Backend.featuresthe right boundary, or would you rather the target hand states to the drafter insideverify(one call fewer per round, but
verifygrows a second job)?Window.heldto name the drafter's buffer; worth it now, or after a CUDA target measures the copy?