M2: tardits arch skeleton in llama.cpp (RAT level 1 parity) #3

Closed
opened 2026-11-11 16:53:47 +00:00 by dsh · 2 comments
Member

Register the tardits arch in C++ and run RAT level 1 end-to-end inside the fork, with numeric parity against the Python step reference.

Scope (detail: devops/runtime.md, learning path: devops/cxx.md):

  • LLM_ARCH_TARDITS + name/KV/tensor maps, llama_model_tardits in src/models/models.h, new src/models/tardits.cpp, llama_model_mapping() case, llm_arch_is_recurrent() entry + n_embd_s(), saver switch.
  • load_arch_hparams/load_arch_tensors for the GGUF from #2: split .real/.imag planes, 2-D flattened tensors, plane-major output.weight.
  • RAT graph: complex q/k/v linears (4 MUL_MAT each), v (x) conj(k), S = cd_mul(S, gamma) + kv in recurrent memory, recall, complex out_proj, SAIL, branch norm, real LM head. Prefill v1 = unrolled steps.
  • parity: per-op then end-to-end against tardits2gguf/goldens/rat45m.{npz,json}; tolerance ~1e-4 relative (f32), documented; grep the goldens, never the scan.

Blocked by nothing now (#2 converter is in). Expected first artifact: one-token step logits matching the golden within tolerance, then 44-token prefill and the greedy 8 [14, 0, 65, 78, 68, 0, 84, 72].

Register the `tardits` arch in C++ and run **RAT level 1** end-to-end inside the fork, with numeric parity against the Python `step` reference. Scope (detail: `devops/runtime.md`, learning path: `devops/cxx.md`): - `LLM_ARCH_TARDITS` + name/KV/tensor maps, `llama_model_tardits` in `src/models/models.h`, new `src/models/tardits.cpp`, `llama_model_mapping()` case, `llm_arch_is_recurrent()` entry + `n_embd_s()`, saver switch. - `load_arch_hparams`/`load_arch_tensors` for the GGUF from #2: split `.real`/`.imag` planes, 2-D flattened tensors, plane-major `output.weight`. - RAT graph: complex q/k/v linears (4 MUL_MAT each), `v (x) conj(k)`, `S = cd_mul(S, gamma) + kv` in recurrent memory, recall, complex out_proj, SAIL, branch norm, real LM head. Prefill v1 = unrolled steps. - parity: per-op then end-to-end against `tardits2gguf/goldens/rat45m.{npz,json}`; tolerance ~1e-4 relative (f32), documented; grep the goldens, never the scan. Blocked by nothing now (#2 converter is in). Expected first artifact: one-token step logits matching the golden within tolerance, then 44-token prefill and the greedy 8 `[14, 0, 65, 78, 68, 0, 84, 72]`.
dsh self-assigned this 2026-11-11 16:53:47 +00:00
dsh changed title from M2: tardits arch skeleton in llama.cpp (RealGPT parity) to M2: tardits arch skeleton in llama.cpp (RAT level 1 parity) 2026-11-11 17:20:08 +00:00
Author
Member

M2a is in (cd45cd306, pushed): the arch loads and its first-token logits match PyTorch.

  • LLM_ARCH_TARDITS + name/tensor maps, src/models/tardits.cpp (loader for the split real/imag planes, HyperRMSNorm via stock rms_norm on the concatenated 2C reals with weight/sqrt(2), eps 5e-7, plane-major LM head), factory + rope-type cases.
  • Converter writes the standard llama.cpp hparams keys now (tardits.context_length, .embedding_length, .block_count, .attention.head_count[_kv], .attention.layer_norm_rms_epsilon); both GGUFs regenerated.
  • Parity harness: tardits2gguf/tools/tardits_parity.cpp (links libllama, decodes one token id, compares to a raw f32 golden). Result on rat45m.gguf, token 52: max_abs_diff = 3.815e-06, argmax 72 on both sides. Python step golden in tardits2gguf/goldens/rat45m_t0.{f32,json}.

Known gaps, all M2b (recipe written up in devops/research/m2-notes.md):

  1. recurrent memory not wired yet - graph asserts n_tokens == 1, so llama-cli on a normal prompt aborts;
  2. general v (x) conj(k) + decay + recall path is scaffolded under TARDITS_USE_STATE but its layout is not validated yet (the zero-state shortcut is what passed);
  3. test-llama-archs auto-enumerates the new enum and goes red - exclude it via arch_supported() until it has a fixture;
  4. llm_arch_is_recurrent() -> true and llm_arch_supports_save() -> false still needed.

M2b plan from the notes: state row layout [p][v][k] (real heads then imag heads, n_embd_s = 2*H*hs*hs derived from ssm_d_state*ssm_d_inner, so no hparams patch), build_rs_inp/build_rs + per-token unrolled update + one ggml_cpy write-back, then 44-token prefill parity and the n_ubatch=16 split check.

**M2a is in** (`cd45cd306`, pushed): the arch loads and its first-token logits match PyTorch. - `LLM_ARCH_TARDITS` + name/tensor maps, `src/models/tardits.cpp` (loader for the split real/imag planes, `HyperRMSNorm` via stock `rms_norm` on the concatenated 2C reals with `weight/sqrt(2)`, eps 5e-7, plane-major LM head), factory + rope-type cases. - Converter writes the standard llama.cpp hparams keys now (`tardits.context_length`, `.embedding_length`, `.block_count`, `.attention.head_count[_kv]`, `.attention.layer_norm_rms_epsilon`); both GGUFs regenerated. - Parity harness: `tardits2gguf/tools/tardits_parity.cpp` (links `libllama`, decodes one token id, compares to a raw f32 golden). Result on `rat45m.gguf`, token 52: **max_abs_diff = 3.815e-06**, argmax 72 on both sides. Python `step` golden in `tardits2gguf/goldens/rat45m_t0.{f32,json}`. Known gaps, all M2b (recipe written up in `devops/research/m2-notes.md`): 1. recurrent memory not wired yet - graph asserts `n_tokens == 1`, so `llama-cli` on a normal prompt aborts; 2. general `v (x) conj(k)` + decay + recall path is scaffolded under `TARDITS_USE_STATE` but its layout is not validated yet (the zero-state shortcut is what passed); 3. `test-llama-archs` auto-enumerates the new enum and goes red - exclude it via `arch_supported()` until it has a fixture; 4. `llm_arch_is_recurrent()` -> true and `llm_arch_supports_save()` -> false still needed. M2b plan from the notes: state row layout `[p][v][k]` (real heads then imag heads, `n_embd_s = 2*H*hs*hs` derived from `ssm_d_state*ssm_d_inner`, so no hparams patch), `build_rs_inp`/`build_rs` + per-token unrolled update + one `ggml_cpy` write-back, then 44-token prefill parity and the `n_ubatch=16` split check.
Author
Member

M2 is done (e9559bd84): RAT runs in llama.cpp, end to end.

What landed:

  • llm_arch_is_recurrent() -> true, llm_arch_supports_save() -> false; state size derived by n_embd_s() from ssm_d_inner = n_head, ssm_d_state = 2*hs*hs*hd, so no llama-hparams.* patch.
  • New fused CPU op ggml_tardits_scan (ggml/include/ggml.h, ggml/src/ggml.c, ggml/src/ggml-cpu/{ops.h,ops.cpp,ggml-cpu.c}): S = S (x) gamma + v (x) conj(k), out = S (x) q for the whole ubatch, returns out_r | out_i | new_state in one tensor (RWKV-WKV7 pattern). The graph unroll was abandoned: it blew graph_max_nodes = 8*n_tensors on prefill.
  • src/models/tardits.cpp: batched projections/SAIL/norms over the ubatch, build_rs state read per layer, one scan op, ggml_cpy state write-back.
  • Fixed the v (x) conj(k) imag sign - the zero-state shortcut had masked it (same 5.03 diff the old kv path showed). Fixed the golden greedy chain; added tardits2gguf/tools/tardits_prefill.cpp; excluded the arch from the synthetic test fixture.

Verified (all against the Python step reference, never the scan):

  • token-52 single step: max_abs_diff=3.815e-06, argmax 72 both
  • 44-token prefill: max_abs_diff=3.338e-06, identical for n_ubatch=44 and n_ubatch=16
  • greedy 8 [0, 52, 72, 69, 0, 83, 84, 65] matches PyTorch across 8 separate llama_decode calls (state write/read works)
  • llama-completion -m models/tardits/rat45m.gguf -p "The quick brown fox" -n 16 -> "The quick brown fox is the same thi"
  • llama-tokenize round-trips the char vocab; test-llama-archs skips tardits (151/151 passed)

Known limits: single sequence (n_seqs == 1 assert), no test-backend-ops entry for the new op, save disabled by design. Next: #4 (HyperFormer) - the arch must flip to llm_arch_is_hybrid with per-layer is_recr_impl for M3.

**M2 is done** (`e9559bd84`): RAT runs in llama.cpp, end to end. What landed: - `llm_arch_is_recurrent()` -> true, `llm_arch_supports_save()` -> false; state size derived by `n_embd_s()` from `ssm_d_inner = n_head`, `ssm_d_state = 2*hs*hs*hd`, so no `llama-hparams.*` patch. - New fused CPU op `ggml_tardits_scan` (`ggml/include/ggml.h`, `ggml/src/ggml.c`, `ggml/src/ggml-cpu/{ops.h,ops.cpp,ggml-cpu.c}`): `S = S (x) gamma + v (x) conj(k)`, `out = S (x) q` for the whole ubatch, returns `out_r | out_i | new_state` in one tensor (RWKV-WKV7 pattern). The graph unroll was abandoned: it blew `graph_max_nodes = 8*n_tensors` on prefill. - `src/models/tardits.cpp`: batched projections/SAIL/norms over the ubatch, `build_rs` state read per layer, one scan op, `ggml_cpy` state write-back. - Fixed the `v (x) conj(k)` imag sign - the zero-state shortcut had masked it (same 5.03 diff the old kv path showed). Fixed the golden greedy chain; added `tardits2gguf/tools/tardits_prefill.cpp`; excluded the arch from the synthetic test fixture. Verified (all against the Python `step` reference, never the scan): - token-52 single step: `max_abs_diff=3.815e-06`, argmax 72 both - 44-token prefill: `max_abs_diff=3.338e-06`, identical for `n_ubatch=44` and `n_ubatch=16` - greedy 8 `[0, 52, 72, 69, 0, 83, 84, 65]` matches PyTorch across 8 separate `llama_decode` calls (state write/read works) - `llama-completion -m models/tardits/rat45m.gguf -p "The quick brown fox" -n 16` -> `"The quick brown fox is the same thi"` - `llama-tokenize` round-trips the char vocab; `test-llama-archs` skips tardits (151/151 passed) Known limits: single sequence (`n_seqs == 1` assert), no `test-backend-ops` entry for the new op, save disabled by design. Next: #4 (HyperFormer) - the arch must flip to `llm_arch_is_hybrid` with per-layer `is_recr_impl` for M3.
dsh closed this issue 2026-11-11 18:19:11 +00:00
Sign in to join this conversation.
No description provided.