Repository navigation
feat(models): add Kolibri-1 (kolibri1) hybrid sliding/full MoE - #3275
Conversation
Implementation Review SummaryIntent
Findings AddressedNo CRITICAL or HIGH findings, so no fixes were committed. Remaining Items
Checked against the referenceRouter (selection on raw logits plus bias, argpartition on the negated selection, reorder by selection value, Verification
Tests: |
Security and Performance ReviewNo CRITICAL or HIGH findings, so no fixes were committed. Checked and sound
Remaining items
Tests runclippy ( |
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
20222a5 to
5b915ce
Compare
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
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.
Summary
model_type: kolibri1), wired intomlxcel 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 intohybrid_prefill_masks, AFMoE output unchanged, its 32 tests pass), plus gemma3'sCacheenum in model-owned state.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 undernorm_topk_prob. Full layers are NoPE; logits are cast to f32 forhead_dtype: float32.moe.router.expert_bias(ormlp.expert_bias) is renamed, the 384 unstacked expert planes per projection are stacked throughdrain_numbered_expert_planesand materialized one layer at a time (41.9 GB resident, 10 to 12 s load), and a short stack is refused by AFMoE'svalidate_stacked_experts. Also refused: alayer_typeslist of the wrong length or kind, a quantized router, a non-defaultrope_scaling,attention_bias.EXPECTED_NATIVE), last-row prefill logits and model-state snapshots, on AFMoE's contracts.docs/supported-models.md(with the trace results),docs/environment-variables.md(Kolibri-1 in theMLXCEL_FUSED_MOEand attention-cache snapshot family lists),docs/CONTINUOUS_BATCHING.md,docs/turbo-kv-cache.md,CHANGELOG.md, and the bilingual technical reportTECHNICAL_REPORTS/3275-kolibri1-hybrid-moe-20261123.{en,ko}.md. The mlx-vlm reference trace script isscripts/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 ofdocs/architecture.mdplus a summarize instruction) gives an accurate outline of the document at 77 tok/s.mlxcel-server,/v1/chat/completionswith the same 792-token prompt (temperature 0, 400 tokens): same text as the CLI,finish_reason: length./v1/completionswith a 731-token raw prompt continues the document.scripts/kolibri1_oracle_trace.py, mlx 0.32.4, corpusdocs/architecture.md,--decided 2, mlxcel withMLXCEL_FUSED_MOE=0):1024 1 8 0)--rope-on-full256 8 8 1024MLXCEL_TRACE_BATCH_ROWS=1), rings wrapped--rope-on-fullThe trace's id-less
PREFILLarm 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 andnorm_topk_prob, NoPE full versus rotating sliding attention, sanitize rename and stacking (plane order checked), pre-stacked rename and idempotency, short-stack, quantized-router andlayer_typesrefusals, detection, decode through a wrapped ring versus prefill, snapshot restore, the model-owned batched multistep harness andlast_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 everyscripts/cicontract check pass.Not tested: the MXFP4 conversion (not on this host) and the EAGLE3 drafter (out of scope).
Closes #2357