Expand description
2026-09-25: DeepSeek-V4.1 Flash engram on the GPU: n-gram hash, row gather,
wkv projection and gate.
Owner: model-arch (DeepSeek-V4.1 engram). Invariants:
rows_from_q2k,rows_from_bf16andapplyrefuse more rows or tokens than themax_tokensworkspace before any copy or launch.hcis in1..=4(EngramV41::new).
Engram runs before each layer in engram_layer_ids. Per token it hashes the
n-gram window of compressed token ids into n_hash_cols row ids of a
per-layer table, gathers those rows, projects their concatenation through
wkv into one key per hyper-connection stream plus one shared value, and
adds gate * value to each stream:
- Hash (
EngramHasher): integer-exact, on the CPU, from the tables in the GGUF metadata. - Rows: the tables are Q2_K, one
ENGRAM_ROW_BYTESblock per 256-wide row, read by id throughEngramRowReader(metrale_model_weights) and dequantised on the device bydequant_q2_k_to_bf16into the[tokens * cols, head_dim]bf16 input (EngramV41::rows_from_q2k). - Projection:
[tokens, cols * head_dim]xwkv^T->[tokens, dim * (hc + 1)], a GEMM for several tokens and a GEMV for one. - Gate (
engram_v41_gate,kernels/gb10/deepseek-v4-flash/nvfp4/engram_v41.cu): normalised dot of stream against key, signed-sqrt sigmoid,h += gate * value, in place on the FP32 highway[T, hc, H].
engram_v41_tests.rs checks the hash exactly against the CPU reference in
crate::deepseek_v41_ref::engram, and (on a GPU) the projection and gate
against the golden captures and the device dequant against the CPU decoder.
Structs§
- Engram
Hash Tables - 2026-09-25: The hash tables, in the shapes the CPU reference’s
EngramTablesuses. - Engram
Hasher - 2026-09-25: The n-gram hash for one sequence. It keeps the compressed id of every position, so decode steps see the prefill’s look-back.
- Engram
Layer Weights - 2026-09-25: One engram layer’s resident weights on the device.
- Engram
V41 - 2026-09-25: The GPU side: kernels, per-layer weights, and workspaces for up
to
max_tokenspositions per call.
Constants§
- ENGRAM_
ROW_ BYTES - 2026-09-25: Bytes of one Q2_K super-block, which is one engram row.