[LD][ABI][Docs] Inkling base decode graph emitter (675 ops, arena-validated) + full forward blueprint
- ld::inkling_graph: emit_decode_base() generates the complete base decode forward from the IR over the unrolled physical schedule: embed -> [per-layer: norm -> QKV -> flash -> O-proj -> residual-add -> MLP norm -> router -> experts w13/w2 -> reduce -> residual-add] -> final norm -> unembed. Live-verified on Inkling: 675 ops, 236 arena decls, validated by abi::arena (no overlap / checked bounds / no use-before-write). This is the structurally-complete base; Inkling parity refinements (learned AttnRes block-mix, loop controllers, ShortConv4, relpos, SWA window, paged KV) layer on top next. - abi::vplan: add the Inkling stage opcodes AttnResMix, ShortConv4, LoopCtrl, L2Clip, KvStore, RelPosBias, MoeRouterTopk, VecAdd (30 total, roundtrip). - ld::inkling_ir: LlmComp derives Copy (used by value in the emitter). - docs/inkling-forward-design.md: full per-layer sequence extracted from forward_batch_chunk (k1 AttnRes block-mix + controllers, k2 projections + shortconv + relpos + KV store, k3 flash, O-proj block-boundary rule, k4 sigmoid router + SiTU experts), real scratch buffer set, deep-residual block mechanism (block_size=6 snapshots + learned queries). Verified live: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS; 5 ignored live tests pass (base graph 675 ops); lean proofs (4 files, 42 theorems) green.
This commit is contained in:
1 parent
d478787863
commit
f57060caa7
4 files changed
+200
-2
No files matched your search
@@ -54,4 +54,47 @@ controller gate application point) from `forward_batch_chunk` in
|
||||
`InklingIr` following the k1→k2→k3→k4 stage order. The `memory.vplan` is
|
||||
validated by `abi::arena` (proof `arena_plan.lean`) before any GPU launch.
|
||||
Open detail to resolve from the reference: precise short-conv history
|
||||
buffering (snapshot/rollback for speculative) and the relpos bias indexing.
|
||||
buffering (snapshot/rollback for speculative) and the relpos bias indexing.
|
||||
|
||||
## Full per-layer sequence (extracted from forward_batch_chunk, lines 4553–5160)
|
||||
|
||||
Real scratch buffers: `cur` (residual), `in0/in1/in2` (q/k/v inputs), `mx3`,
|
||||
`msgs` (cross-pass), `q`, `k_raw/v_raw`, `k_cv/v_cv` (post-sconv), `r_raw`,
|
||||
`rbias` (relpos), `sinks`, `gatea`, `k_dyn/v_dyn`, `aout` (attn out), `oproj`,
|
||||
`asc` (attn sconv), `mlpin`, `mlpf16`, `rlog` (router logits), `tk_i/tk_w`
|
||||
(top-k ids/weights), `moeout`, `msc` (mlp sconv), `sc_blocks_[]` (block
|
||||
snapshots), `sc_splitkv_part_`.
|
||||
|
||||
Per physical visit `ip` (logical layer), `is_swa = local_layer_ids.contains(ip)`:
|
||||
|
||||
1. **k1 — AttnRes mix + input norm.** For `ip>0`: mix the block-snapshot
|
||||
pointers `blk_ptrs` with `cur` using query `attn_res.attn_queries[ip-1]`.
|
||||
SWA → fused mix+`attn_norm` → `in0` (k/v share `in0`); full-attn → mix×3 →
|
||||
`mx3` → split into `in0/in1/in2`, then `q/k/v_input_norm`. `ip==0` copies
|
||||
`cur`. If `has_msgs` (looped core passes): run controllers
|
||||
(`controllers.{attn,k,v}`: low-rank down→gain/forget up, `gate_rank`) on
|
||||
the inputs before norm.
|
||||
2. **k2 — projections.** `wq_du`→q, `wk_dv`→k_raw, `wv_dv`→v_raw,
|
||||
`wr_du`→r_raw, `gate_attn`→gatea, `attn_sink_proj`→sinks (all from the
|
||||
normed inputs). Full-attn also `k/v_sconv.weight_proj`→k_dyn/v_dyn.
|
||||
ShortConv4 on k_raw/v_raw (static `k_sconv`/`v_sconv` + dyn) → k_cv/v_cv.
|
||||
Q/R L2-clip (`q_l2_clip`/`rel_l2_clip`), KV paged store, relpos bias
|
||||
(`rel_logits_proj.proj` → rbias).
|
||||
3. **k3 — flash attention.** `flash_swa_gqa`(q, gatea, rbias, sinks, KV pool)
|
||||
→ aout. Decode = split-KV 2-stage; prefill = WMMA. SWA window vs global.
|
||||
4. **O-proj + block boundary.** `wo_ud`(aout)→oproj; post-attn ShortConv
|
||||
(`attn_sconv`). **AttnRes block rule:** if `ip % block_size == 0` snapshot
|
||||
`cur` into `sc_blocks_[n_blocks]` (push to `blk_ptrs`), then `cur = asc`;
|
||||
else `cur += sconv(oproj)`.
|
||||
5. **MoE sublayer.** AttnRes mix (`blk_ptrs` + `cur` + `mlp_queries[ip]`) +
|
||||
`mlp_norm` → mlpin (+ `controllers.mlp` if has_msgs). Router:
|
||||
`gate.weight`(mlpin)→rlog, `k4_moe_router_topk`(rlog + `gate.bias`,
|
||||
route_scale)→tk_i/tk_w (top-8/128, sigmoid). Experts: w13 (SiTU activation,
|
||||
`situ_beta/situ_lb`)→act, w2→y_part, reduce(tk_w)→moeout. NVFP4 path
|
||||
`*_sf4mx8`. Then mlp ShortConv + residual update.
|
||||
|
||||
The attention-residual **block mix** (`k1_attn_res_mix`, learned queries over
|
||||
block snapshots) is Inkling's deep-residual mechanism — the residual stream
|
||||
is a learned mixture of block outputs, not a plain add. The graph emitter
|
||||
must reproduce the block-snapshot cadence (`block_size=6`) and the query
|
||||
weights. Controllers gate the looped-core passes (`has_msgs`).
|
||||
Reference in new issue
Block a user