Skip to content

Commit c98ee9e

Browse files
justinchubyCopilot
andauthored
Add dedicated PLaMo2 model and GGUF import (#612)
## Summary - add a dedicated PLaMo2 graph with alternating Mamba1 selective-scan and local-attention layers - implement fused per-head `[z_h|x_h]` projection, normalized B/C/dt recurrence, fused QKV/QK norms/RoPE, fused SwiGLU, and sandwich residual norms - add heterogeneous recurrent/KV state threading with bounded sliding-window KV caches and deterministic replay/reorder/rollback semantics - add strict GGUF v3 metadata/tensor validation, exact shape-derived attention widths, folded-norm handling, and exact float/Q4 preservation rules - register the architecture, document support, and defer ORT GenAI packaging to #605 ## Reference pins - llama.cpp: `8d9af256337d1a501250f9bbf4c0859a654bddd6` - `pfnet/plamo-2-1b`: `92c75fd6eea9018bcb9c33ee8921589febe071fa` ## Validation - `2598 passed` — full GGUF suite - `26 passed` — focused PLaMo2 graph/model/import suite - `7107 passed, 52 skipped` — broad non-integration suite; only the two pre-existing `glm_moe_dsa` shape/checker failures remain - focused lint passes - pinned full 1B configuration builds (16 layers, 249 initializers, 33 outputs) - two independent reviews plus a final verification review completed with all findings resolved ## Runtime verdict Graph construction and GGUF import are supported. Released ORT GenAI cannot faithfully represent the heterogeneous recurrent/KV state ABI, so runtime packaging remains deferred to #605. The smallest public checkpoint is approximately 5.16 GB; this PR does not claim real-checkpoint full-logit or deterministic-generation parity. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 2b46fc0 commit c98ee9e

20 files changed

Lines changed: 2036 additions & 14 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 7 additions & 5 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': 89, 'rejected': 3, 'supported': 55}; importable: 53; quantized import: {'rejected': 12, 'supported': 135}; runtime: {'deferred': 144, 'rejected': 3} |
18+
| Architectures | 147 | graph verdicts: {'deferred': 88, 'rejected': 3, 'supported': 56}; importable: 54; 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` |
@@ -457,7 +457,7 @@ before graph construction or durable output.
457457
| `phi3` | — | model=`phi3`; tensor=`phi3` | 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. |
458458
| `phimoe` | — | model=`phimoe`; module=`phimoe_gguf`; tensor=`llama`+`phi3`+`moe_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. |
459459
| `plamo` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | PLaMo uses one RMSNorm feeding attention and FFN in parallel, fixed grouped-query geometry, and converter-specific Q/output projection shuffles. Sequential Llama topology and direct external tensor reuse would both be incorrect. |
460-
| `plamo2` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | The pinned PLaMo2 loader requires a dedicated fused-QKV Mamba1/attention graph with sandwich norms and offset transforms that Mobius does not have. |
460+
| `plamo2` | — | model=`plamo2`; tensor=`plamo2` | not claimed | config=supported; tensor_map=supported; graph=supported; runtime=deferred; quantized_import=supported | The dedicated graph and GGUF importer preserve PLaMo2's alternating Mamba1/attention layers and mixed state ABI, but released ORT GenAI cannot represent heterogeneous per-layer state. Runtime packaging remains deferred to onnxruntime/mobius#605. |
461461
| `plamo3` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | PLaMo3 requires fused QKV and fused SwiGLU, four norm sites with architecture-specific offset transforms, Q/K norm before RoPE, and alternating full/sliding attention state. Mobius has no exact iSWA schedule or value transform. |
462462
| `plm` | — | none (fails before config extraction) | audited-direct-loader-conditional-union | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | PLM uses latent KV projections and normalization with shared RoPE keys, expanded K/V state, tied output, and a non-gated ReLU-squared FFN. Generic MLA cache dimensions do not supply the missing graph or tensor contract. |
463463
| `pockettts` | — | none (fails before config extraction) | not claimed | config=deferred; tensor_map=deferred; graph=deferred; runtime=deferred; quantized_import=supported | The primary GGUF is only PocketTTS's transformed causal CALM backbone: its embedding table contains folded learned conditioning rows and its duplicated embedding output is not a semantic LM head. Voice encoding, continuous 32-D flow generation, EOS scoring, and the stateful 24-kHz Mimi decoder live in a required pockettts_spkenc/pockettts_gen mmproj bundle that Mobius cannot import. Registering the backbone as text generation or TTS would expose the wrong I/O contract, so standalone conversion is refused before graph construction. |
@@ -583,9 +583,11 @@ 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` 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.
586+
`minimax-01` remains deferred before config extraction because its pinned
587+
Lightning schedule and decay/scaling semantics do not match the current graph.
588+
PLaMo2 has a dedicated alternating Mamba1/attention graph and strict GGUF
589+
tensor closure. Its mixed per-layer recurrent/KV runtime package remains
590+
deferred to [`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605).
589591

590592
Falcon-H1 graph/import support is dedicated rather than aliased to Falcon. Every
591593
layer exposes `(key, value, conv_state, ssm_state)` in that order. Static cache is

‎src/mobius/_configs/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
NemotronHConfig,
5656
NemotronParseConfig,
5757
ParakeetCTCConfig,
58+
Plamo2Config,
5859
Qwen35MtpConfig,
5960
Sam2Config,
6061
SegformerConfig,
@@ -133,6 +134,7 @@
133134
"NemotronParseConfig",
134135
"NemotronHConfig",
135136
"ParakeetCTCConfig",
137+
"Plamo2Config",
136138
"QuantizationConfig",
137139
"Qwen35MtpConfig",
138140
"RoPEConfig",

‎src/mobius/_configs/_base.py‎

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,152 @@ def from_transformers(cls, config, parent_config=None) -> FalconH1Config:
28352835
)
28362836

28372837

2838+
@dataclasses.dataclass
2839+
class Plamo2Config(ArchitectureConfig):
2840+
"""Configuration for PLaMo2 alternating Mamba/attention decoder layers."""
2841+
2842+
attention_head_counts: tuple[int, ...] = ()
2843+
attention_kv_head_counts: tuple[int, ...] = ()
2844+
mamba_num_heads: int = 32
2845+
mamba_d_state: int = 64
2846+
mamba_d_conv: int = 4
2847+
mamba_dt_rank: int = 128
2848+
mamba_group_count: int = 0
2849+
attention_window_size: int = 2048
2850+
use_predefined_initial_state: bool = False
2851+
2852+
def __post_init__(self) -> None:
2853+
if self.hidden_act != "silu":
2854+
raise ValueError("PLaMo2 supports only hidden_act='silu'")
2855+
if not math.isclose(self.rms_norm_eps, 1e-6, rel_tol=0.0, abs_tol=1e-12):
2856+
raise ValueError("PLaMo2 requires rms_norm_eps=1e-6")
2857+
if self.mamba_group_count != 0:
2858+
raise ValueError("PLaMo2 supports only ssm.group_count=0")
2859+
if self.use_predefined_initial_state:
2860+
raise ValueError("PLaMo2 predefined initial state is unsupported")
2861+
if len(self.attention_head_counts) != self.num_hidden_layers:
2862+
raise ValueError(
2863+
"PLaMo2 attention_head_counts must contain exactly num_hidden_layers entries"
2864+
)
2865+
if len(self.attention_kv_head_counts) != self.num_hidden_layers:
2866+
raise ValueError(
2867+
"PLaMo2 attention_kv_head_counts must contain exactly num_hidden_layers entries"
2868+
)
2869+
layer_types: list[str] = []
2870+
for layer, (heads, kv_heads) in enumerate(
2871+
zip(self.attention_head_counts, self.attention_kv_head_counts)
2872+
):
2873+
if kv_heads == 0:
2874+
if heads != 0:
2875+
raise ValueError(
2876+
f"PLaMo2 layer {layer} has head_count={heads} but head_count_kv=0"
2877+
)
2878+
layer_types.append("mamba")
2879+
else:
2880+
if heads <= 0 or heads % kv_heads:
2881+
raise ValueError(
2882+
f"PLaMo2 layer {layer} has invalid attention head geometry "
2883+
f"head_count={heads}, head_count_kv={kv_heads}"
2884+
)
2885+
if heads != self.num_attention_heads or kv_heads != self.num_key_value_heads:
2886+
raise ValueError(
2887+
"PLaMo2 currently requires one shared attention geometry across "
2888+
"all attention layers"
2889+
)
2890+
layer_types.append("full_attention")
2891+
if (
2892+
not layer_types
2893+
or "mamba" not in layer_types
2894+
or "full_attention" not in layer_types
2895+
):
2896+
raise ValueError("PLaMo2 requires both Mamba and attention layers")
2897+
self.layer_types = layer_types
2898+
if self.head_dim <= 0 or self.hidden_size != self.num_attention_heads * self.head_dim:
2899+
raise ValueError("PLaMo2 hidden_size must equal num_attention_heads * head_dim")
2900+
if self.mamba_num_heads <= 0:
2901+
raise ValueError("PLaMo2 mamba_num_heads must be positive")
2902+
if self.mamba_d_state <= 0 or self.mamba_d_conv <= 1 or self.mamba_dt_rank <= 0:
2903+
raise ValueError(
2904+
"PLaMo2 Mamba state, convolution, and dt dimensions must be positive"
2905+
)
2906+
if self.attention_window_size <= 0:
2907+
raise ValueError("PLaMo2 attention_window_size must be positive")
2908+
2909+
@property
2910+
def mamba_inner_size(self) -> int:
2911+
return self.mamba_num_heads * self.head_dim
2912+
2913+
@property
2914+
def mamba_head_dim(self) -> int:
2915+
return self.head_dim
2916+
2917+
@classmethod
2918+
def from_transformers(cls, config, parent_config=None) -> Plamo2Config:
2919+
base = ArchitectureConfig.from_transformers(config, parent_config)
2920+
fields = _shallow_fields(base)
2921+
fields["hidden_act"] = getattr(config, "hidden_act", None) or "silu"
2922+
fields["rope_type"] = getattr(config, "rope_type", None) or "default"
2923+
fields["rope_theta"] = float(
2924+
getattr(config, "rope_local_theta", getattr(config, "rope_theta", 10_000.0))
2925+
)
2926+
fields["head_dim"] = int(getattr(config, "hidden_size_per_head", base.head_dim))
2927+
fields["partial_rotary_factor"] = 1.0
2928+
if getattr(config, "full_attention_idx", None):
2929+
raise ValueError("PLaMo2 full_attention_idx layers are unsupported")
2930+
layers = base.num_hidden_layers
2931+
explicit_heads = getattr(config, "attention_head_counts", None)
2932+
explicit_kv_heads = getattr(config, "attention_kv_head_counts", None)
2933+
if explicit_heads is not None or explicit_kv_heads is not None:
2934+
if explicit_heads is None or explicit_kv_heads is None:
2935+
raise ValueError(
2936+
"PLaMo2 per-layer attention head arrays must be supplied together"
2937+
)
2938+
head_counts = tuple(int(value) for value in explicit_heads)
2939+
kv_head_counts = tuple(int(value) for value in explicit_kv_heads)
2940+
else:
2941+
mamba_enabled = bool(getattr(config, "mamba_enabled", True))
2942+
mamba_step = int(getattr(config, "mamba_step", 2))
2943+
if mamba_enabled and mamba_step <= 1:
2944+
raise ValueError("PLaMo2 mamba_step must be greater than one")
2945+
2946+
def is_mamba(layer: int) -> bool:
2947+
if not mamba_enabled:
2948+
return False
2949+
if layers <= mamba_step // 2:
2950+
return layer != layers - 1
2951+
return layer % mamba_step != mamba_step // 2
2952+
2953+
head_counts = tuple(
2954+
0 if is_mamba(i) else base.num_attention_heads for i in range(layers)
2955+
)
2956+
kv_head_counts = tuple(
2957+
0 if is_mamba(i) else base.num_key_value_heads for i in range(layers)
2958+
)
2959+
2960+
return cls(
2961+
**fields,
2962+
attention_head_counts=head_counts,
2963+
attention_kv_head_counts=kv_head_counts,
2964+
mamba_num_heads=int(getattr(config, "mamba_num_heads", 32)),
2965+
mamba_d_state=int(getattr(config, "mamba_d_state", 64)),
2966+
mamba_d_conv=int(getattr(config, "mamba_d_conv", 4)),
2967+
mamba_dt_rank=int(
2968+
getattr(config, "mamba_dt_rank", max(64, base.hidden_size // 16))
2969+
),
2970+
mamba_group_count=int(getattr(config, "mamba_group_count", 0)),
2971+
attention_window_size=int(
2972+
getattr(
2973+
config,
2974+
"attention_window_size",
2975+
getattr(config, "sliding_window", 2048),
2976+
)
2977+
),
2978+
use_predefined_initial_state=bool(
2979+
getattr(config, "use_predefined_initial_state", False)
2980+
),
2981+
)
2982+
2983+
28382984
@dataclasses.dataclass
28392985
class GraniteMoeHybridConfig(BambaConfig):
28402986
"""Configuration for GraniteMoeHybrid: Mamba2+Attention hybrid with MoE on all layers.

‎src/mobius/_registry.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
MuseGlimmerConfig,
3838
NemotronParseConfig,
3939
ParakeetCTCConfig,
40+
Plamo2Config,
4041
SenseNovaU1Config,
4142
WhisperConfig,
4243
)
@@ -104,6 +105,7 @@
104105
Phi4SigLIPModel,
105106
PhiCausalLMModel,
106107
PhiMoEGGUFCausalLMModel,
108+
Plamo2ForCausalLM,
107109
Qwen2MoECausalLMModel,
108110
Qwen2VLCausalLMModel,
109111
Qwen3CausalLMModel,
@@ -459,6 +461,13 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
459461
test_model_id="tiiuae/Falcon-H1-Tiny-90M-Base",
460462
family="falcon-h1",
461463
),
464+
"plamo2": ModelRegistration(
465+
Plamo2ForCausalLM,
466+
task="plamo2-text-generation",
467+
config_class=Plamo2Config,
468+
test_model_id="pfnet/plamo-2-1b",
469+
family="plamo2",
470+
),
462471
"gemma": ModelRegistration(GemmaCausalLMModel),
463472
"gemma2": ModelRegistration(Gemma2CausalLMModel),
464473
"gemma3": ModelRegistration(Gemma3MultiModalModel, task="vision-language"),
@@ -952,6 +961,7 @@ def _create_default_registry() -> ModelRegistry:
952961
"llama": "meta-llama/Llama-3.2-1B",
953962
"mistral": "mistralai/Mistral-7B-v0.1",
954963
"qwen2": "Qwen/Qwen2.5-0.5B",
964+
"plamo2": "pfnet/plamo-2-1b",
955965
"cohere": "CohereForAI/c4ai-command-r7b-12-2024",
956966
"cohere2": "CohereForAI/c4ai-command-r7b-12-2024",
957967
"cosmos3_edge": "nvidia/Cosmos3-Edge",

‎src/mobius/integrations/gguf/_arch_registry.py‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,13 +1161,32 @@
11611161
),
11621162
GGUFArchitectureSpec(
11631163
gguf_arch="plamo2",
1164-
config=Support.DEFERRED,
1165-
tensor_map=Support.DEFERRED,
1166-
graph=Support.DEFERRED,
1164+
model_type="plamo2",
1165+
config_key_map="plamo2",
1166+
config_postprocessor="plamo2",
1167+
tensor_map_recipe=("plamo2",),
1168+
tensor_processor="plamo2",
1169+
required_metadata=(
1170+
"context_length",
1171+
"embedding_length",
1172+
"block_count",
1173+
"feed_forward_length",
1174+
"attention.head_count",
1175+
"attention.head_count_kv",
1176+
"attention.layer_norm_rms_epsilon",
1177+
"rope.freq_base",
1178+
"ssm.conv_kernel",
1179+
"ssm.inner_size",
1180+
"ssm.state_size",
1181+
"ssm.time_step_rank",
1182+
"ssm.group_count",
1183+
),
11671184
runtime=Support.DEFERRED,
11681185
reason=(
1169-
"The pinned PLaMo2 loader requires a dedicated fused-QKV Mamba1/attention "
1170-
"graph with sandwich norms and offset transforms that Mobius does not have."
1186+
"The dedicated graph and GGUF importer preserve PLaMo2's alternating "
1187+
"Mamba1/attention layers and mixed state ABI, but released ORT GenAI "
1188+
"cannot represent heterogeneous per-layer state. Runtime packaging "
1189+
"remains deferred to onnxruntime/mobius#605."
11711190
),
11721191
),
11731192
GGUFArchitectureSpec(

‎src/mobius/integrations/gguf/_arch_registry_test.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#: Number of importable architectures. Pinned so that adding support is a
5858
#: deliberate act that also updates the documented support matrix, and so that
5959
#: accidentally losing an architecture is a failure rather than a silence.
60-
_EXPECTED_SUPPORTED_COUNT = 53
60+
_EXPECTED_SUPPORTED_COUNT = 54
6161
_FINAL_CENSUS_CLOSURE = frozenset(
6262
{
6363
"afmoe",
@@ -174,6 +174,7 @@
174174
"olmoe",
175175
"phi3",
176176
"phimoe",
177+
"plamo2",
177178
"qwen2",
178179
"qwen2moe",
179180
"qwen3",

0 commit comments

Comments
 (0)