Skip to content

Commit 2b46fc0

Browse files
justinchubyCopilot
andauthored
Add dedicated Falcon-H1 model and GGUF import (#610)
## Summary - add a dedicated Falcon-H1 decoder where attention and Mamba2 run in parallel from the same normalized input, followed by the exact residual and SwiGLU topology - add a dynamic four-state-per-layer ABI ordered as attention key, attention value, convolution state, and SSM state - add strict Falcon-H1 GGUF metadata, tensor-closure, bias-family, transform, and quantization validation against llama.cpp `8d9af256337d1a501250f9bbf4c0859a654bddd6` - register the model/task/config, update the generated GGUF census, and add graph, parity, state, import, CLI, save/reload, and failure-path coverage ## Validation - `python -m pytest tests/falcon_h1_test.py tests/build_graph_test.py tests/weight_alignment_test.py tests/synthetic_parity_test.py -q -k 'falcon_h1' --tb=short` — 11 passed - `python -m pytest tests/falcon_h1_test.py -m integration -k pinned -q --tb=short` — pinned `tiiuae/Falcon-H1-Tiny-90M-Base@7994372e93b62822ae25f8bfb19f653649cea3a3` full-logit parity passed - `python -m pytest src/mobius/integrations/gguf -q --tb=short -n auto` — 2,583 passed - `python -m pytest tests/yaml_schema_test.py tests/falcon_h1_test.py tests/build_graph_test.py tests/weight_alignment_test.py tests/synthetic_parity_test.py -q -k 'falcon_h1 or yaml_schema' --tb=short -n auto` — 261 passed - `python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q -k 'not phi4mm and not apply_weights_unknown and not glm_moe_dsa' --tb=short -n auto` — 7,056 passed, 52 skipped - `python scripts/generate_gguf_support_docs.py --check` — passed - `lintrunner f --output oneline --all-files && lintrunner -a` — clean after initialized lintrunner ## Reviews - independent architecture review: no high-confidence findings; confirmed parallel branch topology, multiplier placement, Mamba ordering, grouped gated RMSNorm, clamp/masking, and backward-compatible defaults - independent state/GGUF review: found missing package config, unstamped output ABI, and late malformed-decay rejection; all fixed with regression coverage ## Runtime and quantization verdict Graph construction and GGUF import are supported. Runtime packaging remains **DEFERRED** because the downstream package schema cannot represent heterogeneous K/V plus convolution/SSM states; tracked by #605. No ORT GenAI runtime-support claim is made. Quantized Falcon-H1 sources can be imported through explicit dequantization. `keep_quantized=True` fails closed because the current route cannot preserve only compatible attention/FFN MatMul roles while safely dequantizing recurrent/state-sensitive tensors and retaining every quantization sidecar. ## Waivers - L4/L5 ORT GenAI package/generation goldens: blocked by the heterogeneous four-state package schema tracked in #605. The pinned real checkpoint has direct full-logit graph parity, but downstream stateful generation is not claimed. - CUDA and reduced-precision runtime evidence: not claimed by this PR; support remains limited to the validated graph/import surface. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent fada98a commit 2b46fc0

24 files changed

Lines changed: 1690 additions & 47 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from mobius import build_from_gguf
1515

1616
| Census | Total | Closure |
1717
|---|---:|---|
18-
| Architectures | 147 | graph verdicts: {'deferred': 90, 'rejected': 3, 'supported': 54}; importable: 52; quantized import: {'rejected': 12, 'supported': 135}; runtime: {'deferred': 144, 'rejected': 3} |
18+
| Architectures | 147 | graph verdicts: {'deferred': 89, 'rejected': 3, 'supported': 55}; importable: 53; quantized import: {'rejected': 12, 'supported': 135}; runtime: {'deferred': 144, 'rejected': 3} |
1919
| Active stored qtypes | 25 | 24 have an import route; 1 are explicitly deferred with no route |
2020
| Serialized projector strings | 60 | {'graph-importable': 2, 'runtime-supported': 0} |
2121
| Tokenizer pre identifiers | 87 | 56 semantic groups; all default to deferred and become exact-copy only with a validated embedded `tokenizer.huggingface.json` |
@@ -382,7 +382,7 @@ before graph construction or durable output.
382382
| `exaone-moe` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | EXAONE-MoE serializes a dense trailing NextN block after an iSWA routed/shared expert trunk, but the pinned loader skips appended blocks. Mobius has no exact SWA schedule, remapped global-MTP transform, or executable head contract. |
383383
| `exaone4` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | EXAONE4 serializes attention/FFN post-norm trailing blocks and NextN tensors with optional synthetic Llama3 RoPE factors, but the pinned loader skips them. No Mobius task owns those preserved-only semantics. |
384384
| `falcon` | — | model=`falcon`; tensor=`falcon` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | Config extraction, exact tensor-name closure, and a full synthetic GGUF graph build are covered, but no representative real-weight GGUF has yet passed ORT parity or generation validation. Runtime packaging remains deferred until that evidence exists. |
385-
| `falcon-h1` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | Falcon-H1 executes attention and Mamba2 in parallel in every block and requires KV and recurrent states simultaneously; FalconCausalLMModel is not compatible with that graph or state ABI. |
385+
| `falcon-h1` | — | model=`falcon_h1`; tensor=`falcon_h1` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | The dedicated graph and GGUF importer preserve parallel Attention+Mamba2 layers and their four-state ABI, but runtime packaging remains deferred pending heterogeneous-state schema support (onnxruntime/mobius#605) and real full-logit plus deterministic stateful-generation evidence. |
386386
| `gemma` | — | model=`gemma`; tensor=`llama` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | Config extraction, exact tensor-name closure, and a full synthetic GGUF graph build are covered, but no representative real-weight GGUF has yet passed ORT parity or generation validation. Runtime packaging remains deferred until that evidence exists. |
387387
| `gemma-embedding` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | Gemma Embedding is a bidirectional stateless embedding graph with alternating sliding-window attention, four norm sites, sqrt(hidden) embedding scaling, and optional pooling/dense modules. Causal Gemma3 text/VLM tasks expose the wrong ABI. |
388388
| `gemma2` | — | model=`gemma2`; tensor=`llama`+`gemma2_extras` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | Config extraction, exact tensor-name closure, and a full synthetic GGUF graph build are covered, but no representative real-weight GGUF has yet passed ORT parity or generation validation. Runtime packaging remains deferred until that evidence exists. |
@@ -583,13 +583,20 @@ real-artifact full-logit and stateful-generation parity.
583583
- `static_cache=True` and non-hybrid task dispatch are rejected for these mixed
584584
state ABIs.
585585

586-
`minimax-01`, `plamo2`, and `falcon-h1` are deferred before config extraction.
587-
MiniMax-01's pinned Lightning schedule and decay/scaling semantics do not match
588-
the current graph; PLaMo2 needs a dedicated fused-QKV Mamba1/attention graph;
589-
Falcon-H1 executes attention and Mamba2 in parallel in every block and therefore
590-
needs KV plus conv/SSM states simultaneously. It is not an alias of ordinary
591-
Falcon. `nemotron_h_moe` remains rejected because its folded MTP attention+MoE
592-
head has no equivalent package contract.
586+
`minimax-01` and `plamo2` are deferred before config extraction. MiniMax-01's
587+
pinned Lightning schedule and decay/scaling semantics do not match the current
588+
graph; PLaMo2 needs a dedicated fused-QKV Mamba1/attention graph.
589+
590+
Falcon-H1 graph/import support is dedicated rather than aliased to Falcon. Every
591+
layer exposes `(key, value, conv_state, ssm_state)` in that order. Static cache is
592+
rejected, and quantized-source imports require `--dequantize` until the mixed graph
593+
can preserve only exact attention/FFN MatMul roles. Runtime packaging remains
594+
deferred pending the heterogeneous-state schema tracked by
595+
[`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605) and
596+
real full-logit plus deterministic stateful-generation evidence.
597+
598+
`nemotron_h_moe` remains rejected because its folded MTP attention+MoE head has
599+
no equivalent package contract.
593600

594601
### Audio/TTS/codec cohort
595602

‎src/mobius/__main__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ def _resolve_static_cache_task(model_type: str) -> ModelTask:
174174
from mobius._registry import _TEXT_ONLY_MODEL_TYPE
175175

176176
model_type = _TEXT_ONLY_MODEL_TYPE.get(model_type, model_type)
177+
if model_type == "falcon_h1":
178+
raise ValueError(
179+
"--static-cache cannot represent Falcon-H1's per-layer K, V, "
180+
"convolution, and SSM states"
181+
)
177182
if model_type == "gemma4":
178183
from mobius.tasks._gemma4 import Gemma4Task
179184

‎src/mobius/_configs/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DFlashConfig,
3232
Eagle3Config,
3333
EncoderConfig,
34+
FalconH1Config,
3435
Gemma2Config,
3536
Gemma3nConfig,
3637
Gemma3nMultiModalConfig,
@@ -107,6 +108,7 @@
107108
"DepthAnythingConfig",
108109
"Eagle3Config",
109110
"EncoderConfig",
111+
"FalconH1Config",
110112
"Gemma2Config",
111113
"Gemma3nAudioConfig",
112114
"Gemma3nConfig",

‎src/mobius/_configs/_base.py‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,150 @@ def from_transformers(cls, config, parent_config=None) -> BambaConfig:
26912691
)
26922692

26932693

2694+
@dataclasses.dataclass
2695+
class FalconH1Config(ArchitectureConfig):
2696+
"""Configuration for Falcon-H1 parallel Attention + Mamba2 decoder layers."""
2697+
2698+
mamba_d_ssm: int = 1024
2699+
mamba_n_heads: int = 128
2700+
mamba_d_head: int = 8
2701+
mamba_n_groups: int = 1
2702+
mamba_d_state: int = 256
2703+
mamba_d_conv: int = 4
2704+
mamba_expand: int = 2
2705+
mamba_chunk_size: int = 256
2706+
mamba_conv_bias: bool = True
2707+
mamba_proj_bias: bool = False
2708+
mamba_norm_before_gate: bool = True
2709+
mamba_rms_norm: bool = False
2710+
time_step_limit: tuple[float, float] = (0.0, float("inf"))
2711+
attention_bias: bool = False
2712+
projectors_bias: bool = False
2713+
lm_head_multiplier: float = 1.0
2714+
embedding_multiplier: float = 1.0
2715+
mlp_multipliers: tuple[float, float] = (1.0, 1.0)
2716+
key_multiplier: float = 1.0
2717+
attention_out_multiplier: float = 1.0
2718+
attention_in_multiplier: float = 1.0
2719+
ssm_multipliers: tuple[float, float, float, float, float] = (
2720+
1.0,
2721+
1.0,
2722+
1.0,
2723+
1.0,
2724+
1.0,
2725+
)
2726+
ssm_in_multiplier: float = 1.0
2727+
ssm_out_multiplier: float = 1.0
2728+
2729+
def __post_init__(self) -> None:
2730+
self.attn_qkv_bias = self.attention_bias
2731+
self.attn_o_bias = self.attention_bias
2732+
if self.hidden_act != "silu":
2733+
raise ValueError("Falcon-H1 supports only hidden_act='silu'")
2734+
if (
2735+
self.head_dim <= 0
2736+
or self.num_attention_heads <= 0
2737+
or self.hidden_size != self.num_attention_heads * self.head_dim
2738+
):
2739+
raise ValueError("Falcon-H1 hidden_size must equal num_attention_heads * head_dim")
2740+
if (
2741+
self.num_key_value_heads <= 0
2742+
or self.num_attention_heads % self.num_key_value_heads
2743+
):
2744+
raise ValueError("Falcon-H1 num_key_value_heads must divide num_attention_heads")
2745+
if self.mamba_d_ssm <= 0 or self.mamba_n_heads <= 0:
2746+
raise ValueError("Falcon-H1 Mamba dimensions must be positive")
2747+
if self.mamba_d_ssm % self.mamba_n_heads:
2748+
raise ValueError("mamba_n_heads must divide mamba_d_ssm")
2749+
if self.mamba_d_head * self.mamba_n_heads != self.mamba_d_ssm:
2750+
raise ValueError("mamba_d_head * mamba_n_heads must equal mamba_d_ssm")
2751+
if (
2752+
self.mamba_n_groups <= 0
2753+
or self.mamba_n_heads % self.mamba_n_groups
2754+
or self.mamba_d_ssm % self.mamba_n_groups
2755+
):
2756+
raise ValueError("mamba_n_groups must divide both mamba_n_heads and mamba_d_ssm")
2757+
if self.mamba_d_state <= 0 or self.mamba_d_conv <= 0 or self.mamba_chunk_size <= 0:
2758+
raise ValueError("Falcon-H1 state, convolution, and chunk sizes must be positive")
2759+
if len(self.mlp_multipliers) != 2:
2760+
raise ValueError("mlp_multipliers must contain exactly two values")
2761+
if len(self.ssm_multipliers) != 5:
2762+
raise ValueError("ssm_multipliers must contain exactly five values")
2763+
if len(self.time_step_limit) != 2:
2764+
raise ValueError("time_step_limit must contain exactly two values")
2765+
time_step_min, time_step_max = self.time_step_limit
2766+
if time_step_min < 0 or time_step_max < time_step_min:
2767+
raise ValueError("time_step_limit must be ordered and non-negative")
2768+
multipliers = (
2769+
self.embedding_multiplier,
2770+
self.lm_head_multiplier,
2771+
self.attention_in_multiplier,
2772+
self.attention_out_multiplier,
2773+
self.key_multiplier,
2774+
self.ssm_in_multiplier,
2775+
self.ssm_out_multiplier,
2776+
*self.mlp_multipliers,
2777+
*self.ssm_multipliers,
2778+
)
2779+
if not all(math.isfinite(value) for value in multipliers):
2780+
raise ValueError("Falcon-H1 multipliers must all be finite")
2781+
2782+
@classmethod
2783+
def from_transformers(cls, config, parent_config=None) -> FalconH1Config:
2784+
base = ArchitectureConfig.from_transformers(config, parent_config)
2785+
fields = _shallow_fields(base)
2786+
fields.pop("embedding_multiplier", None)
2787+
fields["mlp_bias"] = bool(getattr(config, "mlp_bias", False))
2788+
d_ssm = getattr(config, "mamba_d_ssm", None)
2789+
if d_ssm is None:
2790+
d_ssm = int(getattr(config, "mamba_expand", 2)) * base.hidden_size
2791+
n_heads = int(getattr(config, "mamba_n_heads", 128))
2792+
d_head = getattr(config, "mamba_d_head", "auto")
2793+
if d_head == "auto":
2794+
if d_ssm % n_heads:
2795+
raise ValueError("mamba_n_heads must divide mamba_d_ssm")
2796+
d_head = d_ssm // n_heads
2797+
time_step_limit = getattr(config, "time_step_limit", None) or (
2798+
0.0,
2799+
float("inf"),
2800+
)
2801+
return cls(
2802+
**fields,
2803+
mamba_d_ssm=int(d_ssm),
2804+
mamba_n_heads=n_heads,
2805+
mamba_d_head=int(d_head),
2806+
mamba_n_groups=int(getattr(config, "mamba_n_groups", 1)),
2807+
mamba_d_state=int(getattr(config, "mamba_d_state", 256)),
2808+
mamba_d_conv=int(getattr(config, "mamba_d_conv", 4)),
2809+
mamba_expand=int(getattr(config, "mamba_expand", 2)),
2810+
mamba_chunk_size=int(getattr(config, "mamba_chunk_size", 256)),
2811+
mamba_conv_bias=bool(getattr(config, "mamba_conv_bias", True)),
2812+
mamba_proj_bias=bool(getattr(config, "mamba_proj_bias", False)),
2813+
mamba_norm_before_gate=bool(getattr(config, "mamba_norm_before_gate", True)),
2814+
mamba_rms_norm=bool(getattr(config, "mamba_rms_norm", False)),
2815+
time_step_limit=tuple(float(value) for value in time_step_limit),
2816+
attention_bias=bool(getattr(config, "attention_bias", False)),
2817+
projectors_bias=bool(getattr(config, "projectors_bias", False)),
2818+
lm_head_multiplier=float(getattr(config, "lm_head_multiplier", 1.0)),
2819+
embedding_multiplier=float(getattr(config, "embedding_multiplier", 1.0)),
2820+
mlp_multipliers=tuple(
2821+
float(value)
2822+
for value in (getattr(config, "mlp_multipliers", None) or (1.0, 1.0))
2823+
),
2824+
key_multiplier=float(getattr(config, "key_multiplier", 1.0)),
2825+
attention_out_multiplier=float(getattr(config, "attention_out_multiplier", 1.0)),
2826+
attention_in_multiplier=float(getattr(config, "attention_in_multiplier", 1.0)),
2827+
ssm_multipliers=tuple(
2828+
float(value)
2829+
for value in (
2830+
getattr(config, "ssm_multipliers", None) or (1.0, 1.0, 1.0, 1.0, 1.0)
2831+
)
2832+
),
2833+
ssm_in_multiplier=float(getattr(config, "ssm_in_multiplier", 1.0)),
2834+
ssm_out_multiplier=float(getattr(config, "ssm_out_multiplier", 1.0)),
2835+
)
2836+
2837+
26942838
@dataclasses.dataclass
26952839
class GraniteMoeHybridConfig(BambaConfig):
26962840
"""Configuration for GraniteMoeHybrid: Mamba2+Attention hybrid with MoE on all layers.

‎src/mobius/_registry.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from mobius._configs import (
2626
BaseModelConfig,
2727
Eagle3Config,
28+
FalconH1Config,
2829
Gemma3nMultiModalConfig,
2930
Gemma4AssistantConfig,
3031
Gemma4Config,
@@ -140,6 +141,7 @@
140141
FalconCausalLMModel,
141142
MPTCausalLMModel,
142143
)
144+
from mobius.models.falcon_h1 import FalconH1ForCausalLM
143145
from mobius.models.fun_asr import FunASRForConditionalGeneration
144146
from mobius.models.gemma3n import Gemma3nCausalLMModel, Gemma3nMultiModalModel
145147
from mobius.models.glm_asr import GlmAsrForConditionalGeneration
@@ -450,6 +452,13 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
450452
"ernie4_5": ModelRegistration(ErnieCausalLMModel),
451453
"exaone4": ModelRegistration(ExaOne4CausalLMModel),
452454
"falcon": ModelRegistration(FalconCausalLMModel),
455+
"falcon_h1": ModelRegistration(
456+
FalconH1ForCausalLM,
457+
task="falcon-h1-text-generation",
458+
config_class=FalconH1Config,
459+
test_model_id="tiiuae/Falcon-H1-Tiny-90M-Base",
460+
family="falcon-h1",
461+
),
453462
"gemma": ModelRegistration(GemmaCausalLMModel),
454463
"gemma2": ModelRegistration(Gemma2CausalLMModel),
455464
"gemma3": ModelRegistration(Gemma3MultiModalModel, task="vision-language"),

‎src/mobius/components/_attention.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def __init__(
263263
self.num_attention_heads = config.num_attention_heads
264264
self.num_key_value_heads = config.num_key_value_heads
265265
self.scaling = scale if scale is not None else self.head_dim**-0.5
266+
self._key_multiplier = getattr(config, "key_multiplier", 1.0)
266267
# NoPE models leave ``partial_rotary_factor`` as ``None``; treat as
267268
# the inert 1.0 for the purpose of computing ``rotary_embedding_dim``
268269
# (which will itself be 0, i.e. no partial-RoPE splitting). The
@@ -325,6 +326,8 @@ def forward(
325326
query_states = self.q_proj(op, hidden_states)
326327
key_states = self.k_proj(op, hidden_states)
327328
value_states = self.v_proj(op, hidden_states)
329+
if not math.isclose(self._key_multiplier, 1.0):
330+
key_states = op.Mul(key_states, self._key_multiplier)
328331

329332
if self.q_norm is not None and self.k_norm is not None:
330333
if self._qk_norm_full:

0 commit comments

Comments
 (0)