Skip to content

attention + tokenizer + sampling: the path to real text (milestone 6) #6

Description

@rhCat

Milestone: attention + tokenizer + sampling — the path to real text (issue #6)

The structure is proven (issues #1/#2/#5): 0.19 s/token, real router +
mxfp4 expert chain, 39x faster, at the read floor. But the engine
computes only the MoE path — no attention, no tokenizer, no logits.
This milestone is what "host it" actually requires.

What the checkpoint gives us (already in the layouts)

Piece Tensors Status
Attention (MLA) q_norm/kv_norm (BF16), wq_a/wq_b, wkv, wo_a/wo_b/wo_c (F8+scales), attn_sink in trunk, never executed
Embedding + head embed.weight, head.weight (~1010 MB each, F8-ish, tied) unclassified, not loaded
Tokenizer tok.h vendored (BPE, cl100k/o200k, kimi family) exists, unwired
KV cache none must be built

Work items

  1. F8_E4M3 matvec kernel — the engine has mxfp4/bf16/f32 but no F8
    path; attention tensors are F8 with per-group scales (wkv.scale
    [4,32], wo_a.scale [64,32], ...). LUT-decode + scale, SIMD like the
    mxfp4 kernel, bit-identical decode gate (same discipline as SIMD kernels: break the compute wall (milestone 3) #5).
  2. MLA attention step: q = norm(x) x wq_a x wq_b; kv = x x wkv;
    causal scores + attn_sink anchoring (V4's million-token trick);
    softmax; output = softmax x v through wo_a->wo_b->wo_c; residual.
    KV cache in RAM (kv latent ~512 -> ~4 KB/token -> 4 GB @ 1M tokens;
    fits the box).
  3. Tokenizer + sampling: tokenize prompt, detokenize output;
    logits = head x state; top-k/temperature sampling. The head is the
    single biggest matvec (~246k x 4096 = 2 GFLOP/token) — resident,
    threaded across rows; NOT streamed from disk.
  4. Autoregressive loop: token -> head -> sample -> embed -> layers
    -> next. The existing state chain becomes the real token loop.
  5. Memory gate: KV accounting (roadmap item, now load-bearing).
  6. Acceptance: fixture determinism (two runs, identical dumps) +
    acer first tokens. Output is real text-shaped tokens; QUALITY is
    explicitly NOT the gate — that needs the hyper-connections.

The fidelity gap (step 2, quality)

The real V4 bounds/mixes layers through hc_* hyper-connections
(hc_attn_fn/hc_ffn_fn, 1.5 MB each) which the skeleton does not
implement; the RMS rescale is the stand-in. First text will be
structurally correct but semantically weak until hc wiring lands. That
is a separate sub-milestone: hc_attn_fn/hc_ffn_fn are small MLPs --
wire them as the layer mixer and replace the RMS stand-in.

Expected cost on the acer

  • +attention: ~2.5 GFLOP/token (F8, threaded) -> ~0.2-0.4 s/token
  • +head: ~2 GFLOP/token -> ~0.1-0.2 s/token (threaded, resident)
  • Total decode ~0.5-0.8 s/token -> ~1.5-2 tok/s single stream.
    That is the honest "hosted" number for one user on this box.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions