Module deepseek_v41_layer

Module deepseek_v41_layer 

Source
Expand description

DeepSeek-V4.1 Flash: one transformer block on the generic model.

The generic TransformerModel owns the embedding, the FP32 mHC highway (BufferArena::hc_streams, [T, hc, H]), the final norm and the LM head; each layer here does everything in between, in the reference’s order (deepseek_v41_ref::model::forward, 39/39 against DeepSeek’s golden):

layer 0 only:        hc_expand(embedding -> streams)
engram layers only:  streams += engram(token n-grams)          (EngramV41)
attention:           (pre_a, post_a, comb_a) = hc_mixes(streams, attn site)
                     x = rmsnorm(collapse(streams, pre_prev))   <- DELAYED pre
                     streams = hc_post(attn(x), streams, post_a, comb_a)
ffn:                 (pre_f, post_f, comb_f) = hc_mixes(streams, ffn site)
                     x = rmsnorm(collapse(streams, pre_a))
                     streams = hc_post(moe(x), streams, post_f, comb_f)
                     pre_prev = pre_f
last layer only:     hidden = collapse(streams, pre_prev)      (no learned head)

pre_prev starts as the one-hot on stream 0 (the reference’s initial pre-mix) and travels with the sequence through V41Runtime. So do the shared attention slots, the engram hasher and the expert cache: V4.1’s attention is shared ACROSS layers (four kv sources write, forty read), which no per-layer state can express, so one runtime object is shared by all forty layers through an Arc and guarded by mutexes. One sequence at a time; multi-sequence decode and the MODEL-level CUDA graph are declined through the layer hooks. The layer captures its own single-token step instead (ATLAS_DS41_GRAPH=1, see GraphMode): the host work in the middle of every layer (the routing download and the expert fetch; on the twelve kv/index source layers also the compressor group and the index top-k) splits the step into graph segments with the host spans between.

Routed experts never sit in HBM: the cache is a page-locked, device-visible arena the GPU reads in place (ExpertLru + ExpertSliceMap), filled by pread from the seven shards; the engram tables are read by row (EngramRowReader).

Structs§

DeepSeekV41Layer
SegState
V41LayerState
V41Runtime
Everything the forty layers share for the ONE sequence in flight.

Enums§

GraphMode
How the single-token step runs. ATLAS_DS41_GRAPH_ORACLE=1 runs every layer BOTH ways and compares the highway bit for bit; ATLAS_DS41_GRAPH=1 replays the captured segments; anything else is the eager step. Read once.

Functions§

graph_mode
step_graph_on
ATLAS_DS41_STEP_GRAPH=1, read once.