Repository navigation
deepseek_v41 handoff: CUDA record codecs, FP4 packers and the part plan - #3563
BlivionIaG wants to merge 39 commits into
Conversation
…, sent as KV handoff protocol 2 hybrid_state gives Qwen3.8-27B's recurrent and attention state one byte order, header and token sha256 that CUDA and Metal both read. Protocol 2 sends a recurrent layer's state part by part with a CRC-32 a frame (ARMv8 CRC instructions where present); protocol 1 readers refuse it. The producer table holds exports for a hand-off, refuses a reused id, expires them, and caps the bytes held (HeldExportsFull). fabric_handoff and tf-mcdma-pair tests cover the fake link and the frames. (ashhart#1594 step 2b)
…a kept state, and is kept as remote The lane host fetches a remote prefix on its own thread after the cache's peek, leads the prefix wait for requests on the same prompt, and falls back to a full local prefill on a refusal. With TF_PREFILL_KEEP (default 1) the states a pulled prefix builds are kept in the prompt cache marked remote, never written to disk or learned from, so a chat's follow-ups resume on the Mac. Tests pin provenance (remote_prefix, pulled_prefix), the keep rules and slot 0's let-go. (ashhart#1594 step 2b)
…ls them over an MKVH link cuda_produce reads a CUDA copy in place and serves hand-off exports as the link's service, at most TF_PRODUCE_HELD_GIB held (default 32). On the Mac, qwen27_remote pulls a prefix into a blank state, checks model, checkpoint, token sha, TP, geometry and protocol, and refuses a checkpoint whose state is not Qwen3.8-27B's (Qwen3.5-9B) at start. remote_trigger asks the GB10 over bounded HTTP, with TF_PREFILL_API_KEY_FILE's key as a Bearer token and a named 401. A detected mismatch turns remote prefill off; a refusal or timeout does not. The TF_PREFILL_* settings join the environment registry. (ashhart#1594 step 2b)
… a GB10, and the hand-off's API fields A completion's kv_transfer_params.mcdma_handoff becomes its hand-off; a malformed one now returns 400 on every native server. Replies on a remote prefix report exact_mode "remote_prefix" with remote_prefix, pulled_prefix and kept_remote_cache_tokens. docs/api.md and docs/environment.md describe both. Off unless both machines are started with the new options. (ashhart#1594 step 2b)
…ecks on real weights The GB10 exports a state (export, tail); the Mac restores it from a file or a live pull and checks it: teacher-forced KL and top-1 (close), the backends' own gap (floor), stage times (time, multi), and agree, which lists every position where the restored state's greedy token differs from the Mac alone with both top-1/top-2 margins, plus repeat restores' bytes and tokens. State files are read in 1 GiB pieces, as macOS refuses one read over 2 GiB. (ashhart#1594 step 2b)
…rrow and no promise A repeat hand-off whose lookup finds a remote copy at the cut resumes below it on the engine's own state and keeps the cut as its own. When a queued chat protects the remote copy and the budget has no room beside it, the guard refuses that keep (CachePromised). The test shows the export and the reply still go on, the borrow from below() is let go, no job is left holding a promise, and the remote copy still serves the next chat.
…umes on the Mac A stream on a pulled prefix was not plain(), so leave() dropped slot 0's record, rewindPoint returned 0 and every follow-up after a hand-off started at 0 and pulled its whole prompt from the GB10 again. Such a stream now counts as plain for slot 0: its pass makes a rewind point at the history end past the cut, and leave() keeps the record, marked remote (Standing.remote). A pass that resumes on that record, here or back at its point, takes its rows' origin (inherit: reuse.remote set, reuse.pulled cleared), so its reply reports the prefix as kept remote and its keeps are marked remote, never the Mac's own. A refused copy that ran here from 0 leaves an own record. With TF_PREFILL_KEEP=0 slot 0 keeps no record and no rewind point of a hand-off's rows, and Job.kept and Job.keep keep nothing on a remote prefix. The unplanned cache checkpoint still skips remote streams. The decisions move into qwen27_resume.zig (plain, leftRemote, inherit, rewindAt, Standing.left, Standing.point, Standing.keeps), where host tests pin the hand-off chain, a refused import, each case that keeps nothing (TF_PREFILL_KEEP=0, a cancelled or failed reply, images, prompt logprobs, untaught rows) and a pull that reaches the history end, which makes no rewind point. (ashhart#1594 step 2b)
New host tests (qwen27_handoff_test.zig, "qwen27 hand-off:", run by test-qwen27-reply-cache-host) drive the real lane host with a fake backend over a device-less Metal whose slot 0 choices are qwen27_slots' own: resumeAt as the lane host's resume_peek, opening where slot 0 resumes, rewindPoint and leave. A pulled turn leaves a remote record with its rewind point at the history end; its follow-up pulls nothing, resumes in place where the turn left slot 0 and reports the prefix as kept remote. With TF_PREFILL_KEEP=0 the follow-up pulls again. A pass on slot 0's remote rows makes no unplanned checkpoint, on its own rows it does, and either way it clears a pull it overtook. To reach these host-side, takeStanding inherits the origin once after its switch (here or back), attach's TF_PREFILL_KEEP goes through remote.keepRule (lane host and slot 0 alike), and leave and rewindPoint are pub.
The cache plans a fill's marks without slot 0's in-place resume, so a follow-up that resumes slot 0 (its own rows, or a hand-off's since the last commit) can carry marks below where its pass begins. It never stands at them, yet a request arriving during its pass waited for one until the pass ended, then computed the prefix itself. The prefix wait now skips a leader's marks at or below its stream's cached rows. A request picked in the same admission as the leader, before its first chunk, is not covered: the leader's start is not known yet. Host tests: a request arriving during a fill waits for its cut and resumes it; one arriving during a fill that resumed past the cut does not wait.
…DA export needs compile-qwen35-rounds-host builds zig/tests/qwen35_cuda_main.zig as its own module, with cuda, qwen35, core and lanes only. Since the main imports qwen35_cuda_export.zig, which reads @import("hybrid_state"), that step stopped compiling. It now gets the same hybrid_state module zig/build/cuda.zig gives tf-qwen35-cuda, built for the census target. (ashhart#1594 step 2b)
inherit now takes the plan and leaves a stream's origin alone for .none, so the decision that a pass resumed here or back at the rewind point stands on the record's rows (remote or not) lives in qwen27_resume.zig, not in takeStanding's arms. The .back arm needs rewindSlot, a GPU blit, so no host test reaches it in qwen27_slots.zig; the rule it calls is pinned by the resume tests, whose helper now calls inherit as takeStanding does instead of deciding by itself. (ashhart#1594 step 2b)
…ixture The hand-off fixture's pass now carries opening's rewind point as chunk's saveRewind would, so the follow-up's rewind_at is the code's (turn 1's point carried; a pass resumed in a reply sent back as generated makes none), and it keeps the s.cached opening set over the fake's own fill instead of setting it again from the resumed position, so qwen27_slots.opening's line is what the reported remote prefix reads. Slot 0's hand-off rules (qwen27_resume_remote_test.zig) also run in zig build test on every OS; the Metal fixture's tests stay in test-qwen27-reply-cache-host, macOS only. (ashhart#1594 step 2b)
Adds the host-only record library for the DeepSeek-V4.1 prefill hand-off: the release geometry, the codec between CUDA's fp8 cache records and the neutral bf16/f32 parts, the E2M1/E4M3 FP4 mirrors of the Metal packers, the part plan (what travels, cut into frames of at most 2 MiB) and the CUDA-side export of a snapshot's copies into those parts. Each piece is tested against independent tables or f64 references; `test-dsv41-handoff` runs them on the host. Not included: the Metal packers and importer, protocol 2 adapter, landing sink and stream file, the CUDA export, and any transport.
|
Thank you @BlivionIaG. The record decoders, part plan and carry copies remain consistent with the reviewed slice. The FP4 helpers still change valid record values: an FP8 index block containing 6 and 1.25 packs and unpacks as 6 and 1. Matching the Metal format does not give an exact record round trip. Please keep this record slice lossless, or refuse conversions that cannot preserve the values exactly. These helpers remain outside inference at this head; this is not a claim of a default serving regression.
|
An E2M1 index block holding 6 and 1.25 came back as 6 and 1: the packers wrote codes and never checked what those codes decode to. Each packer now dequantises its own bytes and returns error.NotExact when any value moves, so a record whose values are off the lane's grid is refused instead of rounded. The synthetic world is generated on that grid, so the import, landing and protocol-2 cases still land, and a raw fp8 index row is the refusal they check.
|
Fixed in Red before on One consequence to flag: a CUDA fp8 index row is storable only when its values are on the target's grid, which for real keys is usually not the case, so the hand-off refuses there instead of re-quantising (both lanes store index keys as fp4; the release lane's bf16 window and pool rows are unaffected). Landing real keys would need a target format that holds them, which is outside this PR. |
|
Thank you, @BlivionIaG. The four packers' exact round-trip checks and NotExact refusals close the earlier value-changing conversion finding. The specific 6/1.25 refusal and the raw-row controls are present, and the producer stack includes this fix too. The isolated record slice is ready for exact record/refusal comparison. Real keys may refuse, as you noted; consumer qualification must retain that refusal and avoid publishing partial state. This does not require importing the separate Metal lane.
|
|
I tested the record and part-plan slice independently on zig build test-dsv41-handoff compile-dsv41-handoff-aarch64-linux compile-dsv41-handoff-aarch64-macos -Dfixed-cpu -j2 --summary allAll 33 host tests passed on M5 Max, and the test executables compiled for Linux and macOS ARM64. This also ran the FP4 exact round-trip and Igor Lessio - AIFLOW LABS |
|
Merged |
|
Thanks, @BlivionIaG. The exact round-trip checks and NotExact refusal remain intact, and the refreshed head merges cleanly. The codec finding stays closed. One inherited serving gate remains before the whole stack lands: the automatic checkpoint ID hashes config and index metadata but omits tensor contents, so different loaded weights can pass the same check. Please keep the isolated record comparison separate and bind loaded content before admitting remote state. No format approximation is needed.
|
Main now pins zig/src/native/qwen27_slots.zig. This branch moves slot 0's standing state to qwen27_standing.zig and takes no cache checkpoint for a remote hand-off fill, so the pin takes the merged file's hash and names ashhart#3563.
|
CI on |
# Conflicts: # zig/src/platform/environment.zig
…p environment_test.zig under 600 lines
# Conflicts: # zig/src/platform/environment_test.zig
# Conflicts: # zig/build/qwen27_host.zig # zig/src/core/lane_host.zig # zig/src/core/lane_stream.zig # zig/src/native/metal.zig # zig/src/native/qwen27_served.zig # zig/src/native/qwen27_slots.zig # zig/src/server/chat.zig # zig/src/server/chat_generation.zig # zig/tests/fixtures/gradient-serving.tsv
|
Thank you for the exact packer fix and the refreshed integration. All four packers now compare the restored BF16 bits with the input and refuse a changed row. The 6/1.25 refusal and the raw FP8 controls cover the earlier rounding bug. The isolated record and codec checks can proceed as exact synthetic comparisons. One serving gate remains. The automatic checkpoint ID hashes the config and weight index, but not the tensor bytes. Two checkpoints with the same metadata and different weights can therefore receive the same ID. Please bind the ID to the bytes actually loaded, with a one-byte mismatch control and refusal on hashing or read failure. That change is still needed before the serving stack can land.
|
|
Merged upstream/main (head |
|
Thank you, @BlivionIaG. The exact packer checks and refusal controls remain intact, and the refreshed memory and hand-off paths integrate cleanly with current main. The earlier codec finding stays closed; isolated exact record comparisons can proceed. The inherited serving gate remains: the automatic checkpoint ID hashes config and index metadata, but omits loaded weight bytes. Identical metadata can therefore admit state from different weights. Please bind the identity to the content actually loaded, with a one-byte mismatch control and refusal when that binding cannot be read or verified. The whole serving stack still needs that correction before landing.
|
…t it cannot read or check is refused The name both ends of a hand-off compare hashed config.json and the weight index only, so checkpoints with equal metadata and different weights shared it. checkpoint_identity.handoffName now names the checkpoint by fullIdentity: the config, index, shard names, sizes and headers, and every shard byte, read once and then taken from the file-digest cache until a file changes; a Hugging Face shard is checked against its blob name. A missing shard, a broken header or bytes that do not match refuse the server's start. lane_remote.checkpointId goes; its callers (the Qwen3.8-27B producer and Mac consumer, the import tool) take handoffName.
|
Thank you, @ashhart. You asked for the checkpoint identity to bind the weight bytes actually loaded, with a one-byte What changed ( Evidence: new tests in One limit, stated plainly: the Metal decoder hashes the checkpoint before it loads it, and the CUDA producer hashes after
|
|
Thank you, @BlivionIaG. The exact packer guards remain intact, and the new naming code closes the metadata-only omission by hashing shard contents and refusing unreadable or mismatched files. The loaded-weight binding remains incomplete, as your note acknowledges. Naming reopens the folder separately from model loading; a replacement between those operations can give loaded tensors another checkpoint's name. Please carry the verified identity from the actual loader snapshot into the hand-off, or refuse when that binding cannot be established, with replacement controls at both serving boundaries. The whole serving stack still needs that correction; isolated exact codec comparisons remain useful.
|
|
Thank you, @BlivionIaG. CHANGES REQUESTED at The shard-content hash closes the metadata-only omission, and the four packers still compare restored BF16 bits before accepting a row. One serving defect remains.
Replace one used shard after CUDA loads checkpoint A but before it hashes replacement B: the producer advertises B while exporting state computed with A. Replace A after Metal hashes it but before the load: the consumer loads B but still expects A. Matching manifest strings can therefore admit cross-checkpoint state instead of refusing it. Please carry the verified identity of the tensors actually loaded into every producer and consumer hand-off, or refuse when that binding cannot be established. Add replacement controls for both orderings above, including no publication of a partial or mismatched destination. The current tests edit files before hashing; they do not cover either loader/hash interval. This was a source-only review. I ran no builds, tests, or device checks. |
# Conflicts: # CHANGELOG.md # zig/build/qwen27_host.zig # zig/src/native/qwen27_reply_cache_test.zig # zig/tests/fixtures/gradient-serving.tsv
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
|
Merged upstream/main ( |
Bound stamps config.json, the index and every shard (device, inode, size, mtime, ctime) before the load reads a byte; its name hashes after the load under those stamps (each shard's digest descriptor must equal its stamp) and checks every file before and after the hash. A file replaced or rewritten in between refuses the hand-off. The qwen27 CUDA producer stamps before F.open and names in cuda_produce.open; the Metal consumer stamps in qwen27_served.open before the load and names in remote.attach after it; the import tool stamps before host.open. handoffName, its alias and remote_id are gone.
What this changes
Before, the tree has nothing that converts DeepSeek-V4.1's CUDA prompt state to the neutral hand-off records. After, a host-only library does: the release geometry, the codec between CUDA's fp8 cache records and the neutral bf16/f32 parts, the E2M1/E4M3 FP4 mirrors of the Metal packers, the part plan (what travels, cut into frames of at most 2 MiB) and the CUDA-side export of a snapshot's copies into those parts. Library and host tests only: no server, flag or transport calls it yet. This is slice 1 of the chain in #3553.
5e399316d7, taken as is; that PR has since moved its own head and is not ours to touch). This PR adds4df318cc3c(the change; review only that),0b01d9dcc8(its CHANGELOG line),084a013def(merge ofupstream/main4c79cfe346),08a8930d2a(slot 0's standing state moved out ofqwen27_slots.zig, which main took past the lean cap), and49ddf74366/f2e600d64d(the closed-host test fix below). The diff against main also shows Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b) #2648 until it lands.atc overlap --json(run after the last push,--base upstream/mainat4c79cfe346): 104 files changed, 415 open PRs read (1 clean, 9 conflicting, 405 unknown). Conflicting: qwen27: serve the 27B pair, refuse what a pair cannot keep, and die with the peer #1434 (4 files), Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632 (1), ricursive: the publisher's DFlash2 drafter for Ripple-65B (stacked on #2231) #2260 (1), ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514 (1), ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522 (1), ricursive: speed up Ripple-65B on two GB10s #2523 (1), qwen27 Metal: DSpine drafter for Qwen3.8-27B, opt-in #2634 (2), server: /v1/completions takes echo, the prompt's text and legacy logprobs ahead of an unchanged reply #3526 (1), qwen27 metal: draft SenseNova-Loop-9B with published mtp.safetensors (MTP) #3868 (2). I did not resolve them: they are other PRs' edits to files this PR also touches (CHANGELOG.mdamong them), and atc does not name the file in this output. Coverage is incomplete (complete: false; limits myPullRequestsLimit, otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit, timeLimit).Checks on this head
5df0217b8fpython3 tools/zig/lean_check.py, on the base and on this head: 165 problems onupstream/main4c79cfe346, 165 on this head, 0 new (tools/zig/lean_new.py).tools/pr_check.py --base a3794242c4 --pr 3563: 0 errors, 1 advisory warning, inherited from Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b) #2648 (cli_remote.zig:40names192.0.2.20, a documentation address).qwen27_slots.zigto 599 lines and the merge to 612, past the lean cap.08a8930d2amoves slot 0's standing state (whether a stream resumes there, what it leaves, its rewind point, the remote resume point) intoqwen27_standing.zig, 105 lines;qwen27_slots.zigis 516.submitnow publishes the host's status after the lock.49ddf74366closes the host in the closed-host refusal test throughhalt(the production close) instead of full teardown, so the submit it refuses runs on live lists;f2e600d64dkeeps the test file under 600 lines.-Dcpu=apple_m1 -j4):zig build -Dcpu=apple_m1 -j4: exit 0.zig build test-dsv41-handoff: 32 pass, 0 fail, 0 skip.zig build test-lane-api-host: 812 pass, 0 fail, 0 skip (it runslane_remote_test.zig, which the merge of main broke).zig build test-qwen27-reply-cache-host: 10 pass, 0 fail, 0 skip (it runsqwen27_handoff_test.zig, which calls the moved helpers).zig fmt --check build.zig zigandgit diff --check: clean.47c8f1100e(run 45126929052). The refreshed head reruns them.zig build test test-golden(full suite),dev-tools, any GPU or Metal device run. The failing-before check for the new tests was not done.Receipt
n/a: a host-only library with no caller outside its tests; it cannot reach inference.
Checklist
Update after review
5df0217b8f:zig build test-dsv41-handoff --summary all -j4 -Dcpu=apple_m1: 33 pass, 0 fail, 0 skip (red before onf2e600d64d: 33 pass, 1 fail, the 6-and-1.25 block came back as 6 and 1.0). Lean 123 vs 123, 0 new, 0 new;tools/pr_check.py --base a3794242c4 --pr 3563: 0 errors, 1 advisory inherited from Prefill on a GB10, decode on a Mac: long prompts for Qwen3.8-27B handed over ConnectX (#1594, step 2b) #2648 (cli_remote.zig:40, documentation address). Hosted CI is queued behind the runner backlog.