Repository navigation
deepseek_v41: load and serve DeepSeek-V4.1-Flash-1017 on four DGX Sparks - #399
Conversation
…am hash ids (CPU only) - New model type deepseek_v41 (model_type or DeepseekV41ForCausalLM): unwraps text_config, shares V4's parse body, and reads the shared-cache fields (kv/index source layers, candidate blocks, Engram, DSpark). - Refuses configs whose sharing would read a wrong cache: a compressing layer with no earlier source of the same ratio, DSpark stages with compressed attention, a candidate source that runs no indexer. - ModelConfig::kv_source_layer / index_source_layer say which compressed cache and top-k each layer reads. - DeepseekV41Engram: bucket primes, offsets, numpy default_rng multipliers (SeedSequence + PCG64 + Lemire) and per-position row ids with sequence-start and image-span breaks. validate() requires the prime buckets to tile the config's engram_num_embeddings exactly. - Pinned to the published 1017 config.json (test_data/). Row-id goldens come from a transcription of the reference NgramHashState, not from running it; cross-check on hardware. No GPU code; nothing loads or serves the model yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… check (CPU only) - preflight::deepseek_v41::manifest names every tensor a checkpoint must hold, with its safetensors dtype and shape, from the config alone: DeepSeek's release (FP8 with 32x32 UE8M0 block scales, MXFP4 routed experts, FP8 Engram tables), NVIDIA's NVFP4 pack, and the EXL3 packs (trellis-coded linears, no Engram tables). - check_headers holds a checkpoint's headers against it and names the first missing, changed and unexpected tensors. - Pinned by count and SHA-256 of the sorted header lines of the published checkpoints: release 96,085 tensors, NVFP4 188,245, EXL3 2.5bpw 192,496. - The vision tower's shapes come in as an argument: ModelConfig does not parse vision_config. Nothing calls the check at load yet; no loader for these weights exists. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… at serve start - tokenizer::engram_dsv41::compress_vocab ports build_compressed_token_map of the checkpoint's inference/engram.py: tokens that normalize alike share an id, ids in first-seen order. - resolve() maps the pad token through it and returns the hash geometry. A tokenizer that does not compress to engram_compressed_vocab_size is refused at serve start, as the reference asserts: every hash multiplier derives from that size, so a map one entry off rehashes both tables without any error. - On the published 1017 tokenizer: 129,280 ids to 99,092, and the map's SHA-256 equals the reference's (ignored test, needs ATLAS_DSV41_TOKENIZER=<tokenizer.json>). The map is built and checked, then dropped; nothing looks up Engram rows yet. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rser V4.1-Flash-1017 ships encoding/encoding.py, V4's encoding with differences. The V4 encoder takes a Dialect instead of growing a copy. - DSML tag names carry a leading space (<|DSML| calls>, " invoke", " parameter"). The tool parser reads and writes both spellings; a block closes in the spelling that opened it. New tool-call parser deepseek_v41, the default for the model type. - Reasoning effort is a number from 1 to 100 (low 50, high 75, max 100). - <|System|> opens the system block. A system message past the start opens a turn like a user message. - Tools may be namespaced (namespace::name) at the tool, the function or in the name itself; conflicts are refused. - Image blocks become <|deepseek_image|>; text may not spell it. - Tool-call arguments encoded twice are decoded; non-objects are wrapped. - A user message holding only tool results does not start a turn. Byte-exact against DeepSeek's five fixture pairs and eight further cases encoded by the same encoding.py (revision 1bae0e10). Atlas's own choices, not DeepSeek's: developer messages render as system messages; minimal/medium/none map to 50 and xhigh to 100; request-level tools with no system message open an empty system block. V4 fix: a transcript with no user message kept none of its reasoning, where V4's encoding_dsv4.py keeps all of it (its last-user index is -1). Co-Authored-By: Claude Fable 5.2 <[email protected]>
…MXFP8 tiers kernels/gb10/deepseek-v4.1-flash resolves model_type deepseek_v41 at hidden size 5120. It compiles deepseek-v4-flash's kernel tree (kernel_source) and adds one overlay file that includes glm-5.3-flash's mxfp8_gemv.cu. The 1017 release stores each FP8 projection as E4M3 [n, k] with one UE8M0 scale per 32 x 32 block. The MXFP8 GEMV tiers read a scale per row and 32 columns, so fp8_block_scales_to_rows repeats each scale row for the weight rows it covers and no new kernel is needed. V4's own FP8 kernels assume 128 x 128 blocks with f32 scales and would compute wrong values here. Checked on a GB10 (ignored GPU test `block32`): parity with the BF16 GEMV and row invariance at nine V4.1 shapes and on eleven of the release's own projections. The target compiles there: 216 kernels. No loader or factory arm yet, so a deepseek_v41 checkpoint is still refused and --check-kernels has not run. [expected_absent] is left to be harvested from that first run. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…te does DeepSeek's chat_template.jinja (repository revision 08c8657f) maps minimal and low to 50, medium, high, xhigh and none to 75, and max to 100. This encoder had medium and none at 50 and xhigh at 100. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…reference The rules for what V4.1's attention caches hold, on the host (layers/deepseek_v41/cache_recipe.rs): the two rotary ladders, FP8 window keys, FP4 index keys and compressed keys, the 128-slot ring and when a compression group completes. The compressed-key rule reproduces rows of DeepSeek's own cache bit for bit (test_data/deepseek_v41). Kernels in the deepseek-v4.1-flash overlay: - dsv41_cache.cu: rotation and the three quantize-then-dequantize rules. Byte-identical to the host rules on a GB10. - dsv41_attn.cu: attention over up to 128 window keys and 512 selected keys with a per-head sink. A query's bytes depend only on its own q and its keys in order, so a decode step and the same position in a prefill chunk agree. The softmax is exact in FP32. Replaying layers 0 to 2 of the reference recording on a GB10 (ignored GPU test, ATLAS_DSV41_REC): 1.1e-3 to 1.7e-3 from the reference, which rounds its weights to BF16, and 99.98% of output bits equal to softmax in f64. Not wired into a layer yet. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… by op The reference quantizes an activation to FP8 before every FP8 GEMM. `fp8_linear` does the same and multiplies on the MXFP8 tiers, so a projection's output differs from the reference's only by summation order. Ignored GPU tests replay single operations of DeepSeek's code on the release's weights, each from its recorded input to its recorded output (recording made with record.py --ops, ATLAS_DSV41_REC): - eleven FP8 projections of the attention, the indexer, the shared expert and Engram: 99.989% to 99.999% of BF16 values equal; - six RMS norms: equal to within a handful of values; - q after rotation and the FP8 window key: the window key is bit-identical on all three layers; - the grouped wo_a projection after the inverse rotation and FP8 step: 99.98% equal. The FP8 quantizer now reads one buffer and writes another, so an activation is left as it was. Co-Authored-By: Claude Fable 5.2 <[email protected]>
V4.1 collapses a sublayer's input with the `pre` the site before it computed, not its own as DeepSeek-V4 does: attention with the previous block's FFN site, the FFN with this block's attention site, the head with the last FFN site, and layer 0's attention with (1, 0, 0, 0). Its stream is BF16 between sublayers and its Sinkhorn ends on a column pass divided by (sum + eps). dsv41_hc.cu is that as three kernels: mix, collapse, expand. Replaying both sites of layers 0 to 2 from DeepSeek's recorded streams on the release's weights (ignored GPU test): coefficients within 2.3e-5, collapsed vectors equal, expanded streams 99.99% of BF16 values equal. The recording these tests read was remade with TF32 matrix products off. NVIDIA's PyTorch container turns them on, which put 3e-4 of error into the reference's FP32 products; the compressed-key fixture is regenerated from the new recording. The shared test helpers moved to test_support.rs. Co-Authored-By: Claude Fable 5.2 <[email protected]>
dsv41_moe.cu states the reference's MoE with its rounding points: the router scores the unquantized activation in FP32 (softplus as PyTorch computes it, then a square root), picks the top six of score + bias and weights them by score; each expert reads an FP8 activation, rounds its gate and up projections to BF16, applies SiLU with the gate capped at 10 and up clamped to +-10, multiplies by its routing weight, rounds, quantizes to FP8 and projects down; the outputs are summed in FP32 in expert order with the shared expert, which keeps its FP8 weights. One thread per output row: this is the form the tensor-core paths will be held to, not the form that serves. On the release's weights (ignored GPU tests): 200 of 200 tokens on each of layers 0 to 2 choose the same six experts in the same order as DeepSeek's code, with weights within 3.4e-6; the MoE output is bit-identical on layer 0 and 99.998% equal on layer 2. Co-Authored-By: Claude Fable 5.2 <[email protected]>
dsv41_side.cu holds the two paths the reference runs in FP32: - the compressor of a layer that produces compressed keys at ratio > 1: key and gate projections of the attention input kept in FP32, each group of `ratio` tokens pooled by a per-value softmax of the gate, rounded to BF16; - Engram's gated add of an n-gram lookup into every copy of the stream. On the release's weights (ignored GPU tests): layer 2's compressor projections are 1.3e-6 from DeepSeek's and 99.95% of pooled values are equal; layer 1's Engram output is 99.995% equal. With this every operation of a block has a plain kernel that replays the reference, except the indexer's scoring and top-k. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rence's schedule A block built from the plain kernels (layers/deepseek_v41/block*.rs): both Hyper-Connection sites with `pre` carried between them, the attention with its window ring and, on compressing layers, the compressor and the compressed keys a source layer hands to the layers after it, then the MoE. One sequence's cache on one layer is SeqState; weights are found by the 1017 release's names with nothing requantized (weights.rs). The attention kernel now follows the reference kernel's schedule: keys 64 at a time in the order of the index row, a running maximum, and the weights that multiply the keys rounded to BF16. The exact FP32 softmax it replaces was 1.3e-3 from the reference, and the block quantizes the attention's output to FP8 before projecting it, which turned that into 1e-2 at the sublayer's output. On the schedule 99.86% to 99.97% of the attention's values equal the reference's. Decode and prefill build the index row the same way (cache_recipe::window_row), so they give the kernel the same keys in the same places. Layers 0 to 2 token by token on the release's weights, each token starting from DeepSeek's recorded stream (ignored GPU test): the attention sublayer is 1.1e-3 to 1.9e-3 from the reference, which is BF16 rounding steps on one value in ten, and the rest of the block is 98.9% to 99.7% equal. Layer 2's compressed keys differ from the reference's in 2 values of 51,200; because a key is FP4 and every later token reads it, the test hands later tokens the reference's key once a group has been compared. Not built: the indexer (a query may see at most index_topk compressed groups), a compressor at ratio 1, Engram in the block, more than one rank, and the TransformerLayer and loader that would serve it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…eference does Past 512 compressed positions a query reads only the best 512, chosen by a small side attention on the index-source layers. This builds it in plain form and wires it into the block. - dsv41_index.cu scores every visible position for one query: BF16(sum over heads of BF16(relu(BF16(q_h . key)) * w_h)). Query heads and index keys are FP4 values, so each dot product is exact and has one value whatever the order; the sum over heads is left in FP32 so ranks holding some of the heads can add their parts before the one rounding. - index_recipe.rs holds the choice, on the host: the top-k in position order with equal scores at the cut going to the earliest positions, and the candidate blocks of the two-level top-k. Scores are BF16, so ties at the cut are the usual case (three queries in four on the recorded prompt), and the reference always keeps the earliest. - A key-source layer writes each completed group's index key next to its compressed key, from the key before its rotation. An index source publishes the positions it chose for the layers after it, and the candidate source its candidates (state.rs, block_index.rs). Against DeepSeek's reference on layer 2 of the recorded prompt, on a Spark (ignored GPU tests): - on the reference's own queries, weights and keys, all 490,700 prefill scores are bit-identical, and so are the decode steps that score an even number of keys; - the attention sublayer token by token over all 1,449 tokens, from its recorded input: 375 of 376 prefill queries that choose pick exactly the reference's 512 (the other shares 510), with 1 index-key value of 92,672 differing and 99.91% of scores equal; - decode steps with an odd number of keys share 507 or more of 512. There the reference's own scores carry its library's rounding (cuBLAS takes a BF16 path on an odd dimension), and the reference's two runs of the same positions share 499 to 508. - the sublayer's output is 2.4e-3 from the reference in prefill and 3.2e-3 on decode steps with an even number of keys; on the odd ones, where the positions read differ, it is 2.2e-2. The host rules are unit-tested on a fixture written by the reference's own top-k and select_candidate_blocks lines on six recorded score rows. Not built: scoring on the GPU end to end (scores come back to the host for the choice), the candidate source on real weights (layer 20 is the first, and no recorded layer runs it), a compressor at ratio 1, Engram in the block, more than one rank, and the TransformerLayer and loader. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…tion replayed From layer 20 every token is its own compression group: no gate and no pooling, the key projection rounded to BF16 is the key. CompressorWeights' gate is now optional and the compressor takes that path at ratio 1. The attention test runs any layer from a full-depth recording of DeepSeek's reference (all 40 blocks, run one at a time on one Spark; its layers 0 to 2 are bit-identical to the three-layer recording). Over the 1,449 recorded tokens, each from its recorded input: - layer 20, the first at ratio 1 and the candidate source: 75 of 741,888 compressed-key values and 39 of 185,472 index-key values differ from the reference's; 885 of 889 prefill queries that choose pick exactly its 512, the least sharing 509; - layer 24, an index source that scores layer 20's index keys inside its candidates: 884 of 889 exact, the least sharing 506; - layer 3, which reads the keys layer 2 made and the positions it chose: output 2.3e-3 from the reference in prefill and 2.5e-3 on the decode steps where layer 2's own output is 2.2e-2 off. So that gap is the positions read, not the attention. - sublayer output in prefill: 2.3e-3 to 4.3e-3 from the reference on all four layers. Test support reads either recording: one set of files for three layers, or a set per layer; the final collapse is checked after the last recorded block (layer 39 at full depth: every value equal). The test loader can leave out the routed experts, which an attention test does not read. Not built: Engram in the block, more than one rank, the TransformerLayer and loader. The candidate rule is still only exercised with every position a candidate: 2,048 blocks of 8 hold 16,384 positions and the recorded prompt has 1,449. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The block test now runs all recorded layers, each with the role the release's config gives it: key source or reader, index source or reader, ratio 2 or 1, candidate source or reader. A layer that reads keys or chosen positions is handed DeepSeek's. The roles and the handing-down are in the test support, which the attention test now uses too. All 40 blocks on 200 tokens each from the full-depth recording, on a Spark: - attention sublayer 1.1e-3 to 7.5e-3 from the reference, the furthest at layers 20, 21 and 35; - the rest of the block 98.1% to 99.8% of stream values equal, at most 4e-4 away, the carried mix within 3.6e-4; - compressed keys and index keys at the key sources: none differ at layers 8 and 14, 3 of 102,400 and 4 of 25,600 at layer 20. On layers 20, 21 and 35 the attention kernel from recorded operands gives 99.91% to 99.94% of the reference's values and wo_a 99.98%, as on the first layers (the per-operation tests now run them at full depth). The larger sublayer figure there is the same few rounding steps, carried through the FP8 step and the output projection. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The two Engram layers (before blocks 1 and 14) in plain form: the rows a token's hash ids name are turned from the table's FP8 into the values the reference looks up (dsv41_engram_rows), projected to a key per copy of the stream and one value, and the value is added through the gate that was already there. Engram::apply takes the rows as the table stores them; finding them in the 101 GB table is the caller's. From recorded hash ids on the release's table and weights, 64 tokens on each layer (ignored GPU test): the looked-up values are bit-identical, the projection 99.99% equal, and the stream it leaves 99.98% (layer 1) and 99.997% (layer 14) equal to the reference's. Not built: the hash ids and the table read wired to this (the ids exist in spark-server, the row cache in spark-storage), more than one rank, the TransformerLayer and loader. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…llel on several The blocks become the engine's layers and the release loads as published. - layers/deepseek_v41/layer.rs: a block as a TransformerLayer, one token at a time. The four-copy stream lives in the arena's Hyper-Connection buffers, one row per token of the pass, with the carried mix beside it; the first layer fills a row from the embedding and the last collapses it for the final norm and head. Engram reads the token's rows before blocks 1 and 14. - engram_table.rs: the 101 GB Engram tables stay on disk; a token's 24 rows are hashed on the host, faulted into a pinned row cache and read in place. The loaders now leave `.engram.embed.` tensors on disk. - weight_loader/deepseek_v41.rs and the factory arm. Attention runs whole on every rank; more than one Spark is expert-parallel. - The MoE over ranks is exact: each chosen expert's output goes in its own slot, the slots are summed across ranks (one rank's value plus zeros), and every rank adds the six in the order one rank would. - A sequence's compressed keys grow with it, and the layers charge them to the KV budget; the paged pool, which nothing reads, is given the narrowest key. - The Engram token map comes from the tokenizer, so the server derives it before the model is built. `rope_theta` of window-only layers is carried as `window_rope_theta`. - ATLAS_DSV41_DEBUG_LAYERS=<n> keeps the first n layers, so a cut of the model fits one Spark; it computes what the reference built with n_layers = n computes. Measured on Sparks: - a three-layer cut on one Spark, against DeepSeek's reference run on the engine's own tokens: 43 of 48 generated tokens are the reference's first choice. The cut's output is near-random text, and the head's logits are BF16 here where the reference's are FP32; - the same cut expert-parallel on two Sparks: tokens and log-probabilities identical to one Spark; - all 40 layers on four Sparks: loads and reports ready. Not built: FP32 logits, snapshots of the layers' state for the prefix cache, the draft stages, vision, and every fast path. The kernels are the plain ones. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…d a stage profiler Where a token's time went on the plain kernels, per layer (ATLAS_DSV41_PROFILE=1, an eight-layer cut on one Spark): 13.7 ms, of which the routed experts 9.95 and the routing 1.87. - dsv41_fp4_tc.cu: a routed expert's FP4 projection on tensor cores, in the layout of mxfp8_gemv_tc. FP4 nibbles become BF16 times their E8M0 scale, exactly, and the sum is FP32 as before. On real experts it gives 100.0000% of the plain kernel's values; the MoE against the reference is unchanged (layer 0 every value, layer 2 99.995%). The experts take 0.87 ms, which is the weights' 106 MB at about 120 GB/s. ATLAS_DSV41_PLAIN_FP4=1 goes back. - Routing as two launches with a block per (expert, token): a thread adds 20 products where the plain kernel's added 5,120, each a global load. 0.06 ms. It chooses as the plain routing does on every recorded token, and the weights are within 4e-7 of the reference's. A layer now takes 2.9 ms a token there: 4.7x less. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…d a quarter each The fastest published engines for this model split every large weight over the Sparks, not the experts between them. This does that with an arithmetic that does not depend on how many Sparks there are. Each wide projection is cut in four parts (parts.rs): its output rows where rows are independent (an expert's w1 and w3, the query heads, the output groups), its input columns where it sums over them (an expert's w2, wo_b). A column part's sum is an FP32 partial, and the four partials are added in part order and rounded once (dsv41_parts.cu). A rank holds 4 / world consecutive parts: one Spark computes all four, four Sparks one each and gather the partials (RDMA gather where the ring offers it, NCCL's otherwise). The kernels, their operands and the order of the sum are the same either way. - dsv41_tc.cu (was dsv41_fp4_tc.cu): the tensor-core projection for FP4 and FP8 weights, with entries that leave the FP32 sum unrounded. - A rank loads only its parts of the routed experts, straight from disk into one allocation per layer and part (the server marks the model expert-sliced, and the fast loader now leaves `.scale` tensors on disk with their weights). wo_b and the shared expert's w2 are sliced on the device and the whole freed. - The expert-parallel path of the previous commit is gone: experts are no longer whole on one rank. All 33 tests pass, and the 40-layer sweep reads as before (attention within 7.5e-3 of the reference, the rest of each block 98.1% of values equal). Also measured, with the kernels of the previous commit on four Sparks: - the engine is deterministic run to run, and the RDMA ring gives the tokens NCCL sockets give; - against the reference's prefill over 1,400 positions, the engine agrees on the first choice 97.3% of the time and the log-probability of the prompt's next token differs by 0.078 on average (median 0.003). Two runs of the reference itself, one with 47 more tokens in the batch, agree 98.4% and differ by 0.074 (median 0.003). The engine is at the model's own rounding noise. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… them One token at a time, the block was bound by how its work was launched, not by the arithmetic: about 65 launches a layer, several of them a single block, which is a single SM. Decode on four Sparks goes from 9.6 to 21 tokens a second with the bytes of every step unchanged where the step kept its summation order, and at the reference's own rounding noise overall. - Hyper-Connections (dsv41_hc.cu): a thread owns one value index of a token in all its copies and a block is 256 of them, so a token uses 20 SMs where it used one. The mix leaves each block's share of its sums in a small scratch and one block adds them in block order. A whole site (the sublayer before it into the stream, the mix, the collapse, the sublayer's norm and its FP8 form) is two launches, `hc::site`, held to the bytes of the plain kernels by a test; it was seven. The block's last expansion reads the MoE's parts directly. - Experts (dsv41_expert.cu): the six chosen experts and the shared one are three launches a part, where they were 35: every projection in is a row of one grid, the activations one block, every projection out a row of another. The router leaves the chosen in expert order on the device, so nothing is read back to the host. Held to the bytes of one launch at a time by a test. The tensor-core body moved to dsv41_tc.cuh so both files instantiate it. - dsv41_sparse_attn: a thread a key, 640 threads a head, in place of 256 threads looping over keys. Same sums in the same order. - dsv41_gemv_f32 (the compressor's and the indexer's BF16 projections): a block a row, adding in a tree, where a thread added a row's 5,120 products one after another and took a millisecond. The same products in another order. - dsv41_common.cuh states once the arithmetic several kernels share (FP8 and FP4 rounding, the four-part sum, SwiGLU, the tree dot product). - No host round trips in a block: positions come from a table on the device, the keys a query reads are uploaded in stream order, and the carried `pre` is written where the next block reads it. 42 tests pass. The 40-layer sweep reads as before (attention within 7.5e-3 of the reference, the rest of each block at least 98.0% of values equal). On four Sparks the engine agrees with the reference's prefill on the first choice at 98.0% of 1,400 positions and the log-probability of the prompt's next token differs by 0.073 on average (median 0.003); two runs of the reference itself agree at 98.4% and differ by 0.074. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…hare a rank Two costs that sat outside the block: Engram at 6.2 ms a token and the LM head at about 4. Decode on four Sparks goes from 21 to 27 tokens a second, and the tokens generated do not change with either. Engram: - Its projection (25,600 x 6,144, 157 MB) is in four column parts like every wide one. A part reads a quarter of a token's 24 table rows, so a rank fetches 6 rows where it fetched 24, projects a quarter of the weights, and the ranks gather the partial sums. - Three quarters of the 6.2 ms was the table: rows fetched from disk on the thread that launches kernels, from a drive that had gone idle since the token before. The first layer now starts the fetch for every Engram layer as soon as the token is known, on a background thread (`Prefetcher`), so the rows are in memory when layers 1 and 14 ask; and the table keeps its drive awake while tokens arrive (`NgramRowCache::start_keepalive`). - The slots a lookup reads are uploaded in stream order, with no wait for the lookup before. Head (model/head_shares.rs): the BF16 head is 1.3 GB and every rank projected all of it for every token. A rank now projects its share of the vocabulary through a pointer offset into the resident head, and the ranks gather the shares into the logits row. `dense_gemv_bf16` computes a column from its weight row alone, so the row is the same bytes; the 300 tokens of the check are the ones the unsplit head gives. Taken only by deepseek_v41, whose ranks all end a token with the same hidden row. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… front is one launch Decode on four Sparks goes from 28.4-29.5 to 30.0-31.1 tokens a second at a short context, and the tokens do not change: every kernel here leaves the bytes of the launches it stands for, and a test holds it to them. - Attention (dsv41_attn.cu). Every head of a query reads the same keys, and with a block a head each head read all of them twice: 16 heads over 640 keys is 21 MB a token and layer. `ops::sparse_attn` is now three launches in which the heads share the reads: a block of 16 keys by 16 heads for the logits, the schedule a head, and a block of 16 output values by 16 heads. A thread adds what the old form's thread added, in its order. At 640 keys it takes 72 us where it took 190. The rotations of the query and of the output happen inside. The block-a-head form stays as `sparse_attn_plain`, the statement the other is tested against. - The attention's front (dsv41_front.cu): the two norms, the turn of the window key and its FP8 rounding were five launches of a block each, and are one. wq_a and wkv are one launch (`dsv41_fp8_gemv_two`), and wo_a's groups one (`dsv41_fp8_gemv_groups_q`). - The projections can round their input to FP8 on the way in (`F4_QUANT` in dsv41_tc.cuh), which drops the launches and buffers that did it for wq_b, wo_a, wo_b and the Engram. Measured on cold weights it costs what the launch cost; it is here for the launches it removes. - The projection tests run the kernels the block runs, and the MXFP8 tier kernels are no longer used by this model. Tried and not kept, measured on four Sparks: the experts' activation inside their projection out (17.5 ms a token against 9.8: every block redoes it), a layout with a warp owning 16 rows over all of K for the tall projections (slower than eight warps sharing K), and the keys staged in shared memory for the attention (slower: these kernels are bound by instructions issued, not by waiting on memory). Measured for what comes next, each kernel alone on an idle GPU with cold weights: the projections stream at 150 to 180 GB/s where memory gives about 235, because decoding FP4 and FP8 weights to BF16 in software is most of their instructions. The native block-scaled FP8 MMA is the way out. All layer tests pass, with the 40-layer sweep as before. Against the reference's prefill over 1,400 positions the engine agrees on the first choice at 98.2% and the log-probability of the prompt's next token differs by 0.075 on average (median 0.004); two runs of the reference agree at 98.4% and differ by 0.074. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ous copies A projection's block loaded its weights as it used them, one chunk ahead, and waited on memory for each load. Timed alone on weights no cache held, the loads were 13.3 of an expert projection's 14.1 us: the arithmetic was never the cost. `dsv41_gemv_staged_impl` (dsv41_tc.cuh) has a block copy its 16 rows into shared memory with `cp.async`, 512 K values of every row at a time and three stages in flight, its scales whole and first, and multiply from there. The sums and their order are the direct form's, so the bytes are; the tests that held the fused kernels to one launch at a time now hold the staged form to the direct one. Which projections stage, measured cold on GB10 for each shape: - the experts, both ways (K = 5,120 in, 576 out): 240 us a layer and part to 179, which is 197 GB/s where memory gives about 235; - wo_a (K = 4,096): 60 us to 44; wq_a and wkv (K = 5,120); - wq_b (K = 1,280) and wo_b (K = 2,048) stay direct: staged they are level or slower, for staging costs a block a barrier a stage and 27 KB of shared memory, and these are many blocks of short rows. Decode on four Sparks, 300 tokens after a 64-token prompt, with the stage profiler on: 28.6 to 30.4 tokens a second, the experts from 10.0 to 7.5 ms a token, and the same tokens. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The second launch of a Hyper-Connection site did its three jobs one after another in one block: the norm, the FP8 rounding of the normed vector with a thread walking each block of 32 values, and then, on one warp, the coefficients with their twenty Sinkhorn rounds, a chain nothing shortens. Timed alone the site took 35 us, most of it that chain waiting its turn. `dsv41_hc_site_finish` is now two blocks: the coefficients run on the second, beside the norm. And a thread rounds the two values it has just normed, the 32 values of a scale block being the pairs of 16 neighbouring lanes, which find the block's largest by shuffles: no second pass, no barrier. The same arithmetic; the test that holds a site to the plain kernels' bytes passes. A site takes 27 us. Decode on four Sparks without the profiler, 300 tokens after a 64-token prompt: 33.3 to 34.7 tokens a second (30.0 to 31.1 before this and the staged projections), 25.1 after a 1,401-token prompt, and the same tokens. Tried and not kept: the mix's weights transposed so a thread reads six wide words a value (no change: the site was not waiting on those reads), and the Sinkhorn rounds in registers with shuffles (41 us against 27). Co-Authored-By: Claude Fable 5.2 <[email protected]>
`dsv41_engram_gate` looped over the stream's four copies inside one block, each copy's three sums and their tree after the last. A copy's gate reads nothing of the others, so each copy now has its own block and they run side by side. The same sums in the same order: the Engram tests read as before, and so do the 300 tokens of the decode check. Engram's kernels take 0.97 ms a token on four Sparks where they took 1.14. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The block took one token. It now takes up to 32 consecutive rows of a sequence (`Block::forward_rows`), and `Layer::prefill` sends a chunk through it in turns of 32 where the default sent it a row at a time. A row's bytes are those of a decode step: the kernels compute a row from that row alone. - The site, the expansion and the attention's front take a row of the grid a token; the projections take the rows of a batch eight to a launch (`parts::project_rows`), which their tiles always could; the attention already took many queries. The experts are still a launch set a row. - Scratch buffers are `[rows, ..]`, and those of the four parts `[PARTS, rows, ..]`, so a rank's part is one run for the gather. - A batch of more than one row reads the window unrolled into position order with its own keys after it (`unroll_window`), since in the ring a row's key would displace one an earlier row of the batch still reads. On four Sparks a 1,401-token prompt reaches its first token in 24 to 25 s where it took 46.5 (57 tokens a second against 30), and the log-probability of every one of its 1,401 positions is bit for bit what the row-at-a-time path gave. Decode is unchanged: 33 tokens a second and the same tokens. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A batch ran its experts a row at a time: six experts' weights read a row, which was two fifths of a prefill's time. A batch is now up to 512 rows, and the host sorts its (row, slot) pairs by expert and cuts each expert's run into tiles of up to eight (`moe_grouped.rs`). Three launches take every tile (`dsv41_experts_in` / `_act` / `_out`): a tile's rows read their activations and leave their outputs wherever they sit in the batch, through the row indices the projection kernel now takes (`a_rows`, `c_rows` in dsv41_tc.cuh). At 512 rows an expert has eight rows on average, so its weights are read once where they were read eight times. The shared expert runs every row through its one set of weights. A row's bytes are still a decode step's: on four Sparks the log-probability of each of a 1,401-token prompt's positions is bit for bit what it was, and the prompt reaches its first token in 13.4 s where the last commit took 24 to 25 (104 tokens a second against 57). What a prefill spends now, of 15.6 s with the stage profiler on: 6.7 s choosing compressed keys a row at a time on the host, 3.1 s on Engram a row at a time, 1.9 s in attention, 1.4 s in gathers, 1.2 s in the experts. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A batch of prefill rows still took the compressor, the indexer and the Engram a row at a time, each with a wait for the device and a read back: 43% and 20% of a 1,401-token prefill. The compressor projects every row of the batch in one launch, pools the groups the batch completes, and carries the tokens of a group it leaves open. The indexer scores the queries that have to choose in one launch and one read back. An Engram layer takes 64 tokens a lookup: one resolve of their table rows, one projection, one gather. A row's bytes are unchanged: the scores of the 1,401-token prompt and a 300-token reply are identical to the row-at-a-time path's. Prefill of that prompt on four ranks goes from 13.4 s to 6.7 s. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…inputs The projections that sum over a split input (wo_b, an expert's w2) were cut by input columns: a rank computed an FP32 partial of the whole output and the ranks gathered the partials, 143 KB a token and layer for the experts and 20 KB for the attention. A prefill cannot carry that. They are now cut by output rows like the others. The ranks gather what the projection reads, which is small (a quarter of the low-rank attention output, a quarter of every expert's hidden activation), a rank computes a quarter of the output from all of it, and the ranks gather the quarters: 17 KB a token and layer in all. A projection reads a gathered input in the pieces the parts left (f4_at), so nothing is copied together. An expert's output is now one sum over its 2,304 hidden values where it was four partials added, so bytes change within the reference's own noise: on the 1,401-token prompt the engine agrees with the reference on 97.86% of positions (98.21% before, the reference's own floor 98.36%). The block's MoE is held to a launch a projection, byte for byte. Prefill of that prompt on four ranks goes from 6.7 s to 6.1 s. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The four-rank all-to-all went in ops of equal shares of every plane's rows. Rows with no divisor near the count the bytes need got an op for every few: a rank's 3,902 rows of a prefill batch (2 x 1,951) went in 1,951 ops of two rows where six carry them, 45 ms a collective and 2.8 s of a 32,000-token prefill at 16,384 rows a batch. Any batch whose share of rows is twice a large prime met it. Equal shares are kept while they take no more than twice the fewest ops the bytes need. Past that, planes of one row count are cut in runs as long as fit, of whole rows and whole 128-byte segments, the last run shorter (`chain/a2a_split.rs`, unit-tested). Where neither serves the call declines as before, with nothing queued. Four Sparks, 32,000-token DeepSeek-V4.1 prefill: at 8,192 rows a batch 4.97 s (6,430 tok/s) as before; at 16,384 rows a batch 6.65 s -> 4.82 s (6,640 tok/s). The same 64 tokens after a 32,000-token and a 9,000-token prompt at both. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… reads A batch's attention wrote its heads' output as BF16 (134 MB a rank at 8,192 rows), and the output projection then rounded each group of eight heads to E4M3 codes before its GEMM: two passes over those bytes a layer. `dsv41_attn_batch_tc` now rounds what it has in its registers. A head's 32 values are with four lanes of a warp, so a block's scale is two shuffles away, and the lanes write the codes and the scale, tiled, where the GEMM reads them (`ops::Coded`). The values rounded are the BF16 values the launch would have written, so the operand is `dsv41_mx_quant` of them (GPU test, eight groups of 64 rows, codes and scales). A few queries, and batches without the GEMMs, are written as values as before. `Block::codes_home` moves to `block_out.rs`. Four Sparks, 32,000-token prefill: 4.97 s -> 4.86 s at 8,192 rows a batch, 4.82 s -> 4.70 s (6,805 tok/s) at 16,384. The same 64 tokens after a 32,000-token and a 9,000-token prompt. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Two kernels on a decode step's chain had a thread do several slow operations one after another, where the block had threads to spare. A division is about 80 ns on this GPU, and a thread's instructions do not overlap. The Hyper-Connection coefficients' Sinkhorn rounds gave a lane a row and then a column of the 4 x 4 matrix: four divisions a lane in each of forty passes, most of a 20 us launch that a decode step makes eighty times. A lane now owns one entry: it adds its row's (or column's) entries in their order and divides its own. The experts' activation gave a thread a block of 32 values: 32 SwiGLUs and 32 roundings in turn. A thread now takes one value, a warp is the block, and the block's scale is five shuffles away (`dsv41_fp8_block_lane`). Every sum, quotient and rounding is the one it was. Four Sparks, the same tokens: a plain decode step 21.8 -> 21.14 ms (45.8 -> 47.4 tok/s), a six-row verify step 46.1 -> 45.2 ms; a 32,000-token prefill is unchanged (4.70 s at 16,384 rows a batch). Co-Authored-By: Claude Fable 5.2 <[email protected]>
The batch attention kernel is bound by its warps at work: with a step's keys staged whole and one block a multiprocessor it took twice as long. It ran two blocks a multiprocessor because a block's shared memory was 39 KB, 16 KB of it a warp's 64 values of the 16 keys it adds to the output. A warp now stages those a quarter at a time, 16 values of each key, in the memory of the step's logits, which are done with by then. A block's shared memory is 22.7 KB and its threads fit 64 registers with a few spills, so four blocks share a multiprocessor. A tile's sum is the one it was: the tensor-core byte-identity tests pass, and a 32,000-token and a 9,000-token prompt continue with the same 64 tokens. Four Sparks, 32,000-token prefill: 4.70 s -> 4.50 s (6,810 -> 7,115 tok/s) at 16,384 rows a batch, 4.86 s -> 4.66 s at 8,192. Three blocks (halves of 32 values, 80 registers) gave 4.60 s. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Four blocks left a thread 64 registers, and the launch kept what did not fit in memory and read it back inside its loops. Three blocks leave 85. The output's operands come by the matrix-load instruction where a lane assembled each from eight 2-byte reads; the bits are the same. Timed alone, 16 heads of 16,384 queries over 640 keys: 17.1 ms with three blocks, 21.2 with four, 17.8 with two. A 32,000-token prefill on four Sparks at 16,384 rows: 4.35 s (7,350 tok/s) where it took 4.50. The tokens after a 32,000-token and a 9,000-token prompt are unchanged, and the batch still leaves the bytes of the few-query kernels. Measured on the way, none of it kept: every multiply made twice costs nothing, the schedule costs nothing, half the launch is the output's reads of the keys; a warp reading a key once for all sixteen heads in the logits was slower, and reading the four quarters' pieces ahead changed nothing. The matrix loads alone, at four blocks, were neutral. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A greedy step asks its logits for their argmax and nothing else. Where the draft head is served, every rank already holds an FP8 copy of its quarter of the head, so a rank now reads that copy (half the bytes), bounds how far each token's coarse logit can lie from the head's own (head_bound.rs), and runs the head's own arithmetic only for the tokens the copy cannot rule out (dsv41_head.cu). The pick is the token argmax_bf16 finds in the row the head in shares would have left. The step leaves no logits, and marks the rows so. The argmax of a marked row is its token; whoever reads a marked row's bytes (sampling, logprobs, a penalty, a masked pick) first has the whole head run on that step's rows, and the ranks go back to the head in shares for a number of steps that doubles each time (model/head_pick.rs). The ranks agree on picking or not with a new command word before the next command the head starts. On by default with the draft head; ATLAS_DSV41_HEAD_PICK=0 turns it off and ATLAS_DSV41_HEAD_PICK_CHECK=1 runs the head beside every pick. Both are in the startup parity table. Four DGX Sparks, greedy chat, one run each: plain decode 48.9 -> 50.4 tok/s (20.45 -> 19.84 ms a step); drafted prose / Python / JSON 56.4 / 100.2 / 93.7 -> 57.5 / 102.4 / 95.8, inside run-to-run noise. Same text in every run. Check mode: 3,845 rows on each of four ranks, every pick the head's argmax. On one GPU with the release's head, all 1,449 recorded hidden rows pick the head's argmax; tokens kept: median 7 of 129,280. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A thread a token read 32 rows a load, a value each. A warp now takes 32 tokens one after another and a lane eight values of each row, so a row is one load of whole cache lines and the row before's values stay in registers. A round alone: 98 us to 18.5 us with the release's head, the same token chosen. The gain's sum order changes, which only drafts see. The kernel takes a rank that is a multiple of 8; the loader now refuses any other. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A block scored its rows one after another and read the gate once for each. It now reads a gate value once and adds its product with each of up to three rows, the rows' sums through one tree side by side. The scores are the same bits: the test holds a digest of a row's scores from the old kernel. Alone with the pick behind it, us for 1 / 3 / 6 rows: 27 / 37 / 44 before, 26 / 31 / 35 now. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A verify whose drafts were refused launched a restore in each of forty layers between the verify and the draft pass, with nothing else on the GPU. The rollback now only records what was taken back, and the layer's next attention launches the restore ahead of anything that reads or writes the ring. Co-Authored-By: Claude Fable 5.2 <[email protected]>
`launchs` and `familys` in two test names fail the typos check. Names only; nothing a build runs changes. Co-Authored-By: Claude Fable 5.2 <[email protected]>
ad35226 to
e7b5d31
Compare
Brings the branch up to main (76 commits: Inkling 2 Mini Atlas-Inf#401/Atlas-Inf#404/Atlas-Inf#410, Atlas-Inf#332 and the rest). Nine conflicts, each two additions in the same place, resolved as unions: the config parser imports and the dispatch list, kv_only_prefix_cache_is_safe (deepseek_v41 and inkling2_loop both false), the factory loaders and its supported-model list, the aux-state model list, the PDL module doc, the tokenizer modules, tool_call_ids_in_template (main's matches! for Inkling, this branch's `!= ChatEncoding::Jinja`, since ChatEncoding is now Jinja | Deepseek(dialect)), and tool_defaults.toml. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Brought up to
🤖 Generated with Claude Code |
|
@data-angel I ran the part of this I can run without four Sparks: does it change anything for the models already here? sparky job 192, one GB10. I merged One conflict, in
So the shared changes (PDL lists, graph capture, buffer sizing, tool-parser streaming, the tokenizer load) leave these two GB10 models' output identical. I have not checked DeepSeek-V4.1 itself, which needs the four-Spark ring. Its correctness rests on your receipts. If you want the 89-commit stack split for review, as you offered, that would make the shared-code part easier to sign off. With this merge as it stands, I'd take it after #397/#411 settle. sparky nightq 192 · merge 🤖 Generated with Claude Code |
|
Merged Verified locally: Fine to let #397 and #411 settle first — if you'd prefer the small shared-code pieces ( |
|
@data-angel Re-gated
On the Flash-Next C8 line: that model isn't batch-invariant at C8 (C1 vs C8 is 2/8 on CI: the workspace tests, clippy, fmt, nvcc and the 500-line cap pass. Docs (rustdoc) is red with four private-item links: Yes to the split you offered. Please peel the shared-code pieces into their own PR ahead of the rest: sparky nightq 217 / 217z · 🤖 Generated with Claude Code |
|
@data-angel I pushed This merges third, after #411 and #397. It conflicts with #411 in five files (config re-exports, dispatch imports, the factory loader list and its "Supported" string, 🤖 Generated with Claude Code |
…pseek_v41 Conflicts in five files, each two additions in the same place (Ling-3.2-air from Atlas-Inf#411, DeepSeek-V4.1 here): config.rs and config/dispatch.rs parser imports, the factory loader list and its Supported string, model_type_ships_vanilla_norm_weights, and supports_chunked_mla_impl (DeepSeek-V4.1's early return kept ahead of Atlas-Inf#411's Ling/GLM expression). Both sides kept everywhere.
|
@data-angel Merging as the third PR of today's chain, after #411 and #397. Merge of
Its tree ( Gate (sparky job 219, one GB10). This again covers only what a single GB10 can show: whether the shared changes move existing models. The chain's top vs
Code review of what I can't run (DeepSeek-V4.1 itself needs the four-Spark ring). No blockers.
The model's correctness on the ring rests on your receipts in the PR body. Please post a four-Spark greedy / ST-995 run on sparky nightq 219 · 🤖 Generated with Claude Code |
Summary
Adds a
deepseek_v41model family and agb10/deepseek-v4.1-flashkernel target: Atlas loadsdeepseek-ai/DeepSeek-V4.1-Flash-1017as published and serves it on four DGX Sparks joined in an RDMA ring, with prefill in batches and decode through the release's own draft head with an exact verify.It is one long series (89 commits, 203 files, about 28,000 lines) because the model shares almost nothing with the families already here. Nearly all of it is new files under
layers/deepseek_v41/and the new kernel directory; the changes to shared code are listed below. I am happy to split it into a stack if that is easier to review: the commits are in the order the work landed and each builds on the last.What is in it
About 60 of the 203 files are shared code. The larger touches:
atlas-core: config fields and dispatch for the new family.spark-model: the factory, the model's entry points for prefill, verify and the head, the MXFP8 weight map, and the startup-parity table.spark-runtime: theATLAS_DSV41_PDLswitch, and the arena does not size other families' scratch for this model.spark-comm: an all-to-all is cut in runs where its rows do not divide.spark-server: tokenizer, tool-parser and topology entries.Measured
All on four DGX Sparks in a ring, the release as published, one stream, greedy, through SparkSeek's
start.sh.At commit
fb3b99b68(the head but for one commit that renames two tests), three runs each, with raw files and checksums (receipt):The reply rates are the engine's own
Done:lines. With drafts, a step kept 1.78 tokens on the prose prompt, 4.10 to 4.13 on the Python one and 3.52 to 3.60 on the JSON one, so these are three prompt classes and not one headline. With drafts off the draft head is not loaded and a greedy step runs the whole head.An earlier receipt at
8c71b62eeof this series, one run of each reply: prefill 4.87 to 5.45 s at 8,192 rows, prose 53.0, Python 95.9, JSON 86.5 tok/s, drafts off 45.7 to 46.6. The two receipts are side by side, not a controlled comparison.Correctness
#[ignore]: they need a GB10 and the checkpoint or the recordings.What it does not do
Test plan
On this branch merged with
mainat269b533bc(a clean merge), in a Rust 1.93.1 container with CI's GPU stubs:cargo fmt --all -- --checkandcargo clippy --workspace --tests -- -D warningsare clean.scripts/check_spdx.py,scripts/check_kernel_shadows.py,typosand the 500-line file cap pass.cargo test --workspace --locked --no-fail-fast: 8,761 passed, 13 failed, 335 ignored. All 13 are in files this branch leaves identical tomain:/tmpdoes not have (spark-storagengram_pack×6,model_download::free_bytes×2);bench_selfstart,bench_variants×2);atlas-plugin's agentic harness reap child processes (a_detached_survivor_in_the_sandbox_is_reaped,a_timed_out_command_takes_the_children_it_forked_with_it); I have not diagnosed these.scripts/check_env_budget.pyfails, as it does onmain: see the note below.-- --ignored) were run on a GB10 as the series was built, and serving was checked on four Sparks. They were not re-run on the merge withmain.Notes for reviewers
ATLAS_DSV41_*names, and the ratchet is already over onmain. Four are read only by tests (CKPT,REC,HEADERS,TOKENIZER) and one cuts the model to its first layers for debugging (DEBUG_LAYERS). Three are what a deployment sets (ROWS,DRAFT,PDL). The rest are fallbacks and probes kept from the bring-up (NO_GEMM,NO_OWNED_ROWS,NO_TAIL,PLAIN_FP4,MOE_SPAN,EXPERT_GEMM_ROWS,DRAFT_FLOOR,PROFILE,HEAD_PICK,HEAD_PICK_CHECK). Tell me which you want gone, or moved toMODEL.tomlor flags, and I will do it in this PR.ATLAS_DSV41_PDL, which a deployment sets.🤖 Generated with Claude Code