Skip to content

feat(models): add Paradigma Limite (limite) text model - #3251

Merged
inureyes merged 7 commits into
mainfrom
feature/issue-2360-limite
Nov 22, 2026
Merged

inureyes merged 7 commits into
mainfrom
feature/issue-2360-limite

Conversation

@inureyes

@inureyes inureyes commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds Paradigma Limite (model_type: limite, paradigma-inc/limite-1b-violetto). Before this, mlxcel exited with Unsupported model type: limite.

  • Numerics follow mlx-vlm's mlx_vlm/models/limite: a weightless RMSNorm with the dtype's finfo.eps, fold rounding the f32 scalar to bf16 before the multiply, partial interleaved RoPE (32 of 64 pairs, bf16 cos/sin, odd-lane sine negated), 1025-key sliding layers (k >= q - 1024 inclusive, RotatingKVCache(1025)), NoPE full-causal globals, softmax scale 0.1, value embeddings, XSA, the per-head gate, the residual lambdas, the MUDD mix on layers 24 and 47 (accumulated left to right), and the sigmoid-softcapped tied head. The head's bounded values are returned as the logits, as upstream does.
  • The checkpoint keeps its bf16 activations. The bf16 to f16 load cast is skipped for this family, because it would change the norm epsilon.
  • The config's convention strings are checked at load. rope_per_layer: true, mlp_type: relu2, a non-sigmoid softcap, a finite global_window, quantized exports, num_hidden_layers: 0, an unbroadcastable ve_stored_heads and mudd: false with mudd_tap_idx set are refused.
  • limite_shapes.rs checks every checkpoint tensor shape before any op runs (projections, MLP, gates, scalars, xsa_alpha, MUDD tensors, and value_embeds rows against the vocabulary), so a malformed checkpoint returns a load error instead of aborting the process or gathering out of bounds.
  • The model owns its per-sequence caches. last_row_logits applies the head to the sampled row only, batched decode is native, --kv-cache-mode is honored and reported per layer (the 1025-key sliding layers store FP16), and release goes through release_sequence_state_by_id.
  • Wired into detection, the config-backed loader, LoadedModel, the registry (mlxcel arch, KV modes) and docs/supported-models.md. There is no Korean counterpart of that doc.
  • scripts/limite_oracle_trace.py scores the logit_trace chunk plan with mlx-vlm. It has a --drop-mudd negative arm.

Validation

Unit tests on synthetic tensors cover the dtype eps, the bf16 fold (checked against a hand bf16 rounding), the partial RoPE (fails if all 64 pairs rotate), the three-tap MUDD order (256+1+1 in bf16 gives 256, not 258), the 1025-key sliding cache (1025/1025/1025/1101 visible keys after 1100+1 tokens), config refusals, the shared model-owned contracts, int8 KV and last-row. Selectors limite, coverage_tests, models::registry, models::detection_tests, models::mixed_cache_batched_decode_tests, models::model_owned_kv_mode_tests and models::last_row_logits all pass. Clippy -D warnings on lib and tests, fmt and every brief contract check pass.

Real checkpoint, M3 Ultra, bf16. Corpus docs/architecture.md, decided means a top-two gap of at least 2:

Arms Positions Decided disagreement Max delta on ref top-1
ref (one forward per chunk) vs mlxcel, 64 40 8 1536 2560 0 / 814 0.63
ref (prefix-shared forward) vs mlxcel, same plan 2560 1 / 815 2.74
ref vs ref, shared vs per-chunk 2560 1 / 814 3.79
ref vs mlxcel width 1 (decode), 1 1300 8 1536 1300 1 / 402 3.54
mlxcel MLXCEL_TRACE_BATCH_ROWS=1 vs =4, 64 36 8 1536 2304 0 / 666 0.58
ref vs ref --drop-mudd (negative arm) 2560 814 / 814

The single decided disagreement sits at corpus position 1250 every time. The two forward shapes of the reference already disagree there (3672 vs 87, gap 4.05 vs 3.49), and mlxcel agrees with the per-chunk reference in both of its shapes. Chunks 17 to 39 have more than 1025 tokens of context. Perplexity: reference 797.3, mlxcel 796.2. The values are high because the head is bounded.

cargo build --release --features metal,accelerate --bin mlxcel --bin mlxcel-server --example logit_trace
PYTHONPATH=references/mlx-vlm uv run --python 3.12 --with mlx-vlm --with tokenizers --with numpy python scripts/limite_oracle_trace.py models/limite-1b-violetto docs/architecture.md 64 40 8 1536 [--no-prefix-sharing|--drop-mudd] > ref.tsv
./target/release/examples/logit_trace models/limite-1b-violetto docs/architecture.md 64 40 8 1536 > mlxcel.tsv
python3 scripts/compare_logit_traces.py ref.tsv mlxcel.tsv --decided 2
  • mlxcel generate -m models/limite-1b-violetto -p "Hello" -n 50 --temp 0 runs at about 90 tok/s. The model is a math reasoner with a fixed system prompt, so the 50 tokens go to its reasoning channel: "We need to parse the user's request. The user says: "Hello... Please reason step by step...". With -p "What is 17 * 23?" -n 600 it derives 340 + 51 = 391.
  • mlxcel-server served a 1821-token chat prompt and a concurrent 45-token prompt. Both completed (finish_reason: length, 120 and 200 tokens), and the short one reasoned to 42.

Changes during review

  • Security review: added the load-time shape validation above (the value_embeds row check closes an out-of-bounds GPU gather on a malformed checkpoint) and the extra config refusals.
  • Performance review: the RoPE cos/sin tables are built once per forward (limite_rope.rs) instead of per layer and per q/k, and the residual lambdas are cast once at load. Greedy output is byte-identical; decode on a test-fast build went from about 99 to 111 tok/s.
  • Finalizer: unit tests for the tap-index, softcap, EOS and position helpers.

Closes #2360

@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:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) labels Nov 22, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Port Paradigma Limite (limite) with upstream-exact numerics, wired into detection, loader, registry, CLI, server and docs, with model-owned batched decode, last_row_logits, and KV mode reporting.

Findings Addressed

None needed. Each numeric trap was checked line by line against mlx_vlm/models/limite/language.py: dtype eps, bf16 fold, partial interleaved RoPE (bf16 cos/sin, odd-lane sign), the 1025-key window (q - k < 1025 band, RotatingKVCache(1025)), softmax scale 0.1, value embeds before Q/K norm, XSA in f32 with the 1e-4 floor, the per-head gate, residual lambdas, MUDD taps, history and left-to-right accumulation, final norm and the f32 sigmoid softcap head. The wrapper matches the Mellum and Laguna model-owned pattern method for method.

Remaining Items

  • mudd: false with a non-empty mudd_tap_idx skips the mix, while upstream applies it from mudd_tap_idx regardless of the flag. The released checkpoint declares mudd: true, so this does not affect it (LOW, not fixed)

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow (mlxcel arch lists it; CLI generate verified at 112 tok/s)
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass: limite (58), coverage_tests (18), mixed-cache batched decode, model-owned KV mode, last-row, detection and registry selectors; clippy -D warnings, fmt and every contract check

@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

Fixed in ff6e3d2 (fix(models): validate Limite checkpoint shapes at load):

  • HIGH: model.value_embeds was loaded without a row-count check. With fewer rows than embed_tokens, valid token ids gather out of bounds on the GPU, and MLX does not bounds-check the gather. The loader now requires both tables to be [vocab_size, ...].
  • MEDIUM: a checkpoint tensor with the wrong shape threw a C++ exception through the non-Result FFI and terminated the process, at load or at the first forward. limite_shapes.rs now checks the projections, MLP, gates, scalars, xsa_alpha and the MUDD tensors before any op runs, and returns a load error that names the tensor.
  • MEDIUM: validate now refuses num_hidden_layers == 0, which panicked on layers[0]. It also refuses a ve_stored_heads below the KV head count unless it is 1, because no other value broadcasts.
  • MEDIUM (perf): RoPE cos/sin tables were rebuilt for every layer and for both q and k. They are now built once per forward (limite_rope.rs), and the residual lambdas are cast to the activation dtype at load. On limite-1b-violetto, greedy decode output is byte-identical and decode went from about 99.4 to 111.3 tok/s, measured on a test-fast build because a release build was not possible in this worktree.

Checked with no change needed:

  • MUDD history keeps only the tapped slots and is dropped at the end of each forward.
  • Per-sequence caches are released through release_sequence_state_by_id, and the sliding caches are bounded to sliding_window + 1 keys.
  • Folded weights are built once at load. The decode path has no host syncs.
  • Batched decode follows the shared model-owned pattern.

Not fixed (LOW):

  • History slots are held to the end of the stack rather than freed after their last tap.
  • eos_token_id values are narrowed from i64 to i32 without a range check.

Tests:

  • --lib limite: 59 passed.
  • --lib coverage_tests: 18 passed.
  • check, clippy -D warnings and fmt are clean.
  • check_used_by.py, the apache header check and the other contract scripts pass.
  • New unit tests cover the shape refusals and the config refusals.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 22, 2026
Limite is a 48-layer dense decoder whose numerics mlxcel had no equivalent for: weightless RMSNorm with the dtype's finfo eps, bf16-rounded scalar folds, a partial interleaved RoPE with bf16 cos/sin, 1025-key sliding layers interleaved with NoPE global layers, value embeddings, XSA, a per-head attention gate, residual lambdas, the MUDD dense-connection mixer on layers 24 and 47, and a sigmoid-softcapped tied head whose bounded values are what the sampler receives.

The model lives in src/models/limite{,_layers,_config,_wrapper}.rs. The config's convention strings are checked at load and unsupported variants (rope_per_layer, relu2, non-sigmoid softcap, quantized exports, a finite global window) are refused. The checkpoint keeps its bf16 activations because the bf16 to f16 load cast would change the norm epsilon. The wrapper owns per-sequence sliding/global caches, implements last_row_logits and native batched decode, honors the injected KV cache modes and reports per-layer storage modes. Detection, loader registration, mlxcel arch, the registry KV modes and docs/supported-models.md are updated.

scripts/limite_oracle_trace.py scores the same chunk plan with mlx-vlm for the teacher-forced logit trace, with a --drop-mudd negative arm.

Validated with unit tests on synthetic tensors (eps, fold rounding, partial RoPE, MUDD accumulation order, 1025-key sliding cache, config refusals, model-owned cache contracts) and against the real checkpoint (see the PR).

Closes #2360
Upstream applies the MUDD mix whenever mudd_tap_idx is set, regardless of the mudd flag, so a config where the two disagree is now refused at load instead of silently skipping the mix.
The mlxcel_core ops are non-Result FFI calls, so an MLX shape error throws a C++ exception that aborts the whole process (every server tenant), and the value-embedding gather does not bounds-check on the GPU. A checkpoint whose value_embeds had fewer rows than embed_tokens read past the table for every token id above its row count.

A new load-time contract (limite_shapes.rs) checks every tensor the forward reads against the config before any op touches it and returns a "Limite: <tensor> has shape ..., expected ..." error: embed_tokens and value_embeds rows equal vocab_size, the projection and MLP matrices, the one-element scales and lambdas, attn_gate, ve_gate, xsa_alpha, and the MUDD tables (rows past the largest MUDD layer, tap columns for its taps). The layouts match limite-1b-violetto's safetensors header. ModelArgs::validate also refuses num_hidden_layers 0 and a ve_stored_heads that neither equals 1 nor reaches num_key_value_heads, the two cases the reference broadcasts.

Decode no longer rebuilds the RoPE tables per layer and per q/k: cos and the lane-signed sin are computed once per forward (now in limite_rope.rs) with the same f32-to-bf16 order, and the residual lambdas are cast to the activation dtype once at load. Greedy output on limite-1b-violetto is byte-identical (50 and 200 tokens) and decode goes from about 99 to 111 tok/s (test-fast binary).

Validated with the limite and coverage_tests selectors, clippy, fmt and the contract scripts.
Add pure unit tests for the Limite config surface and the RoPE position helpers that the numerics tests did not reach: tap_indices (future slot, too many or no taps, non-numeric key, tapped layer missing from mudd_layers), sigmoid_softcap (explicit, defaulted, absent, null, non-sigmoid kind, zero c), eos_token_ids (number, list, none), and positions_from_offset(s) shapes and values.

Validation:
- cargo test --profile test-fast --features metal,accelerate --lib limite: 63 passed
- cargo test ... --lib coverage_tests: 18 passed
- cargo clippy --lib --tests --features metal,accelerate -- -D warnings: clean

Refs #2360
@inureyes
inureyes force-pushed the feature/issue-2360-limite branch from ae513f4 to 1a1ceec Compare November 22, 2026 20:07
@inureyes
inureyes marked this pull request as ready for review November 22, 2026 20:10
@inureyes
inureyes merged commit d8f4618 into main Nov 22, 2026
32 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-2360-limite branch November 22, 2026 20:11
inureyes added a commit that referenced this pull request Nov 23, 2026
#3251 added the script with a shebang but Git mode 100644, which fails `test_script_executable_modes` in the python tooling CI job on main and on every PR.
@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:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) 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 Limite (limite) support

1 participant