- ld::inkling_plan: physical_schedule() unrolls the looped core (verified against the reference logical->physical mapping; Inkling = 6 + 3x12 + 6 = 48 physical steps over 24 logical layers). scratch_layout()/scratch_plan() lay out the decode activation arenas (residual/q/k/v/attn_out/moe/logits), 4 KiB-aligned with checked offsets, validated by abi::arena. - ld::inkling_graph: GraphBuilder accumulates arena decls (scratch=0, weights=1, inputs=2) + a flat op sequence and validates the whole plan (no overlap, checked bounds, no use-before-write) via abi::arena. emit_trunk() emits the first complete sub-graph: embed(+embed_norm fused) -> final norm -> unembed, arena-validated. The per-layer k1->k4 body plugs into the same builder next. - abi::vplan: add GemmBf16 opcode (BF16 trunk/unembed GEMM). - docs/inkling-forward-design.md: forward blueprint grounded in the strata reference (k1->k4 stage order from kernel numbering, real scratch buffer set, loop structure, two forward paths main-LLM + MTP DSpark). Verified live: RUSTFLAGS="-D warnings" cargo test --workspace = 96/96 PASS; 4 ignored live tests pass; lean proofs (4 files, 42 theorems) green.
3.2 KiB
Inkling forward-pass design (grounded in the strata reference)
Status: design foundation for the graph.vplan generator (M1).
Reference: ../strata-safetensors/engine/src/inkling2/hip/ink_hip_ops.hip.h
(kernel families), ink_hip_backend.hip.cpp (forward_batch_chunk dispatch),
ink_hip_tree.hip.h (MTP beam-tree). Config: ld::inkling::InklingConfig.
Two forward paths
- Main LLM — 24 layers, looped MoE, hybrid SWA + relative attention.
This is the decode critical path and the first
graph.vplantarget. - MTP / DSpark draft — separate
mtp.safetensorsshard, 3 non-causal block-8 layers (standard attention + SwiGLU) + Markov head (rank 256) + beam-tree verification (ink_hip_tree.hip.h). Simpler; lands after the main path.target_layer_ids [5,23,41,48]tap the main model.
Per-layer stage order (verified from kernel stage numbering)
The reference kernels are numbered k1_..k4_ — the numbering IS the
per-layer forward order:
| Stage | Reference kernel(s) | Role | Our opcode |
|---|---|---|---|
| k1 | k1_attn_res_mix_norm_fused |
attention-residual mix + norm | rms_norm (+residual) |
| k2 | k2_shortconv4_* |
short conv (kernel 4) on q/k/v/attn/mlp | (new shortconv4) |
| k2 | k2_qrkv_norm_clip_fused |
q/k/v proj + input-norm + L2 clip | gemm_* + rms_norm |
| k2 | k2_qrkv_kvstore_relpos_fused |
KV store + relative position | rope_kv_write (+rel) |
| k3 | k3_flash_swa_gqa / _splitkv / _prefill_wmma |
SWA flash attention (decode/prefill) | flash_gqa_wmma |
| k3 | k_relpos_bias_proj |
relative-position bias (full-attn layers) | (rel attn variant) |
| k4 | k4_moe_router_topk |
MoE routing top-8 of 128 | moe_route_bucket |
| k4 | expert GEMM + k_scatter_add_expert |
NVFP4 experts w13/w2 + reduce | moe_w13_wmma/moe_w2_wmma/moe_reduce |
| — | k_embed_lookup / k_unembed_softcap |
trunk embed / unembed (softcap 30) | embed_bf16 / gpu_penalties_topk |
Notes:
- SWA layers (20 of 24) use
attn_norm; full-attention layers {5,11,17,23} useq/k/v_input_norm+ relative bias (verified on the live inventory). - Controllers (
gain/forget/down× attn/k/v/mlp) gate the looped passes. - Trunk:
embed → embed_norm → [layers] → norm → unembed(softcap).
Loop structure (from config)
loop_config {core_start 6, core_end 18, num_passes 3, gate_rank 64}: the
core layers [6,18) run 3 passes; middle_cycle_cross_pass_queries /
..._kv_queries carry state across passes; attn_res.attn_queries[0..22] /
mlp_queries[0..23] / output_query are the attention-residual block
queries (n_layers_per_attn_res_block = 6). The graph encodes this as
loop_layer over the core body ×3 with the cross-pass query buffers.
Next brick (executable graph)
Extract the exact operand wiring (buffer offsets, fusion boundaries, the
controller gate application point) from forward_batch_chunk in
ink_hip_backend.hip.cpp, then emit graph.vplan + memory.vplan from
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.