Reference comparison (strata-inkling --serve ground truth) exposed a systematic
precision bug: vetta truncated f32->bf16 (>>16) while the reference f32_to_bf16
rounds to nearest even (0x7FFF + ((u>>16)&1)). Truncation bias accumulates over
the 48-visit loop and drifts the residual stream.
- k_cast_f32_bf16: round-to-nearest-even (was truncation).
- k_ctrl_pack: packed cur/msg bf16 now round-to-nearest-even.
- k_shortconv4_decode / k_shortconv4_dyn_decode: history ring rounded through
bf16 between steps (exact strata "Round through BF16 between steps"), via a
new bf16_round device helper.
- CPU oracles updated to match (packer bf16_trunc, hip f32_to_bf16 + the
shortconv/controller test history shifts).
Effect on the full forward (single token 100, reference argmax 68014):
argmax moved 100 -> 8 and logit[68014] rose 8.6 -> 11.1 (toward the reference),
confirming the rounding fix is real and directional. Generation from "The
capital of France is" (prompt ids verified identical to the reference) now
produces structured text but the argmax still diverges from the reference
" Paris" — further precision/composition parity is in progress (reference uses
fp16 KV cache + fp16 expert input; candidate next mismatches).
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
GPU 17/17 (--features hip, --ignored) green with the rounded oracles;
lean proofs (5 files) green.
- k_shortconv4_dyn_decode / vetta_shortconv4_dyn_decode: exact strata
k2_shortconv4 dyn semantics for the full-attention layers — y = x0 +
sw0*h0+sw1*h1+sw2*h2+sw3*x0, then y += dt0*x0+dt1*h2+dt2*h1+dt3*h0, scaled
by 1/3 (vs 1/sqrt(5) for the static SWA variant). dyn_taps [M,n_heads,4],
head = c/(C/n_heads); static_w [C,4]; history ring shifted in place.
- Multi-step parity test: 5-token recurrence vs CPU oracle, per-step match
(<1e-5) AND device history ring == host history ring (exact). The dynamic
short-conv (driven by k/v_sconv.weight_proj taps) evolves correctly.
This is the last shortconv variant needed for the full-attn layers {5,11,17,23}
(3-query mix split + separate q/k/v norms + dyn shortconv + tau + global attn).
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (5 files incl. inkling_loop) green; GPU 16/16 (--features hip).
- k_softcap / vetta_softcap: logits = cap*tanh(x/cap), the final logit
softcapping (Inkling cap=30). Parity vs CPU 9.7e-8; bounds |logits| <= cap.
- ld::layer::final_logits: the CORRECT final output path extracted from the
reference — the final norm is itself an AttnRes depth mix over the block
snapshots + cur with the learned output_query, then norm + unembed + softcap:
h_norm = norm(attn_res_mix(blocks, cur, output_query))
logits = softcap(unembed(h_norm), 30)
(The earlier unembed_logits used a plain rms_norm(cur), missing the final
depth mix; final_logits fixes that.)
- multi_layer_prelude_forward now uses final_logits: argmax token 128538
(logit 19.16, bounded by 30). The token shifts vs the plain-norm path,
confirming the final output mix materially affects the result.
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU softcap + multi-layer final PASS
(--features hip, --ignored).
- k_l2_clip / vetta_l2_clip: exact strata Q/R/K per-head L2 clip — v = x*scale
(scale nullable), fac = min(1, clip/(sqrt(sum v^2)+1e-6)), optional tau
fac *= 1 + 0.1*log(max(1,(pos+1)/8192)) (kLogScaleAlpha=0.1, floor=8192);
x = v*fac, in place. Config: qk_clip=22.627, rel_clip=8.0; tau=!is_swa.
- k_relpos_bias / vetta_relpos_bias: rel_bias[h,dist] = sum_rc R[h,rc] *
rel_proj[rc,dist] for dist < lim=min(pos+1,rel_extent). R pre-clipped
[n_head,d_rel=16], rel_proj [d_rel,rel_extent=1024] (rel_logits_proj.proj).
- k_kv_store / vetta_kv_store: K (pre-clipped) stored as-is, V RMS-normalized
(rsqrt(mean v^2 + eps)), into a contiguous f32 KV cache [n_kv,seq,hd] at pos.
(Paged FP16/FP8 KV pool is a later perf refinement; contiguous f32 first.)
- Combined parity test vs CPU oracles: l2_clip (scale+tau and plain), relpos
bias, kv_store (K exact, V <1e-5). These complete the k2 attention prep; with
gemm_bf16 (projections) + shortconv4 + flash_swa_gqa the full attention block
can now be composed.
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU 14/14 (--features hip).
- k_attn_res_mix / vetta_attn_res_mix: exact strata k1_attn_res_mix semantics.
For each learned query q and token m, mix n_states = n_blocks+1 depth states
(block snapshots + current): per state inv_rms = rsqrt(mean(x^2)+eps),
score = (x.q)*inv_rms/sqrt(D); softmax over scores -> w; final weight =
w*inv_rms; out = sum_s weight[s]*state_s (RMS-normalized depth mix). This is
Inkling's deep residual that replaces the standard additive residual stream.
Contiguous blocks [n_blocks,M,D] snapshot buffer (FFI-friendly vs ptr array).
- Parity test vs CPU oracle (nb=3, M=2, nq=2, D=64): max_rel_err 1.0e-5.
With this, ALL defining Inkling mechanisms are verified kernels: ShortConv4,
flash SWA GQA (window+relpos+sink+gate), AttnRes block-mix, NVFP4 experts +
SiTU + sigmoid router. The kernel parity foundation is complete; what remains
is integration (lowering the full graph + wiring a complete layer + loop
controllers + KV store + projections).
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU 13/13 (--features hip).
- k_shortconv4_decode / vetta_shortconv4_decode: exact strata
k2_shortconv4_batched static (no-dyn) semantics — per channel
y = x0 + sw0*h0 + sw1*h1 + sw2*h2 + sw3*x0, scaled by 1/sqrt(5); the 3-tap
history ring (t-3,t-2,t-1) shifts h0<-h1<-h2<-x0 in place. This is a defining
Inkling mechanism (applied to k/v/attn/mlp). f32 history here; the BF16 ring
for bit-exact CPU match is a later parity refinement.
- Multi-step parity test: 6-token recurrence vs a CPU oracle, per-step output
match (<1e-5) AND device history ring == host history ring after all steps
(exact). The stateful short-conv evolves correctly across tokens.
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU 11/11 (--features hip).
- kernels/hip: NVFP4 (SF4) codecs ported exactly from strata ink_hip_common —
sf4_e2m1_f32 (E2M1 nibble LUT {0,0.5,1,1.5,2,3,4,6,...}), e4m3fn_to_f32
(F8_E4M3FN: subnormal mant*2^-9, NaN->0, bias 7). Layout: packed_e2m1
[N,K/2] (low nib even col), scales_e4m3 [N,K/16], f32 outer_scale.
- k_nvfp4_gemv (M=1 decode): y[N] = dequant(W)[N,K] @ x[K], one block/row,
threads stride K/16 groups, f32 accumulate. Correctness-first; the Wave32
bandwidth-saturated path is the performance pass. This is the core of the
MoE expert compute (w13/w2); the full direct path (SiTU activation +
weighted reduce) builds on it.
- C ABI + safe wrapper nvfp4_gemv + CPU-oracle parity test (Rust e2m1/e4m3
matching the kernel).
Verified LIVE on gfx1150: nvfp4_gemv max_rel_err ~4e-7 across (8,64)/(16,256)/
(32,128). Eight compute kernels now verified. Default suite 97/97, lean 4
files green; GPU parity 8/8 (--features hip).
- kernels/hip: k_embed_bf16_gather (BF16 table -> f32 token rows, exact) and
k_gemm_bf16 (y[M,N] = x[M,K] @ w[N,K]^T, BF16 in / f32 accumulate,
correctness-first per-element; WMMA tiling is the later performance pass).
C ABI + safe Rust wrappers (embed_bf16_gather, gemm_bf16) + DeviceBuf
byte-level h2d/d2h.
- Verified LIVE on gfx1150: embed exact, gemm max_rel_err 0.0 across
(2,8,16)/(4,32,64)/(1,128,256), rms_norm ~1e-6. Three kernels now cover the
trunk + projection compute path (embed, norm, gemm).
- docs/ORIENTATION.md: a guide for newcomers arriving from vLLM/llama.cpp/
SGLang — what this engine is, the five ideas behind the mental-model shift
(microkernel+services, models compiled to .vbundle, forward pass as a
Lean-proven validated plan, proof-first, parity discipline), the crate map,
the honest current state (CPU pipeline done, GPU begun, no token yet), and
the ordered road to the first agent chat and beyond. Linked from README.
Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU parity 4/4 (--features hip).
- New crate vetta-infer-hip: HIP FFI/DMA backend (unsafe isolated here per
AGENTS.md). Kernel build is feature-gated (`hip`, default OFF) so
`cargo test --workspace` stays host-independent (97/97, no toolchain).
build.rs invokes hipcc --offload-arch=gfx1150, archives libvetta_kernels.a,
links amdhip64 from ROCM_PATH/lib.
- kernels/hip/vetta_kernels.hip: device query, minimal device-buffer
lifecycle (alloc/free/h2d/d2h, RAII DeviceBuf), and the first microkernel
k_rms_norm_f32 (one block/row, shared-mem reduction). C ABI extended in
vetta_kernels.h.
- Safe wrappers: query_device, DeviceBuf, rms_norm_f32.
Verified LIVE on Sogliola (cargo test -p vetta-infer-hip --features hip
-- --ignored): device = AMD Radeon 890M Graphics gfx1150 CU=8 UMA=true;
rms_norm parity vs CPU oracle max_rel_err ~1.3e-6 across rows 1/4/3/2 and
d 2304/128/1024 (tolerance 1e-4). First GPU compute verified end-to-end:
hipcc -> static lib -> FFI -> launch -> parity. This opens the GPU execution
half (executor + remaining kernels toward the first served token).