Repository navigation
Conversation
A DFlashDraftModel config now parses as variant v1: its taps (up to eight), block, mask token and layer kinds come from the config, with no conv or selector keys. Its graph is the plain qwen3 body (eleven tensors a layer, fc, hidden_norm, norm), each layer adding attention and MLP to its residual through a new add operator on the target's residual kernel. With no codebooks (rank 0) the selector's edge term is zero, so trees come from each depth's marginals. The target's tap planes follow the drafter's tap count (eight here), and the keep, gather and glue paths pass that count instead of five. DFlash2 parsing, its schedule and its tests are unchanged.
…nd fusion rows runnerBytes kept five raw planes a prompt row. tapRowBytes now prices a drafter's planes, and for a fusing (v1) drafter the row-major copy, fc's rows and the fused row: 18 x hidden x 2 bytes for the 9B drafter's eight taps. Fit carries it as tap_row; 0 keeps the five-plane figure, so DFlash2 and drafter-less serves plan exactly as before.
…the whole context The target's taps pass now runs the drafter's fc and hidden_norm as a v1 drafter's taps complete (Taps.setFuser), so every gather reads one plane of fused rows: a ring row and a prompt-cache state's drafter part are 8 KiB a token instead of 64 KiB. The drafter's context append starts from those rows (k and v alone). DFlash2 keeps its raw planes. The ring and the context now keep the served span (context plus the lane window) instead of the 4096-token window. Sliding layers attend their own window of it; the full-attention layer attends all of it, with its own cache and attention sized to the span.
The serving line already named a v1 drafter "DFlash", but the startup log line still said "DFlash2 drafts for one of them" for either. Config.kind() gives the name, DFlash for z-lab's v1 layout and DFlash2 for DFlash2, and both lines take it from there. Test: a v1 config is named DFlash and the stock DFlash2 config DFlash2.
… so a v1 drafter's fused ring passes it Main's gather check (the ring's stride against the raw planes, width times count) predates this PR's fused ring: a DFlash v1 drafter keeps one plane of fused rows (Taps.source), so every v1 gather would have been refused. The check now compares the ring's stride with what the gather copies, src.width times src.planes; for DFlash2 and the 27B's own taps that is the raw planes, as on main.
…h has no rotary_dim since 4f12fa0 Main's 4f12fa0 (core metal: drop tf_lane_rope and Attention.rotate, which only lanes_see calls) took rotary_dim and rope out of core.shared_attention.Shape: only the dropped rope kernel read them, and the Qwen27 DFlash drafters rope their rows in their own ops (runtime_callbacks' rope). Main's own window attention dropped the field then; this series' attention_full, the v1 drafter's full-context layers, still named it, which macOS's compile refused (runtime_backend.zig:86). It now passes main's fields; nothing reads a rotary width there.
Every slot took K/V rows for the whole --context on its first use, so four live 9B streams at --context 32768 held 4 GiB of K/V while each stream used a few thousand tokens. With TF_Q27_KV_GROW=<rows> a slot starts at that many rows and, when a round, a restored state or a moved slot needs more, grows to the need rounded up to the step or a quarter more than it holds, at most the context. Growth goes one attention layer at a time: a wider buffer pair, one waited blit of every old byte to its place (each K/V head from h*old*dim to h*new*dim), the old pair out of the residency set and freed, so growing holds at most one layer's old pair beside the new rows. It runs where moveSlot and reset already touch a slot (settleSlot, no pending keep, no failure). The attention kernels already take each stream's head stride from its cache, so the plan now passes the slot's held rows; arithmetic and key order depend only on positions. Unset, every slot holds the context as before, and the startup fit and slot admission still charge the full context.
With TF_Q27_KV_GROW a slot kept its high-water rows after its stream ended, and every parked stream's drafter taps ring was sized to the whole span, so one long request left its rows behind in every slot it touched. Give-back: when a stream leaves slot k, the slot goes back to its first rows (fresh small buffers, no copy) as soon as no blit reads it. The check is a non-blocking status read of the kept-state save, retried at each backend call, so no stream waits on it. Slot 0 keeps its rows while it stands for a next turn's resume; the next fresh pass there gives them back, as does any fresh pass in any slot. Rings: a parked stream's taps ring starts at the same first rows and grows by the K/V rule when taps are absorbed or a kept state is restored or moved into it (Ring.grow, Ring.hold); the old rows move to their places on the CPU after the slot's pending reads land. Drafter frames wait for their ring reads before closing, so a ring only changes between them. A context's reset gives its ring back. The growth helpers move to kv_slots.zig to keep decode_round.zig under 600 lines.
…ROW) With K/V grown as used, a fresh prompt pass gave its slot back to the first rows and then grew it step by step through the prompt: ten growths for a 65,536-token prompt, each a waited blit of every layer into new buffers. The slot is empty at that point, so it now takes the rows the prompt fills (rounded up to the step) in new buffers with no copy, and keeps them when it already holds exactly that many. Decode and restores still grow by the same rule.
…re each byte sits in its lease The rows store's view of a GLM kept state, without the store: the words (format, position, head rows, ring bases, KDA copy bits), the KDA prefix, each DSA layer's latent rows, scales and whole pools by position, its rings and pools in progress as the state's own, the head's caches at a whole verify window (rows past the head's own read as zeros), then the tail. Copies run a page of the lease at a time. Nothing is wired to --learn-conversations yet.
…state on disk Rank 0's engine thread leases, fills, reads and seals each rank's copy through the follow link (cuda_disk_ranks: blank, put, take, seal, prefixes). The store's image is rank 0's image followed by each other rank's prefix, the one part a rank holds alone; the rest are the same bytes on every rank, checked at start by the identity probe. A blank state is refused by restore until its seal. A blank whose disk step fails on the link gives rank 0's lease back, and its id goes on the dropped list, so the next step drops it on any rank the step reached; the id is not used again. An NCCL failure there already ends every rank (the liveness lines), but a CUDA error in the step's launch or upload returns to the disk read, which tries one shorter state and then prefills while the server goes on. cuda_disk_ranks_test.zig runs the steps on host memory with a fake link: that failed blank, a blank state refusing bytes past its words and front until sealed (DiskOrder), each BadStep a follower refuses before its states or the link, and each other rank's shared bytes taken past its prefix and compared to rank 0's (RanksDiffer, in ranks.same, which the probe calls). attach's refusals of the shared store and of more ranks than prefix_buf holds (KvShareWithLearnConversations, TooManyRanks) have their own test in cuda_glm_disk.zig. link and prefix_buf stay process-wide: the process serves one model. With TF_GLM_KV_LIVE_HALF=1 a keep holds one KDA half and the disk image both, so GLM refuses --learn-conversations with it by name at startup (cuda_refusal.zig); the test that pinned GLM refusing --learn-conversations outright now pins that it takes the flag alone and refuses it beside live-half keeps. Rank 0's link becomes the disk steps' link in `follow.Link.lead` (which also sets whether the other ranks begin asleep), at TP only, and `Link.deinit` clears it, so cuda_native.zig stays at its 600 lines. cuda_disk_ranks_test.zig: one rank leaves the steps local, two set the link, another link's deinit leaves it, its own clears it; the test fails with the clear removed.
…sk state into that storage A family whose kept states live in preallocated storage it reuses (GLM's snapshot pages on CUDA) and cannot trim never had a disk read chosen: the selection counted its spare storage as fixed and its kept states as not reclaimable, so no state ever fit. Such a family's room for a read is now its spare storage plus what evicting unborrowed states frees, and a read is ready once the family says its spare storage takes the state, as a keep's admission already asks. Families with trim, or without reused storage, are unchanged.
…t, as before The disk read's early admission for a family whose spare storage takes the state now applies only to a family without trim, as the selection's capacity already does. A family with trim, such as Flash Next's or Qwen3.8-27B's pools on Metal, makes room for a read by trimming its spare storage and evicting, exactly as it did before, and a new test pins that its read stays within the budget when its reuses answers yes.
…he state's rows An index ring based at `base` holds the rows from `base` up to the state's position, and the image keeps at most a ring's rows of each. The seal now checks the words' main base against the state's position and the head's base against its rows, so an image whose words name a ring that starts past them, or too far back to be held, is refused before the blank state is made whole.
…/O worker GLM's store uses The write-behind gave GLM's store its own I/O worker, while the grid test wrote on the test's thread (sync_writes). It now runs on each, drained by write.drain, so a worker path that loses the grid's chunk starts fails the test.
…rn-conversations alone keeps its states Since #1413 CUDA serves --spill-gib and --checkpoint-slots, and --learn-conversations admits GLM, so --learn-conversations --spill-gib (or --checkpoint-slots) opened GLM and ignored the flag: its disk store writes every rank's part between passes and stages nothing at eviction. GLM now refuses both by name. Its store's spill stays off, since an eviction would gather on rank 0 mid-pass while the other ranks wait in the gate's all-reduce. docs/api.md lists every CUDA family that keeps states on disk.
…he shared-store refusal names TF_KV_SHARE - A kept state's device pages are read out with cuda.memory.download, which stages through the pinned buffer on an integrated GPU (#2103, #2289), as every other synchronous readback does; the copy back in stays a direct HtoD. - The refusal beside share_pages names TF_KV_SHARE, the switch behind it since #2211, in its message and comment. - The disk image test's driver answers cuCtxGetDevice and cuDeviceGetAttribute (a discrete card).
…e owner, and a read refuses another by name The image's words gain three: the ranks that wrote it, its layout and the rank that owns its latent rows. Every image is unsplit so far (every rank holds every row): it records this server's world, layout 0 and no owner. A read refuses words of another world (DiskWorld) or another layout, or an owner its layout does not have (DiskLayout), before the blank state is sealed. The words are 72 bytes, the seal step 18 words. #1431's split states fill the layout and owner without another format. A disk read forgets a state's file refused as DiskWorld or DiskLayout after one recall, as it does one refused as DiskWords (rows_read.refused); rows_refusal_test.zig's cases include both.
… attach, so a long state is staged whole cuda_glm_disk.attach opened the store with rows.Rows.open, which keeps the 1 GiB default staging permit and skips the floor rows.attach applies (the longest state's charge, within the RAM store's budget). At about 18.5 KiB a token that stopped every state past roughly 55K tokens: `imprint: saving 124928 tokens skipped (StagingFull)`, whatever --learn-gib said, and a long conversation was recomputed cold after a restart (found by crystal8194 on #1411). attach now goes through rows.attach, as Qwen 3.5 27B does, with `longest` the capacity's whole pools (`image.longest`, the last position `parts` takes; rows.attach falls back to the default when pricing it fails, so the position matters). Spill stays off and the slots unset, as before. The start-up line gains the permit: "a save stages up to N MiB". Tests: - test-cuda-disk-open-host: GLM's own open over a store of 18,944-byte tokens. A 124,928-token state's charge is past the 1 GiB default and within the permit, which is the longest state's charge; with a RAM store too small to keep the state the permit stays the default. It fails with the floor gone (the permit is 1 GiB). It prices the permit a save's stage step asks; it does not write 2.3 GiB. - The GLM set: `longest` is a position the store's parts take at capacities on and off a pool's edge, and the next pool past it is refused.
…n one step, copied into place on the device A restore placed every piece of a block (each layer's rows) through its own follow-link step per other rank: a header broadcast, a payload broadcast, a download and a host copy per page on that rank, while every decoding stream waited on rank 0's engine thread. At TP=3 the shared rows also crossed twice. Now each block's pieces go as one table and one broadcast of their bytes (more only past the link's room), the shared rows once for every rank, and each rank copies its pieces from the link's buffer device to device.
…g the file within 600 lines Main now holds zig/src/native/cuda.zig at 600 lines, and the glm import this branch added took it to 601.
…o, after main's 7948cc4 Main's 7948cc4 launches GLM's CUDA kernels as dependent launches through cuda_pdl (cuLaunchKernelEx), so the follow link's put kernel no longer goes through cuLaunchKernel. The test's fake driver sets cuLaunchKernelEx from the same put handler, through cuda_pdl.forwardEx, as main's own GLM tests do. Nothing else changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #4585 #1896 #1411 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.