Expand description
2026-09-25: DeepSeek-V4.1 Flash tiny-graph reference: the V4.1 graph on the
CPU, checked against ds41_tiny_golden.json.
Nothing here runs on a GPU. The GPU attention (attn_v41) uses its RoPE
tables, window indices and top-k selections, and model::forward is the
oracle the GPU tests compare against.
§Where the truth comes from
ds41_tiny_golden.json is produced by gen_ds41_tiny_golden.py (beside
it), which runs DeepSeek’s inference/model.py (the revision the golden’s
fixture.reference records) on a tiny synthetic model: hc_mult=4
hyper-connections with delayed mixes, engram on two layers with the
reference’s hash (engram.py), shared compressed attention with two kv
sources, three index sources and a candidate prefilter whose consumers
share its ratio, sqrt-softplus routing with a correction bias,
route_scale, the swiglu clamp and a shared expert. The tilelang kernels
the reference imports are replaced by ds41_ref_shims.py (pure torch).
§Determinism, and why only outputs are committed
Weights and inputs are RNG-free and order-free: fixed_value(name, i, scale, offset) here reproduces the generator’s filler (fnv1a64 salt,
splitmix64, 24-bit uniform, f64 arithmetic, f32 result, bf16 RNE where the
parameter is stored bf16). So the golden carries only outputs: each
capture as {shape, n, stride, ck, data} where data is a prime-strided
sample and ck is the fp64 index-weighted checksum over the whole tensor.
tests.rs checks the regeneration against the golden.
§The engram hash parameters come from the GGUF
Measured 2026-09-15 with gen_ds41_engram_hash_check.py: the token map,
bucket primes, slot offsets and hash multipliers that engram.py
computes from the V4.1 tokenizer equal the deepseek41.engram.* metadata
of the Q2_K GGUF, so the loader builds the engram tables from that
metadata alone (EngramHashTables::from_flat).
Owner: model-arch, DeepSeek-V4.1 reference. Invariants: none beyond the types.
Modules§
- attn
- 2026-09-25: DeepSeek-V4.1 attention for ratio-0 layers (the reference’s
Attention.forwardatcompress_ratio == 0), CPU reference against the golden: low-rank Q with RMSNorm, one latent KV row per token (wkv+kv_norm), RoPE on the lastrope_dimof both, the KV row rounded through fp8 in place (block 32, power-of-two scale), a sliding-window ring cache,sparse_attnwith the attention sink, the inverse rotation on the output, then the grouped low-rank output projection (wo_aper group, thenwo_b). Also the RoPE, window and fp8 helpers the compressed layers andattn_v41share. - compress
- 2026-09-25: DeepSeek-V4.1 compressed attention (
compress_ratio > 0), CPU reference against the golden: YaRN RoPE withcompress_rope_theta, the two fp4 quantisers,linear_f32, andattention_any, the attention forward for any ratio. The compressor and the indexer are in thecompressorandindexersubmodules; the ratio-0 pieces are shared withattn.rs. - engram
- 2026-09-25: DeepSeek-V4.1 engram, CPU reference, checked stage by stage against the golden:
- hc
- 2026-09-25: DeepSeek-V4.1 block scaffold: hyper-connections (
hc_mixeswith the Sinkhorn split,hc_pre,hc_post) and RMSNorm, CPU reference against the golden. - model
- 2026-09-25: DeepSeek-V4.1 full tiny-graph model: the config, weights, state
and trace types that
forward(inmodel/forward.rs) fills. On the fixture: embed, expand tohc_multcopies, the one-hot initial pre-mix, engram before layers 1 and 4, six blocks with the delayed mixes, collapse, final RMSNorm, f32 logits. The per-layer caches and the shared slots carry across prefill and decode, so the golden’s captures for every layer and the logits are checkable. - moe
- 2026-09-25: DeepSeek-V4.1 MoE (the reference’s
Gate,Expert,MoE), CPU reference against the golden: sqrt-softplus routing with a correction bias that picks experts but does not scale them, top-k renormalisation,route_scale, the SwiGLU clamp, and one shared expert every token goes through.
Structs§
- Golden
- Golden
Tensor - 2026-09-25: One committed capture.
- Weight
Meta - 2026-09-25: One parameter’s regeneration rule, from
weights_meta.
Constants§
- GOLDEN_
JSON - 2026-09-25: The tracked golden, produced by
gen_ds41_tiny_golden.py.
Functions§
- assert_
close - 2026-09-25: Elementwise max-abs comparison that names the worst index and both values.
- checksum
- 2026-09-25: fp64 index-weighted checksum
sum(v[i] * (i + 1)), the generator’sck. Summed sequentially here and by a torch reduction there, so callers compare with a relative tolerance. - fixed_
int - 2026-09-25: The generator’s integer filler (
fixed_ints):fixed_raw % modulus. - fixed_
raw - 2026-09-25: Raw stream value for element
iof the tensor namedname. - fixed_
value - 2026-09-25: The generator’s filler:
u = (z >> 40) / 2^24,f32((2u - 1) * scale + offset)in f64. - fnv1a64
- 2026-09-25: FNV-1a 64 over the UTF-8 bytes of
s; the per-tensor salt. - regen_
param - 2026-09-25: Regenerate an f32-kind parameter (bf16- or f32-stored) as the
generator initialised it: the rule (scale, offset) and the storage dtype
come from
weights_meta. Panics on another kind; the fp8 tables are regenerated byengram::regen_table. - splitmix64
- 2026-09-25: The splitmix64 finaliser of
gen_ds41_tiny_golden.py::splitmix64. - to_
bf16_ rne - 2026-09-25: Round an f32 to bf16 precision, round-to-nearest-even; NaN passes through.