Skip to content

feat(models): add Kolibri-1 (kolibri1) hybrid sliding/full MoE - #3275

Merged
inureyes merged 3 commits into
mainfrom
feature/issue-2357-kolibri1
Nov 22, 2026
Merged

inureyes merged 3 commits into
mainfrom
feature/issue-2357-kolibri1

Conversation

@inureyes

@inureyes inureyes commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds Aleph Alpha Kolibri-1 (model_type: kolibri1), wired into mlxcel generate, mlxcel-server, mlxcel arch, the config-backed loader and the adapter weight path. It is AFMoE without the attention output gate, so it reuses AFMoE's attention block (now with an optional gate and explicit geometry), its shared MLP, its weight validators and its hybrid prefill masks (lifted into hybrid_prefill_masks, AFMoE output unchanged, its 32 tests pass), plus gemma3's Cache enum in model-owned state.
  • Router: selection on raw logits plus e_score_correction_bias (not sigmoid plus bias), the six reordered by selection value, weights from the sigmoid of the unbiased logits in f32, renormalized only under norm_topk_prob. Full layers are NoPE; logits are cast to f32 for head_dtype: float32.
  • Load: moe.router.expert_bias (or mlp.expert_bias) is renamed, the 384 unstacked expert planes per projection are stacked through drain_numbered_expert_planes and materialized one layer at a time (41.9 GB resident, 10 to 12 s load), and a short stack is refused by AFMoE's validate_stacked_experts. Also refused: a layer_types list of the wrong length or kind, a quantized router, a non-default rope_scaling, attention_bias.
  • Native batched decode (pinned in EXPECTED_NATIVE), last-row prefill logits and model-state snapshots, on AFMoE's contracts.
  • Docs: docs/supported-models.md (with the trace results), docs/environment-variables.md (Kolibri-1 in the MLXCEL_FUSED_MOE and attention-cache snapshot family lists), docs/CONTINUOUS_BATCHING.md, docs/turbo-kv-cache.md, CHANGELOG.md, and the bilingual technical report TECHNICAL_REPORTS/3275-kolibri1-hybrid-moe-20261123.{en,ko}.md. The mlx-vlm reference trace script is scripts/kolibri1_oracle_trace.py.

Validation on models/kolibri-1-mlx-4bit (M3 Ultra)

  • mlxcel generate -m models/kolibri-1-mlx-4bit -p "Hello" -n 50 --temp 0 --show-reasoning: coherent reasoning text ("The user said "Hello". ... This is a standard greeting."), 83 tok/s. A 792-token prompt (first 3000 characters of docs/architecture.md plus a summarize instruction) gives an accurate outline of the document at 77 tok/s.
  • mlxcel-server, /v1/chat/completions with the same 792-token prompt (temperature 0, 400 tokens): same text as the CLI, finish_reason: length. /v1/completions with a 731-token raw prompt continues the document.
  • Teacher-forced traces against the vendored mlx-vlm module (scripts/kolibri1_oracle_trace.py, mlx 0.32.4, corpus docs/architecture.md, --decided 2, mlxcel with MLXCEL_FUSED_MOE=0):
Reference Candidate Top-1 disagreement Decided Perplexity
mlx-vlm, one 1024-token forward mlxcel prefill (1024 1 8 0) 0 / 1024 0 / 383 31.24 vs 31.24, max delta 0
same mlx-vlm --rope-on-full 601 / 1024 155 / 383 (40.5%), fails 116.28
mlx-vlm chunks 4 to 7 of 256 8 8 1024 mlxcel width-one decode behind a 1024-token prefix (MLXCEL_TRACE_BATCH_ROWS=1), rings wrapped 57 / 1024 1 / 388 (0.26%) 18.10 vs 18.08
same mlx-vlm --rope-on-full 685 / 1024 220 / 388 (56.7%), fails 155.36

The trace's id-less PREFILL arm is not used: like AFMoE, this family opts out of chunked prefill, so an id-less multi-token forward starts a new prompt and the traced chunk loses its context (chunk 0 agreed, later chunks did not).

Tests

  • models::kolibri1 (19): router fixtures that fail under the sigmoid-plus-bias rule, selection ordering and norm_topk_prob, NoPE full versus rotating sliding attention, sanitize rename and stacking (plane order checked), pre-stacked rename and idempotency, short-stack, quantized-router and layer_types refusals, detection, decode through a wrapped ring versus prefill, snapshot restore, the model-owned batched multistep harness and last_row_logits.
  • models::afmoe (32), coverage_tests (18), rope_parameters_lift, all_model_types, model_metadata, snapshot_sizing, clippy on lib and tests with -D warnings, cargo fmt --check, and every scripts/ci contract check pass.

Not tested: the MXFP4 conversion (not on this host) and the EAGLE3 drafter (out of scope).

Closes #2357

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata labels Nov 22, 2026
@inureyes inureyes added modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box 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

Run Aleph Alpha Kolibri-1 (kolibri1) through mlxcel generate, mlxcel-server and mlxcel arch with output matching mlx-vlm, reusing AFMoE's attention, masks, validators and an existing expert stacker.

Findings Addressed

No CRITICAL or HIGH findings, so no fixes were committed.

Remaining Items

  • kolibri1_lm.rs restates AFMoE's model-owned LanguageModel impl (about 300 lines, roughly 85 differing lines after renaming). This matches how the other model-owned families are written today; a shared helper would be a separate refactor across AFMoE, Gemma 3 and the others. (MEDIUM)
  • docs/environment-variables.md: the MLXCEL_FUSED_MOE row's "Active for" list and the two attention-cache snapshot family lists (prompt-cache sizing paragraphs) name AFMoE but not Kolibri-1, which uses the same fused kernel and snapshot path. (LOW)
  • The router_t f32 copy of the router weight adds about 3.9 MB per layer (about 200 MB total) over keeping it bf16 and casting per call. Numerically identical, so acceptable as is. (LOW)

Checked against the reference

Router (selection on raw logits plus bias, argpartition on the negated selection, reorder by selection value, sigmoid(logits) weights, +1e-20 renormalization only under norm_topk_prob, f32 combine cast back), norm sandwich order, NoPE full layers, per-head Q/K norm before RoPE, RotatingKVCache(513) on sliding layers and KVCache on full layers, sliding and causal masks, f32 logits for head_dtype: float32, and the sanitize (bias rename, numbered and pre-stacked experts, short-stack refusal) all match mlx_vlm/models/kolibri1/language.py. The AFMoE refactor (optional gate, AttentionGeometry, hybrid_prefill_masks) is behavior-preserving: AFMoE always loads the gate and the mask helper is the same code moved.

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass

Tests: models::kolibri1 19 passed, models::afmoe 32 passed, coverage_tests 18 passed (under the GPU lock), and clippy on lib and tests with -D warnings is clean. Contract checks (fmt, used-by, kernel dtype keys, env var docs, crate versions, kernel port dispatch, binary assets, Apache header) pass. The real checkpoint was not rerun because no forward-pass code changed.

@inureyes

Copy link
Copy Markdown
Member Author

Security and Performance Review

No CRITICAL or HIGH findings, so no fixes were committed.

Checked and sound

  • Expert gather bounds: validate_weights runs after stacking and refuses a stack with fewer planes than num_experts (validate_stacked_experts), a router with other than num_experts rows, a bias not shaped [num_experts], and scales or biases whose leading axes differ from the weight. A gap in expert numbering stops the drain early and is refused the same way. num_experts_per_tok is bounded to 1..=num_experts, so router indices stay below the plane count on both the fused and unfused paths.
  • Config: every size that reaches an allocation, an as i32 cast or a kernel is bounded (layers, hidden, heads, head_dim, vocab, experts, intermediate sizes, sliding window), KV heads must divide heads, layer_types must cover every layer, and eps, rope_theta and quantization params are checked before weights are read.
  • Decode path: no evals or host syncs; routing is lazy MLX ops only. The AFMoE refactor (Option gate, hybrid_prefill_masks) is behavior-equivalent and adds one match per attention call.
  • Load: stacking is materialized one projection of one layer at a time, so peak extra memory is one layer's planes plus its stack.

Remaining items

  • MEDIUM, drain_numbered_expert_planes (src/models/switch_layers.rs): expert planes with mismatched shapes (different rank or dims across experts) reach mlx::core::stack, which throws across a non-Result cxx binding and aborts the process during sanitize_weights, before validate_weights can return an error. A malformed checkpoint therefore kills the loading process instead of failing the load. The helper is shared with Qwen3.5, Qwen3-Next and Gemma 4, so the fix (compare every part's shape against expert 0 before stacking and leave the leaf unstacked so validation refuses it) belongs in a separate change covering all callers.
  • LOW, Kolibri1Moe::router_t: the f32 transposed router copy costs about 4 MB per layer (about 200 MB on 50 layers). Keeping the bf16 weight and casting per call would save that at a small per-token cost; the current choice is reasonable.

Tests run

clippy (--lib --tests -D warnings) and --lib models::kolibri1, --lib models::afmoe, --lib coverage_tests under the GPU lock.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 22, 2026
Aleph Alpha Kolibri-1 (`model_type: kolibri1`) failed with `Unsupported model type`. It is AFMoE without the attention output gate: 50 layers in a 4 sliding + 1 full pattern (513-token rotating window, NoPE full layers), per-head Q/K norm, four sandwich norms, and 384 routed experts top-6 plus a shared expert on every layer.

- AFMoE's attention block takes an optional gate and explicit geometry, its shared MLP and weight validators are crate-visible, and its prefill mask construction moved into `hybrid_prefill_masks`; AFMoE output is unchanged and its 32 tests pass.
- The router selects on raw logits plus `e_score_correction_bias`, reorders the six by selection value, and weights with the sigmoid of the unbiased logits in f32. Logits are cast to f32 for `head_dtype: float32`.
- Load renames `moe.router.expert_bias`, stacks the unstacked per-expert planes through `drain_numbered_expert_planes` one layer at a time, and refuses a short stack with AFMoE's `validate_stacked_experts`, a quantized router, and a `layer_types` list of the wrong length or kind.
- Wired into detection, registry, loader metadata, `LoadedModel`, native batched decode, last-row logits, snapshot sizing and the docs. `scripts/kolibri1_oracle_trace.py` is the mlx-vlm reference arm, with a `--rope-on-full` negative arm.

Refs #2357
The supported-models entry now carries the teacher-forced results on `Kolibri-1-MLX-4bit`: a 1024-token prefill matches mlx-vlm at every position, width-one decode through wrapped 513-token rings disagrees on 1 of 388 decided positions, and the RoPE-on-full negative arm fails. It also notes why the trace's id-less PREFILL arm does not apply to this family, and the oracle script says how its chunks align with the batched decode arm.

Refs #2357
The review found that docs/environment-variables.md named AFMoE but omitted Kolibri-1 in the MLXCEL_FUSED_MOE "Active for" list and in the attention-cache snapshot family lists. Kolibri-1 uses the fused single-token decode MoE kernel (try_fused_routed) and is in the snapshot sizing family list in snapshot_sizing.rs, so it is added to all three places. There is no Korean counterpart of that file.

Also adds the bilingual technical report for the port: architecture, router semantics, weight sanitize and stacking with its bounds check, the AFMoE refactor, the real-checkpoint trace validation, and the two open MEDIUM findings (LanguageModel impl duplication with AFMoE, and drain_numbered_expert_planes aborting on mismatched plane shapes).

Validation: models::kolibri1 (19) and coverage_tests (18) pass, clippy -D warnings on lib and tests is clean, fmt and the scripts/ci contract checks pass.

Refs #2357
@inureyes
inureyes force-pushed the feature/issue-2357-kolibri1 branch from 20222a5 to 5b915ce Compare November 22, 2026 22:08
@inureyes
inureyes marked this pull request as ready for review November 22, 2026 22:12
@inureyes
inureyes merged commit ede733b into main Nov 22, 2026
33 of 34 checks passed
@inureyes
inureyes deleted the feature/issue-2357-kolibri1 branch November 22, 2026 22:13
inureyes added a commit that referenced this pull request Nov 22, 2026
The branch was rebuilt on current main (f315dc2) to clear the CHANGELOG.md and docs/supported-models.md conflicts with #3270, #3275 and #3276. This merge records the previously pushed commit 2642118 as a parent so the update is a fast-forward of the remote branch; the tree is the rebuilt branch's, which already carries every change of that commit.

Refs #2354
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:hybrid Hybrid attention stack (linear/sliding/full or attention+SSM interleave) area:models Model architectures, weights, loading, metadata modelsize:medium 4-bit checkpoint 10-50GB; comfortable on a 128GB dev box modeltype:text Text-only language model priority:medium Medium 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 Kolibri-1 (kolibri1) support

1 participant