Skip to content

feat(models): add Z1T-0 (z1t) attention-free AFT-conv decoder - #3249

Merged
inureyes merged 6 commits into
mainfrom
feature/issue-2364-z1t-support
Nov 22, 2026
Merged

inureyes merged 6 commits into
mainfrom
feature/issue-2364-z1t-support

Conversation

@inureyes

@inureyes inureyes commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds Extropic Z1T-0 (model_type: z1t). The model uses an AFT-conv token mixer, Dynamic Tanh norms and fixed fan-in-4 sparse tanh-linears. It is wired into mlxcel generate, mlxcel-server, mlxcel arch and the special weight loader, and it follows mlx_vlm/models/z1t numerically.
  • Per-layer streaming state (pool sums plus the ksize - 1 conv window) lives in ModelOwnedSequenceState, as RWKV-7's does. Decode is O(1) per token.
  • Batched decode decision: it joins native batched decode (pinned in EXPECTED_NATIVE). It stacks the per-row state, runs once, and splits the state back. Mixed fresh and initialized rows, multi-token calls and masked calls fall back to per-row forwarding, exactly as RWKV-7 does.
  • last_row_logits projects only the sampled row through the head and its bias. APC is opted out for z1t (by model type and by architecture name), and prompt caching of the state stays out of scope.
  • Load-time validation: aft_kind other than conv is refused; aft_ksize must be 1 to 1024; the positional table size must fit in i32 elements; the int32 index tables are range-checked; dense weights, the embedding and the head are shape-checked against the config when unquantized.
  • Long prefill chunks the sparse gather along the sequence axis so B * L * out * k stays under 32M elements (exact; equal to upstream's 8M L * out cap for Z1T-0). The running pool sums are scheduled after prefill so the full-length per-token tensors are released early.
  • The memory estimate classifies z1t as having no context-proportional KV cache (it previously reported 1.50 GiB at full context for a state under 1 MiB).
  • A one-token chunk skips the time-axis cumsum, which is the identity there. The strided scan over a length-1 axis cost 93 ms per layer per decode step (2.72 tok/s overall); without it the model decodes at 225.7 tok/s.

Validation on models/z1t-0-mlx (M3 Ultra, test-fast build)

  • mlxcel generate -m models/z1t-0-mlx -p "The meaning of life is" -n 64 --temp 0 (re-run on the final code with a release build: 236.6 tok/s, load 0.33 s, 4.63 GB resident) prints The meaning of life is not a thing of the past. It is not a question of meaning. It is not a question of meaning. ... at 64 tokens and 225.70 tok/s. This is the same text as greedy decode through the vendored mlx-vlm module and its Z1TCache (139.6 tok/s there).
  • mlxcel-server, one /v1/completions request (max_tokens 32, temperature 0): it returns " not a thing of the past. It is not a question of meaning. ...", finish_reason: length, usage 5 + 32 tokens. Startup logs that APC is disabled for z1t.
  • Teacher-forced trace (examples/logit_trace, docs/architecture.md, 8 chunks of 64, top-8), compared with scripts/compare_logit_traces.py --decided 2. The reference arms load the vendored references/mlx-vlm z1t module under mlx 0.32.4:
Reference Candidate Top-1 disagreement Decided (gap >= 2) Max logit delta
mlx-vlm z1t mlxcel 0 / 512 0 / 113 0.0000
mlx-vlm z1t mlx-vlm z1t, conv only (pool dropped) 325 / 512 62 / 113 (54.9%), fails n/a
mlxcel B=1 mlxcel native batched B=4 0 / 512 0 / 113 0.0000

Perplexity is 130.56 for both full arms and 320.92 for the conv-only arm.

Tests

  • models::z1t: 13 tests. They cover flat versus streaming (token by token and uneven pieces) within 1e-5, the sparse linear against a dense reference built from the same indices at three chunk caps, chunked gather inside the model, upstream-sanitized key names, refusals (aft_kind, heads, out-of-range index, truncating or oversized config values, mis-shaped dense weights), batched chunked gather, the dense fan-in path, detection and EOS, the model-owned batched-decode harnesses and last_row_case!.
  • These also pass: coverage_tests (18), prompt_cache::hybrid_ssm (14), execution::kv_arch (57), all_model_types, model_metadata, loading::special, models::detection_tests, models::registry, clippy on lib and tests with -D warnings, cargo fmt --check, and every scripts/ci contract check.

Changes during review

  • e36757d6: memory estimate no longer charges Z1T for a KV cache.
  • 44e0247f: bounds on max_position_embeddings and aft_ksize that previously truncated through as i32 (out-of-bounds positional read, empty conv kernel panic), and a gather chunk measure that includes batch and fan-in.
  • 5ac895ad: dense shape validation at load, z1t in HYBRID_SSM_ARCH_FRAGMENTS, docs/turbo-kv-cache.md updated.
  • The bilingual technical report is in TECHNICAL_REPORTS/3249-z1t-attention-free-decoder-20261123.{en,ko}.md.

Closes #2364

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:low Low priority area:models Model architectures, weights, loading, metadata labels Nov 22, 2026
@inureyes inureyes mentioned this pull request Nov 22, 2026
5 tasks done
@inureyes inureyes added modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model arch:ssm State-space / recurrent model (Mamba, RWKV) labels Nov 22, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

Fixed in 44e0247:

  • HIGH: max_position_embeddings past i32 truncated in the positional-table shape check (2^32 + 256 matched a 256-row table), so decode positions indexed past the table in an unchecked GPU gather. Validation now requires the table plus its zero row to fit i32 elements.
  • HIGH: aft_ksize was unbounded. 2^32 truncated to an empty w_conv and panicked on the first forward; large values sized every sequence's conv window without limit. Capped at 1024.
  • HIGH: the sparse gather chunk measured L * out only (upstream _SPARSE_CHUNK_ELEMS), so a large fan-in allocated 8M * k elements per projection. The measure now counts B * L * out * k; the Z1T-0 chunk size is unchanged.
  • MEDIUM: the lazy AFT running pool sums pinned every layer's full-length ekv and ek after a long prefill until the first decode step. They are now scheduled with schedule_prefill_state.

Not fixed (MEDIUM/LOW):

  • Dense-path linears, the embedding and the LM head are not shape-checked against hidden_size, 2 * hidden + heads and vocab_size, so a malformed dense checkpoint fails inside MLX at the first forward instead of at load.
  • An unknown sequence id panics in forward_rows_for_sequence and batched decode, matching RWKV-7.
  • Batched decode restacks and copies every row's state per step. The state is small (about 1 MB per sequence on Z1T-0) and this matches the other recurrent families.
  • The sinusoidal fallback (only when pe.pe is missing) can still build up to i32::MAX elements on the host.

Tests: models::z1t (12, including two new ones), coverage_tests (18), clippy -D warnings, fmt, and the CI contract scripts all pass. A release mlxcel generate on models/z1t-0-mlx (greedy, 24 tokens) loads and decodes coherent text at about 227 tok/s.

inureyes added a commit that referenced this pull request Nov 22, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 22, 2026
Extropic Z1T-0 mixes tokens with AFT-conv (a causal depthwise conv over a ksize window plus a causal cumulative pool), normalizes with Dynamic Tanh, and runs every internal projection as a fixed fan-in-4 sparse linear wrapped in tanh. The port follows mlx_vlm/models/z1t numerically and accepts both the raw JAX key names the checkpoint ships and the names upstream's sanitize produces.

Each layer's running pool sums and ksize - 1 conv window live in ModelOwnedSequenceState, as RWKV-7 does, so decode is O(1) per token and joins native batched decode by stacking the per-row state. The sparse gather is chunked along the sequence axis past upstream's 8M-element cap, and the int32 index table is range-checked at load. aft_kind other than conv is refused. The prefill implements last_row_logits, and APC is disabled for the family.

A one-token chunk skips the time-axis cumsum (it is the identity there): the strided scan over a length-1 axis cost 93 ms per layer per decode step on an M3 Ultra, 2.7 tok/s in total, and 225.7 tok/s without it.

Validated on mlx-community/Z1T-0-mlx: the greedy CLI output matches mlx-vlm token for token, and a 512-position teacher-forced trace shows 0 disagreements against the mlx-vlm z1t module.

Refs #2364
List z1t in the supported text families with its state model, limits and validation, add it to the model-owned families that run native batched decode, and add a changelog entry.

Refs #2364
Z1T-0 is attention-free, and its config carries no attention head count, so the KV classifier fell through to the flat formula with one head of width hidden_size. `mlxcel inspect` and the memory preflights then charged a phantom 196608 bytes per token (1.50 GiB at 8192 tokens) labelled "standard attention (4 layers, full context)". Its real per-sequence state is the fixed AFT-conv pool and conv window, under 1 MiB.

`kv_arch::classify` now treats `z1t` like the pure SSM families (no context-proportional KV), which also keeps the prompt-cache snapshot sizing and the KV-mode advisor on their no-KV branches. A unit test pins the Z1T-0 config to zero KV bytes.

Refs #2364
A malformed Z1T checkpoint could get past load-time validation through i32 truncation. A max_position_embeddings of 2^32 + 256 truncated to 256 in the positional-table shape check, so a 256-row table passed while decode positions indexed past its end in an unchecked GPU gather. An aft_ksize of 2^32 truncated to an empty w_conv and panicked on the first forward, and a large aft_ksize sized every sequence's conv window without bound.

Validation now caps aft_ksize at 1024 and requires the positional table, including its appended zero row, to fit i32 elements. The sparse projection chunk measure counts the batch and the fan-in of the [B, chunk, out, k] transient, so a checkpoint with a large fan-in no longer allocates 8M * k elements per projection; the cap keeps the upstream chunk size for Z1T-0. The AFT running pool sums are scheduled after a long prefill so the lazy sums stop pinning every layer's full-length source until the first decode step.

Validated with the models::z1t and coverage_tests selectors, clippy -D warnings, and the CI contract scripts.

Refs #2364
…h name

The dense-path projections, the embedding and the LM head of Z1T were not checked against hidden_size, 2*hidden+heads and vocab_size, so a mis-shaped checkpoint would fail later with an opaque broadcast error. Unquantized weights are now shape-checked at load with a clear error; layers that ship a .scales tensor are skipped because quantization changes the stored shape.

Also add the z1t architecture fragment to the hybrid-SSM APC carve-out next to rwkv7, so a config without model_type still disables prompt-cache sharing, and list Z1T in the attention-free row of the Turbo KV advisor table.

Validation:
- cargo clippy --lib --tests --features metal,accelerate -- -D warnings: clean
- --lib models::z1t (13), coverage_tests (18), prompt_cache::hybrid_ssm (14), execution::kv_arch (57): pass

Refs #2364
@inureyes
inureyes force-pushed the feature/issue-2364-z1t-support branch from b31def7 to f677f99 Compare November 22, 2026 20:12
@inureyes
inureyes marked this pull request as ready for review November 22, 2026 20:15
@inureyes
inureyes merged commit c0bcf57 into main Nov 22, 2026
32 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-2364-z1t-support branch November 22, 2026 20:15
inureyes added a commit that referenced this pull request Nov 22, 2026
The Kolibri-1 (#3275), Limite (#3249) and Xing4.0 (#3276) oracle trace scripts carry a shebang but landed with mode 100644. The executable-mode check in the Python tooling tests fails on main, and every open PR inherits the failure through its merge ref.

This sets the executable bit on the three files. Mode change only, no content changes. Verified locally that no other tracked `scripts/*.py` with a shebang is left at 100644.
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:ssm State-space / recurrent model (Mamba, RWKV) area:models Model architectures, weights, loading, metadata modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): add Z1T-0 (z1t) support

1 participant