Repository navigation
feat(models): add K2-Horizon (k2_horizon) dense support - #3243
Merged
Merged
Conversation
inureyes
added a commit
that referenced
this pull request
Nov 22, 2026
Bilingual (en/ko) report for the K2-Horizon dense support PR: the config translation onto the shared Llama decoder, the screened variants, the turn terminator, and the real-checkpoint logit-trace and CLI/server results.
mlxcel exited with `Unsupported model type: k2_horizon` on IFM/K2-Horizon-0.9B. The 0.9B is a plain Llama-shaped decoder with YaRN RoPE, so it now runs on the shared Llama3Model through a K2HorizonConfig translation registered as a config-backed text family (CLI, server, adapter path, `mlxcel arch`). K2HorizonConfig applies the shared impl_rope_lifting_deserialize! lift, so the transformers 5 rope_parameters block becomes rope_theta / rope_scaling (YaRN factor 16 at base 1e6 on the 0.9B, base 1e7 with no scaling on the 7B). to_llama3_args is a full struct literal so a new llama3::ModelArgs field fails to compile here. validate() refuses, naming the field, grouped RMSNorm (layernorm_num_groups != 1, the 3.7B / 7B / 32B), query_key_norm, num_experts / mova_num_experts > 0, a non-null attention_gate_func, use_sliding_window, and a rope_head_dim that differs from head_dim (partial rotary). Tensor parallelism stays refused for the family. Unit tests pin both Hub configs through the lift and each refusal; detection and the rope_parameters lift registry cover the new type. Refs #2358
K2-Horizon's config.json, generation_config.json and tokenizer_config.json declare only <|endoftext|> as EOS, while every assistant turn the chat template renders ends with <|ifm|im_end|>. mlxcel-server therefore decoded the marker into content before the model emitted EOS. The K2-Horizon loader now resolves <|ifm|im_end|> by name from tokenizer.json added_tokens (falling back to tokenizer_config.json added_tokens_decoder) and appends it to the model's EOS ids, following the InternVL and LLM-jp-VL loaders. Shared EOS resolution for other families is unchanged. Unit tests cover the lookup, the merge, and the real checkpoint tokenizer when present. Verified on models/k2-horizon-0.9b: server chat completions (streaming and not) and CLI generate stop after 68 tokens with finish_reason stop and no marker in the output. supported-models.md documents the remaining limitation: the <ifm|think> block is not split into reasoning_content. Refs #2358
…m_experts K2HorizonConfig defaulted an absent query_key_norm to false and an absent num_experts to 0, so a config that left either key out passed validate() and loaded on the dense Llama decoder. The HF configuration_k2_horizon.py defaults them to true and 128, so such a config describes a QK-norm or MoE model; the QK-norm case would decode wrongly without any error because the unused q_norm/k_norm weights are ignored. The serde defaults now follow the HF config class, so an omitted key is refused by name like an explicit one. The published 0.9B config declares both keys and still loads. A unit test removes each key from the 0.9B fixture and expects the refusal. Validated with the k2_horizon, rope_parameters_lift and coverage_tests selectors, clippy -D warnings, fmt and the scripts/ci contract checks. Refs #2358
Cap num_attention_heads, num_key_value_heads, hidden_size, intermediate_size, vocab_size and max_position_embeddings, and check that heads * head_dim and kv_heads * head_dim fit in i32, so an untrusted config cannot wrap the decoder's i32 casts. The MAX_HEAD_DIM doc comment no longer claims it bounds that product alone. Refuse a hidden_act other than silu, since the shared decoder is SwiGLU. An omitted head_dim now defaults to 128 as in HF configuration_k2_horizon.py (the 0.9B declares 64 and is unchanged). A YaRN attention_factor that differs from the shared derivation 0.1 * ln(factor) + 1 is refused; RopeScalingSpec gains an optional attention_factor field that no other family reads, and yarn_get_mscale becomes pub(crate). The adapter route (from_weights) still does not add the turn terminator: the config-backed weight_builder hook receives only the weights and config, with no model directory or tokenizer. Validation: models::k2_horizon (14 passed), models::rope_utils (33 passed), coverage_tests (18 passed), clippy -D warnings clean, and the 0.9B checkpoint still loads and generates. Refs #2358
Bilingual (en/ko) report for the K2-Horizon dense support PR: the config translation onto the shared Llama decoder, the screened variants, the turn terminator, and the real-checkpoint logit-trace and CLI/server results.
inureyes
force-pushed
the
feature/2358-k2-horizon
branch
from
November 22, 2026 19:46
2ba254d to
0eb9404
Compare
inureyes
marked this pull request as ready for review
November 22, 2026 19:51
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
k2_horizon(IFM/K2-Horizon-0.9B) now loads on the sharedLlama3ModelthroughK2HorizonConfig, a config-backed text family, so the CLI,mlxcel-server, the adapter path andmlxcel archpick it up.rope_parametersthrough the sharedimpl_rope_lifting_deserialize!lift: YaRN (factor 16, beta_fast 128, beta_slow 4, original 8192) at base 1e6 on the 0.9B, base 1e7 without scaling on the 7B.to_llama3_argsis a full struct literal.validate()refuses, naming the field:layernorm_num_groups != 1(grouped RMSNorm: 3.7B / 7B / 32B),query_key_norm,num_expertsormova_num_expertsabove 0, a non-nullattention_gate_func,use_sliding_window,rope_head_dim != head_dim(partial rotary), ahidden_actother thansilu, and a YaRNattention_factorthat differs from the shared derivation0.1 * ln(factor) + 1. Omitted keys take the HFconfiguration_k2_horizon.pydefaults (query_key_norm: true,num_experts: 128,head_dim: 128), so leaving a key out is refused the same way as declaring it. Geometry is capped andheads * head_dimis checked to fit in i32. Tensor parallelism stays refused.RopeScalingSpecgains an optionalattention_factorfield (read only by K2-Horizon) andyarn_get_mscalebecomespub(crate); no other family's RoPE changes.<|ifm|im_end|>, resolved by name from the tokenizer's added tokens, to the model's EOS ids. The sidecars declare only<|endoftext|>, so the marker used to leak intocontent.attention_factor, and the floor/ceil range matchestruncate: true.Real-checkpoint validation (
models/k2-horizon-0.9b, bf16, M3 Ultra)mlxcel generate -p "The capital of France is" -n 50 --temp 0: coherent ("... The capital of France is Paris. ..."), 182 tok/s. With a chat question and-n 200it stops on the terminator after 68 tokens. Re-run after the final screening commit: still loads and generates.mlxcel-server/v1/chat/completions, non-streaming and streaming:finish_reason: stop, 68 tokens, no<|ifm|im_end|>in the output, ending "The capital of France is Paris."k2_horizon(d998a620, bf16), 2 chunks of 12288 tokens,compare_logit_traces.py --decided 2:rope_scalingdroppedYaRN-arm disagreements all sit where the reference's top-two gap is below 0.25 (mlxcel runs the weights in f16).
Known limitations
<ifm|think>block (and thethink_fast/think_fastereffort variants) is not split intoreasoning_content. Registering the pairs touches five shared marker tables, so it is left for a follow-up.from_weights) does not add the turn terminator: the config-backedweight_builderhook receives only the weights and config.Test plan
models::k2_horizon(14),models::rope_utils(33),models::detection_testsandcoverage_tests(18) selectors; clippy-D warnings; fmt; thescripts/cicontract checksCloses #2358