Skip to content

Commit d4957ef

Browse files
justinchubyCopilot
andcommitted
Preserve quantized MiniMax embeddings
Construct MiniMax token embeddings through the quantization-aware factory so untied packed tables import and tied packed heads share executable storage. Strengthen exact role and ORT coverage, and correct the runtime-only deferral documentation. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 66aebf2 commit d4957ef

3 files changed

Lines changed: 61 additions & 10 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,11 @@ real-artifact full-logit and stateful-generation parity.
593593
- `static_cache=True` and non-hybrid task dispatch are rejected for these mixed
594594
state ABIs.
595595

596-
`minimax-01` remains deferred before config extraction because its pinned
597-
Lightning schedule and decay/scaling semantics do not match the current graph.
596+
`minimax-01` graph import supports its exact pinned Lightning schedule,
597+
decay/scaling semantics, recurrent state, and mixed full-attention cache.
598+
Runtime packaging remains deferred because the released schema cannot represent
599+
that heterogeneous state ABI or bounded rollback snapshots; this is tracked by
600+
[`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605).
598601
PLaMo2 has a dedicated alternating Mamba1/attention graph and strict GGUF
599602
tensor closure. Its mixed per-layer recurrent/KV runtime package remains
600603
deferred to [`onnxruntime/mobius#605`](https://github.com/onnxruntime/mobius/issues/605).

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

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ def _write_minimax_gguf(
12751275
path: Path,
12761276
*,
12771277
quantized: bool,
1278+
quantized_embedding: bool = False,
12781279
omit: str | None = None,
12791280
extra: str | None = None,
12801281
malformed_shape: str | None = None,
@@ -1352,7 +1353,7 @@ def add_q4(name: str, shape: tuple[int, ...]) -> None:
13521353
)
13531354
writer.add_tensor(name, raw, raw_dtype=GGMLQuantizationType.Q4_0)
13541355

1355-
add_float("token_embd.weight", (vocab, hidden))
1356+
(add_q4 if quantized_embedding else add_float)("token_embd.weight", (vocab, hidden))
13561357
add_float("output_norm.weight", (hidden,))
13571358
add_float("output.weight", (vocab, hidden))
13581359
projection = add_q4 if quantized else add_float
@@ -5525,9 +5526,27 @@ def test_quantized_source_preserves_exact_projection_roles(self, tmp_path: Path)
55255526
from mobius.integrations.gguf import build_from_gguf
55265527

55275528
path = tmp_path / "minimax-q4.gguf"
5528-
_write_minimax_gguf(path, quantized=True)
5529+
_write_minimax_gguf(path, quantized=True, quantized_embedding=True)
55295530
model = build_from_gguf(path, keep_quantized=True)["model"]
5530-
assert sum(node.op_type == "MatMulNBits" for node in model.graph) >= 19
5531+
assert sum(node.op_type == "GatherBlockQuantized" for node in model.graph) == 1
5532+
expected_projection_weights = {
5533+
"model.layers.0.self_attn.qkv_proj.weight",
5534+
"model.layers.0.self_attn.output_gate.weight",
5535+
"model.layers.0.self_attn.o_proj.weight",
5536+
"model.layers.1.self_attn.q_proj.weight",
5537+
"model.layers.1.self_attn.k_proj.weight",
5538+
"model.layers.1.self_attn.v_proj.weight",
5539+
"model.layers.1.self_attn.o_proj.weight",
5540+
*{
5541+
f"model.layers.{layer}.mlp.experts.{expert}.{projection}_proj.weight"
5542+
for layer in range(2)
5543+
for expert in range(2)
5544+
for projection in ("gate", "up", "down")
5545+
},
5546+
}
5547+
assert {
5548+
node.inputs[1].name for node in model.graph if node.op_type == "MatMulNBits"
5549+
} == expected_projection_weights
55315550
assert all(
55325551
"norm" not in node.inputs[1].name
55335552
for node in model.graph
@@ -5549,6 +5568,38 @@ def test_tied_output_uses_embedding_storage(self, tmp_path: Path) -> None:
55495568
assert "lm_head.weight" not in model.graph.initializers
55505569
assert "model.embed_tokens.weight" in model.graph.initializers
55515570

5571+
def test_quantized_tied_output_uses_embedding_storage(self, tmp_path: Path) -> None:
5572+
from mobius._testing.ort_inference import OnnxModelSession
5573+
from mobius.integrations.gguf import build_from_gguf
5574+
5575+
path = tmp_path / "minimax-q4-tied.gguf"
5576+
_write_minimax_gguf(
5577+
path,
5578+
quantized=True,
5579+
quantized_embedding=True,
5580+
omit="output.weight",
5581+
)
5582+
model = build_from_gguf(path, keep_quantized=True)["model"]
5583+
op_types = [node.op_type for node in model.graph]
5584+
assert op_types.count("GatherBlockQuantized") == 1
5585+
assert op_types.count("MatMulNBits") == 20
5586+
assert (
5587+
sum(name.endswith("embed_tokens.qweight") for name in model.graph.initializers)
5588+
== 1
5589+
)
5590+
assert not any(name.startswith("lm_head.") for name in model.graph.initializers)
5591+
tied_head = next(
5592+
node for node in reversed(model.graph) if node.op_type == "MatMulNBits"
5593+
)
5594+
assert tied_head.inputs[2].name == "model.embed_tokens.scales"
5595+
assert tied_head.inputs[3].name == "model.embed_tokens.zero_points"
5596+
session = OnnxModelSession(model)
5597+
try:
5598+
outputs = session.run(self._inputs(np.asarray([[1, 2]], np.int64)))
5599+
finally:
5600+
session.close()
5601+
assert np.isfinite(outputs["logits"]).all()
5602+
55525603
def test_cli_build(self, tmp_path: Path) -> None:
55535604
from mobius.__main__ import main
55545605
from mobius._model_package import ModelPackage

‎src/mobius/models/minimax.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
from mobius._configs import ArchitectureConfig, MiniMaxConfig
2828
from mobius.components import (
2929
Attention,
30-
Embedding,
3130
MoELayer,
3231
RMSNorm,
3332
create_attention_bias,
3433
initialize_rope,
3534
)
3635
from mobius.components._lightning_attention import LightningAttention
37-
from mobius.models.base import CausalLMModel
36+
from mobius.models.base import CausalLMModel, embedding_for_config
3837
from mobius.models.moe import _quantized_linear_class, _rename_moe_expert_weights
3938

4039

@@ -161,9 +160,7 @@ def __init__(self, config: ArchitectureConfig):
161160
if config.head_dim <= 0:
162161
raise ValueError("MiniMax head_dim must be explicit and positive")
163162
self._dtype = config.dtype
164-
self.embed_tokens = Embedding(
165-
config.vocab_size, config.hidden_size, config.pad_token_id
166-
)
163+
self.embed_tokens = embedding_for_config(config)
167164
self.layers = nn.ModuleList(
168165
[MiniMaxDecoderLayer(config, layer_idx=i) for i in range(config.num_hidden_layers)]
169166
)

0 commit comments

Comments
 (0)