Repository navigation
feat(models): add Falcon-H1 (Mamba2 + attention parallel hybrid) - #256
Conversation
Falcon-H1 (TII) runs a Mamba2 SSM mixer and GQA attention in parallel within each decoder block, summing both mixer outputs with the residual on a single normed input, followed by a SwiGLU MLP. The Mamba2 mixer reuses the Nemotron-H float32-hardened SSD scan (in_proj -> gate/conv_input/dt split -> depthwise conv1d + SiLU -> hidden/B/C split -> scan -> gate -> out_proj) with the fused decode kernel for single-token steps. The one Falcon-H1 difference is the post-scan gate: plain SwiGLU (silu(gate) * y) when mamba_rms_norm is false (the default), versus the gated RMSNorm when true. MUP channel multipliers are pre-folded into the mlx-community weights during conversion (the reference sanitize early-returns once the conv1d weight is in MLX channels-last layout), so the loader folds nothing and only applies the runtime tied-head factor lm_head_multiplier / embedding_multiplier on embed_tokens.as_linear. The embedding forward uses the pre-scaled weight directly. Each layer owns a paired cache (Mamba2 conv+ssm state and a KVCache, both present) through ModelOwnedSequenceState; the family reports supports_batching == false and supports_padded_prefill == false, excluding the recurrent SSM state from paged batching. Registered across detection, model metadata (Nonstandard directory + Special weight route), LoadedModel dispatch, the nonstandard directory loader, the special owned-weights loader, the tensor-parallel model-type string map, and the CLI family order (new "Falcon" group). Adds checkpoint-free config/geometry unit tests and a supported-models doc entry.
Implementation Review: APPROVEIntentPort TII Falcon-H1: a hybrid decoder block running a Mamba2 SSM mixer and GQA attention in parallel on the same normed input, summing both with the residual, followed by a SwiGLU MLP. First Mamba2-hybrid port; pattern intended for reuse. Verification against focus areasSSD-scan correctness (prefill graph + decode kernel). Conv split offsets. in_proj split: gate Per-head geometry. n_heads=24, mamba head_dim=32 (= d_ssm/n_heads = 768/24), n_groups=1, state=64 threaded consistently; attention head_dim=64 kept separate from the mamba head_dim. Multiplier pre-folding. Integration. Complete and consistent: detection, mod.rs (module/re-export/enum/ALL_MODEL_TYPES/metadata/test-mod), model_metadata (Nonstandard + Special), loaded_model (variant + delegate), nonstandard.rs + special.rs loaders, tensor-parallel fallback string, and main.rs FAMILY_ORDER ("Falcon", matching the metadata family). docs updated. Recurrent SSM state excluded from paged batching via Conventions. License header matches the in-tree pattern; upstream cited by GitHub URL; no Findings (none blocking)
No CRITICAL/HIGH findings; no code changes made. The implementation faithfully mirrors the validated nemotron_h scan and the LFM2 hybrid-cache pattern. Checklist
|
…lup#256) * feat(models): add Falcon-H1 (Mamba2 + attention parallel hybrid) Falcon-H1 (TII) runs a Mamba2 SSM mixer and GQA attention in parallel within each decoder block, summing both mixer outputs with the residual on a single normed input, followed by a SwiGLU MLP. The Mamba2 mixer reuses the Nemotron-H float32-hardened SSD scan (in_proj -> gate/conv_input/dt split -> depthwise conv1d + SiLU -> hidden/B/C split -> scan -> gate -> out_proj) with the fused decode kernel for single-token steps. The one Falcon-H1 difference is the post-scan gate: plain SwiGLU (silu(gate) * y) when mamba_rms_norm is false (the default), versus the gated RMSNorm when true. MUP channel multipliers are pre-folded into the mlx-community weights during conversion (the reference sanitize early-returns once the conv1d weight is in MLX channels-last layout), so the loader folds nothing and only applies the runtime tied-head factor lm_head_multiplier / embedding_multiplier on embed_tokens.as_linear. The embedding forward uses the pre-scaled weight directly. Each layer owns a paired cache (Mamba2 conv+ssm state and a KVCache, both present) through ModelOwnedSequenceState; the family reports supports_batching == false and supports_padded_prefill == false, excluding the recurrent SSM state from paged batching. Registered across detection, model metadata (Nonstandard directory + Special weight route), LoadedModel dispatch, the nonstandard directory loader, the special owned-weights loader, the tensor-parallel model-type string map, and the CLI family order (new "Falcon" group). Adds checkpoint-free config/geometry unit tests and a supported-models doc entry. * fix(models): honor mamba_norm_before_gate in Falcon-H1 gated RMSNorm
Summary
Port TII Falcon-H1, a hybrid that runs a Mamba2 SSM mixer and GQA attention in parallel within each decoder block: both mixers consume the same normed input, their outputs are summed with the residual, and a SwiGLU MLP follows.
Upstream reference: https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/falcon_h1.py
What changed
src/models/falcon_h1.rs(new): the parallel Mamba2 + attention block, the float32-hardened SSD scan with fused single-token decode kernel, the SwiGLU MLP, the paired per-layer cache, the directory/owned-weights loaders, and theLanguageModelimpl.src/models/falcon_h1_tests.rs(new): checkpoint-free config, Mamba2 geometry, tied-head-factor, gate-selection, and EOS tests.src/models/detection.rs("falcon_h1"),src/models/mod.rs(module, re-export,ModelType::FalconH1,ALL_MODEL_TYPES, metadata"Falcon", test module),src/model_metadata.rs(Nonstandard directory + Special weight route),src/loaded_model.rs(enum variant + dispatch arm),src/loading/nonstandard.rs(directory loader),src/loading/special.rs(owned-weights loader),src/distributed/tensor_parallel/inference.rs(model-type string),src/main.rs(FAMILY_ORDERgains"Falcon").docs/supported-models.md: Falcon-H1 entry in the hybrid families list.Implementation notes
silu(gate) * y) whenmamba_rms_normis false (the default) and the gated RMSNorm only when true.sanitizeearly-returns once the conv1d weight is in MLX channels-last layout), so the loader folds nothing and applies only the runtime tied-head factorlm_head_multiplier / embedding_multiplieronembed_tokens.as_linear.KVCache, both present) throughModelOwnedSequenceState; the family reportssupports_batching == falseandsupports_padded_prefill == false, which keeps the recurrent SSM state out of paged batching.Test plan
cargo fmt --checkcargo check --release --features metal,accelerate --libcargo clippy --release --features metal,accelerate --lib -- -D warningsmodels/Falcon-H1-Tiny-90M-Instruct-4bit(runs on the Metal host; no GPU in the build environment)Closes #247