Repository navigation
feat(models): add Z1T-0 (z1t) attention-free AFT-conv decoder - #3249
Merged
Merged
Conversation
5 tasks done
Member
Author
Security and performance reviewFixed in 44e0247:
Not fixed (MEDIUM/LOW):
Tests: |
inureyes
added a commit
that referenced
this pull request
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
force-pushed
the
feature/issue-2364-z1t-support
branch
from
November 22, 2026 20:12
b31def7 to
f677f99
Compare
inureyes
marked this pull request as ready for review
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 intomlxcel generate,mlxcel-server,mlxcel archand the special weight loader, and it followsmlx_vlm/models/z1tnumerically.ksize - 1conv window) lives inModelOwnedSequenceState, as RWKV-7's does. Decode is O(1) per token.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_logitsprojects only the sampled row through the head and its bias. APC is opted out forz1t(by model type and by architecture name), and prompt caching of the state stays out of scope.aft_kindother thanconvis refused;aft_ksizemust 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.B * L * out * kstays under 32M elements (exact; equal to upstream's 8ML * outcap for Z1T-0). The running pool sums are scheduled after prefill so the full-length per-token tensors are released early.z1tas having no context-proportional KV cache (it previously reported 1.50 GiB at full context for a state under 1 MiB).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) printsThe 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 itsZ1TCache(139.6 tok/s there).mlxcel-server, one/v1/completionsrequest (max_tokens32, 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 forz1t.examples/logit_trace,docs/architecture.md, 8 chunks of 64, top-8), compared withscripts/compare_logit_traces.py --decided 2. The reference arms load the vendoredreferences/mlx-vlmz1t module under mlx 0.32.4: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 andlast_row_case!.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 everyscripts/cicontract check.Changes during review
e36757d6: memory estimate no longer charges Z1T for a KV cache.44e0247f: bounds onmax_position_embeddingsandaft_ksizethat previously truncated throughas 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,z1tinHYBRID_SSM_ARCH_FRAGMENTS,docs/turbo-kv-cache.mdupdated.TECHNICAL_REPORTS/3249-z1t-attention-free-decoder-20261123.{en,ko}.md.Closes #2364