Skip to content

Commit a49c3a3

Browse files
justinchubyCopilot
andcommitted
Own MiniMax Music3 workflow defaults in the config adapter
The hierarchical-audio workflow config (semantic-token boundary, guidance schedule, chunked flow plan, prompt template) carries runtime facts that cannot be read back from the exported neural graphs. Previously the builder required these to arrive from an explicit caller argument or an external `mobius_workflow.json` source-model asset, else it failed closed -- too strict, since mobius is the canonical model-name -> model-information registry and already owns MiniMax token constants here. Move the Music 3 defaults into the diffusers config-adapter layer, following the existing `from_diffusers` prior art: - Add named `MINIMAX_MUSIC3_*` workflow defaults + a `MiniMaxMusic3WorkflowConfig` adapter in `_configs.py`. Its `from_diffusers` builds the typed, generic `HierarchicalAudioWorkflowConfig` from source component configs (the global decoder's context window) plus the mobius-owned defaults, with provenance comments. A divergent checkpoint overrides any field. - Select the adapter by pipeline class in the builder via a small `_resolve_hierarchical_workflow_config` helper: an explicit `workflow_config` argument always wins; otherwise mobius supplies the adapter defaults; an unrecognised hierarchical topology still fails closed (marked so ONNX GenAI metadata emission stops with an instruction). Remove the `mobius_workflow.json` asset loader and `HIERARCHICAL_AUDIO_WORKFLOW_ASSET`. - Keep the generic metadata writer fully model-agnostic: zero model-name/class checks and no MiniMax literals; it validates normalized fields and the two token ids against the graph's global logits width. - Drive the checked-in hierarchical_audio validation fixture through the new adapter (byte-identical output), and add adapter/resolution tests proving default ownership, context-window generalization, explicit-argument override, and fail-closed behavior for unknown pipelines. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
1 parent 29cf64a commit a49c3a3

5 files changed

Lines changed: 336 additions & 155 deletions

File tree

‎src/mobius/integrations/diffusers/_builder.py‎

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,37 +56,54 @@
5656
"QwenImageEditPlusPipeline": "qwen_image_edit",
5757
}
5858

59-
#: Optional source-model asset naming a pipeline's model-agnostic workflow
60-
#: configuration. When present at the requested revision it supplies the
61-
#: semantic facts a hierarchical-audio workflow cannot derive from its graphs.
62-
#: The builder never ships or defaults these values; the checkpoint publisher
63-
#: does, keeping the config out of mobius and off any model/class-name branch.
64-
HIERARCHICAL_AUDIO_WORKFLOW_ASSET = "mobius_workflow.json"
6559

60+
def _pipeline_workflow_adapters() -> dict[str, type]:
61+
"""Map a pipeline class to the mobius adapter that owns its workflow config.
6662
67-
def _load_source_workflow_config(
68-
model_id: str,
69-
roles: dict[str, str],
70-
*,
71-
revision: str | None,
63+
A hierarchical-audio pipeline cannot describe its ONNX GenAI execution from
64+
the exported graphs alone (semantic-token boundary, guidance schedule,
65+
chunked flow plan, prompt template). Mobius owns those model-specific
66+
defaults in the config-adapter layer -- exactly like the ``from_diffusers``
67+
component adapters -- and selects the adapter here by pipeline class, so the
68+
generic metadata writer stays model-agnostic. Returned lazily to keep the
69+
``_configs`` import off module load.
70+
"""
71+
from mobius.integrations.diffusers._configs import MiniMaxMusic3WorkflowConfig
72+
73+
return {"MiniMaxMusic3ModularPipeline": MiniMaxMusic3WorkflowConfig}
74+
75+
76+
def _resolve_hierarchical_workflow_config(
77+
pipeline_class: str,
78+
workflow_roles: dict[str, str],
79+
component_configs: dict[str, dict],
80+
workflow_config: HierarchicalAudioWorkflowConfig | None,
7281
) -> HierarchicalAudioWorkflowConfig | None:
73-
"""Load a hierarchical-audio workflow config from a source-model asset.
82+
"""Resolve the workflow config for a hierarchical-audio pipeline.
7483
75-
Reads a well-defined :data:`HIERARCHICAL_AUDIO_WORKFLOW_ASSET` from the
76-
source repository at the requested revision. The asset carries only the
77-
model-agnostic semantic fields; the structural role map is supplied by the
78-
builder from the graphs it actually produced. Returns ``None`` when no asset
79-
is present so the caller can fail closed instead of inventing defaults.
80-
"""
81-
from mobius.integrations.onnx_genai import HierarchicalAudioWorkflowConfig
84+
Precedence:
8285
83-
data = _load_optional_diffusers_json(
84-
model_id, HIERARCHICAL_AUDIO_WORKFLOW_ASSET, revision=revision
85-
)
86-
if not data:
87-
return None
88-
fields = {key: value for key, value in data.items() if key not in ("kind", "components")}
89-
return HierarchicalAudioWorkflowConfig(components=dict(roles), **fields)
86+
1. An explicit caller ``workflow_config`` always wins (override).
87+
2. Otherwise mobius supplies the defaults it owns for a recognised pipeline
88+
through its config adapter, selected by pipeline class.
89+
3. When neither is available the result is ``None`` so the caller can fail
90+
closed rather than invent semantic values.
91+
92+
In every non-``None`` case the built graphs' structural role map is
93+
authoritative and replaces the config's ``components`` field, so the caller
94+
can pass a config whose roles are placeholders.
95+
"""
96+
resolved = workflow_config
97+
if resolved is None:
98+
adapter = _pipeline_workflow_adapters().get(pipeline_class)
99+
if adapter is not None:
100+
resolved = adapter.from_diffusers(
101+
components=dict(workflow_roles),
102+
component_configs=component_configs,
103+
)
104+
if resolved is not None:
105+
resolved = dataclasses.replace(resolved, components=dict(workflow_roles))
106+
return resolved
90107

91108

92109
def _init_diffusers_class_map() -> None:
@@ -495,12 +512,13 @@ def build_diffusers_pipeline(
495512
execution_provider: Target execution provider for EP-aware graph optimization.
496513
workflow_config: Optional typed, model-agnostic workflow description for
497514
pipelines whose ONNX GenAI execution cannot be derived from the graphs
498-
alone (currently hierarchical audio). When omitted, the builder looks
499-
for a source-model workflow asset at the requested revision. When
500-
neither is available the graphs are still built, but the package is
501-
marked so ONNX GenAI metadata emission fails closed with an
502-
instruction to supply the config rather than being misclassified.
503-
Never selected by pipeline/model/class name.
515+
alone (currently hierarchical audio). When omitted, mobius supplies the
516+
defaults it owns for a recognised pipeline via its config adapter. When
517+
neither a caller argument nor a registered adapter is available the
518+
graphs are still built, but the package is marked so ONNX GenAI
519+
metadata emission fails closed with an instruction to supply the config
520+
rather than being misclassified. The generic metadata writer never
521+
selects values by pipeline/model/class name.
504522
505523
Returns:
506524
A :class:`ModelPackage` containing the built component model(s).
@@ -645,9 +663,9 @@ def load_optional_component_json(component_name: str, filename: str) -> dict:
645663

646664
# Structural role extraction (model-building layer): map each recognized
647665
# component class to the structural role it plays so a hierarchical-audio
648-
# pipeline's graphs can be wired to a workflow. This never selects semantic
649-
# values by class name -- those come only from ``workflow_config`` or a
650-
# source-model asset below.
666+
# pipeline's graphs can be wired to a workflow. This maps only class -> role;
667+
# the semantic values come from an explicit ``workflow_config`` argument or
668+
# the pipeline's mobius config adapter resolved below.
651669
role_specs = {
652670
"Qwen3ForCausalLM": {
653671
"global_decoder": "",
@@ -675,24 +693,21 @@ def load_optional_component_json(component_name: str, filename: str) -> dict:
675693
from mobius.integrations.onnx_genai import HIERARCHICAL_AUDIO_ROLES
676694

677695
# A complete role set means the built graphs form a hierarchical-audio
678-
# topology. Resolve the workflow config only from an explicit argument or a
679-
# pinned source-model asset -- never a mobius default or a class-name
680-
# lookup. When neither is available the graphs still build and
681-
# ``workflow_kind`` marks the package so ONNX GenAI metadata emission fails
682-
# closed with an instruction to supply the config.
696+
# topology. An explicit ``workflow_config`` argument always wins (caller
697+
# override); otherwise mobius supplies the model-specific defaults it owns as
698+
# the canonical registry, selecting the config adapter by pipeline class --
699+
# never by a class-name branch inside the generic metadata writer. When no
700+
# adapter is registered for the pipeline and no argument was given, the
701+
# graphs still build and ``workflow_kind`` marks the package so ONNX GenAI
702+
# metadata emission fails closed with an instruction to supply the config.
683703
is_hierarchical_audio = workflow_roles.keys() >= HIERARCHICAL_AUDIO_ROLES
684-
resolved_workflow_config = workflow_config
685-
if is_hierarchical_audio:
686-
if resolved_workflow_config is None:
687-
resolved_workflow_config = _load_source_workflow_config(
688-
model_id, workflow_roles, revision=revision
689-
)
690-
if resolved_workflow_config is not None:
691-
# The graph names the builder produced are authoritative, so wire
692-
# the structural role map onto whatever semantic config was supplied.
693-
resolved_workflow_config = dataclasses.replace(
694-
resolved_workflow_config, components=dict(workflow_roles)
695-
)
704+
resolved_workflow_config = (
705+
_resolve_hierarchical_workflow_config(
706+
pipeline_class, workflow_roles, component_configs, workflow_config
707+
)
708+
if is_hierarchical_audio
709+
else None
710+
)
696711

697712
package.config = DiffusersPipelineConfig(
698713
source_model_id=model_id,

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

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020
_load_diffusers_component_config,
2121
_load_diffusers_pipeline_index,
2222
_load_optional_diffusers_json,
23-
_load_source_workflow_config,
2423
_resolve_diffusers_component_source,
24+
_resolve_hierarchical_workflow_config,
2525
build_diffusers_pipeline,
2626
)
27+
from mobius.integrations.diffusers._configs import (
28+
MINIMAX_MUSIC3_AUDIO_CODE_OFFSET,
29+
MINIMAX_MUSIC3_AUDIO_END_TOKEN_ID,
30+
MINIMAX_MUSIC3_GLOBAL_CONTEXT,
31+
MINIMAX_MUSIC3_SEMANTIC_VOCAB_SIZE,
32+
MINIMAX_MUSIC3_UNCONDITIONAL_TOKEN_ID,
33+
MiniMaxMusic3WorkflowConfig,
34+
)
2735
from mobius.integrations.onnx_genai import HierarchicalAudioWorkflowConfig
2836

2937
# ── Helpers ──────────────────────────────────────────────────────────────
@@ -116,53 +124,96 @@ def test_hierarchical_workflow_config_fails_closed_on_invalid_input(overrides, m
116124
_hierarchical_workflow_config(**overrides)
117125

118126

119-
def test_load_source_workflow_config_reads_pinned_asset():
120-
"""A pinned source-model asset supplies the semantic facts; roles come from graphs."""
127+
def test_minimax_workflow_adapter_applies_owned_defaults():
128+
"""The mobius adapter fills the typed config from Music 3 defaults it owns."""
121129
roles = _hierarchical_workflow_config().components
122-
asset = {
123-
"semantic_vocabulary_start": 2048,
124-
"semantic_vocabulary_size": 32,
125-
"stop_token_id": 7,
126-
"unconditional_token_id": 9,
127-
"semantic_guidance_scale": 2.0,
128-
"local_guidance_scale": 1.5,
129-
"flow_guidance_scale": 1.7,
130-
"sampling_top_k": 40,
131-
"chunk_frames": 150,
132-
"chunk_hop": 75,
133-
"flow_steps": 12,
134-
"carry_length": 100,
135-
"crop_left_latents": 50,
136-
"crop_right_latents": 150,
137-
"max_prompt_tokens": 4000,
138-
"max_audio_frames": 8000,
139-
"global_context": 256,
140-
"target_sample_rate": 44100,
141-
"unconditional_replace_from": 1,
142-
"unconditional_preserve_trailing": 2,
143-
"prompt_segments": [{"literal": "<audio>"}],
144-
}
145-
with patch(
146-
"mobius.integrations.diffusers._builder._load_optional_diffusers_json",
147-
return_value=asset,
148-
):
149-
resolved = _load_source_workflow_config("fake/model", dict(roles), revision=None)
130+
config = MiniMaxMusic3WorkflowConfig.from_diffusers(
131+
components=dict(roles),
132+
component_configs={"decoder": {"max_position_embeddings": 4096}},
133+
)
134+
assert isinstance(config, HierarchicalAudioWorkflowConfig)
135+
# Semantic constants come from the mobius-owned defaults, not the writer.
136+
assert config.semantic_vocabulary_start == MINIMAX_MUSIC3_AUDIO_CODE_OFFSET
137+
assert config.semantic_vocabulary_size == MINIMAX_MUSIC3_SEMANTIC_VOCAB_SIZE
138+
assert config.stop_token_id == MINIMAX_MUSIC3_AUDIO_END_TOKEN_ID
139+
assert config.unconditional_token_id == MINIMAX_MUSIC3_UNCONDITIONAL_TOKEN_ID
140+
# The context window is derived from the source language config.
141+
assert config.global_context == 4096
142+
assert config.components == dict(roles)
143+
assert config.prompt_segments # non-empty prompt template
144+
145+
146+
@pytest.mark.parametrize("max_positions", [2048, 8192])
147+
def test_minimax_workflow_adapter_generalizes_context(max_positions):
148+
"""A divergent language config flows through to the derived context window."""
149+
roles = _hierarchical_workflow_config().components
150+
config = MiniMaxMusic3WorkflowConfig.from_diffusers(
151+
components=dict(roles),
152+
component_configs={"decoder": {"max_position_embeddings": max_positions}},
153+
)
154+
assert config.global_context == max_positions
155+
156+
157+
def test_minimax_workflow_adapter_context_fallback():
158+
"""When the source omits the context window the adapter uses its named default."""
159+
roles = _hierarchical_workflow_config().components
160+
config = MiniMaxMusic3WorkflowConfig.from_diffusers(
161+
components=dict(roles),
162+
component_configs={},
163+
)
164+
assert config.global_context == MINIMAX_MUSIC3_GLOBAL_CONTEXT
165+
166+
167+
def test_resolve_workflow_config_explicit_argument_overrides_defaults():
168+
"""An explicit caller config wins over the mobius adapter defaults."""
169+
roles = _hierarchical_workflow_config().components
170+
override = _hierarchical_workflow_config(
171+
semantic_vocabulary_start=2048,
172+
stop_token_id=7,
173+
flow_steps=12,
174+
target_sample_rate=44100,
175+
)
176+
resolved = _resolve_hierarchical_workflow_config(
177+
"MiniMaxMusic3ModularPipeline",
178+
dict(roles),
179+
{"decoder": {"max_position_embeddings": 4096}},
180+
override,
181+
)
150182
assert resolved is not None
183+
# The caller's divergent values survive; the adapter defaults are not used.
151184
assert resolved.semantic_vocabulary_start == 2048
185+
assert resolved.stop_token_id == 7
152186
assert resolved.flow_steps == 12
153187
assert resolved.target_sample_rate == 44100
154-
# The structural role map is supplied by the builder, not the asset.
188+
# The built graphs' structural role map is authoritative.
155189
assert resolved.components == dict(roles)
156190

157191

158-
def test_load_source_workflow_config_returns_none_when_asset_absent():
159-
"""No asset means fail closed at the caller, not an invented default."""
192+
def test_resolve_workflow_config_uses_adapter_defaults():
193+
"""Without an explicit config, mobius supplies the pipeline's owned defaults."""
160194
roles = _hierarchical_workflow_config().components
161-
with patch(
162-
"mobius.integrations.diffusers._builder._load_optional_diffusers_json",
163-
return_value={},
164-
):
165-
assert _load_source_workflow_config("fake/model", dict(roles), revision=None) is None
195+
resolved = _resolve_hierarchical_workflow_config(
196+
"MiniMaxMusic3ModularPipeline",
197+
dict(roles),
198+
{"decoder": {"max_position_embeddings": 4096}},
199+
None,
200+
)
201+
assert resolved is not None
202+
assert resolved.semantic_vocabulary_start == MINIMAX_MUSIC3_AUDIO_CODE_OFFSET
203+
assert resolved.global_context == 4096
204+
assert resolved.components == dict(roles)
205+
206+
207+
def test_resolve_workflow_config_fails_closed_for_unknown_pipeline():
208+
"""A hierarchical topology with no registered adapter fails closed (None)."""
209+
roles = _hierarchical_workflow_config().components
210+
resolved = _resolve_hierarchical_workflow_config(
211+
"SomeUnknownAudioPipeline",
212+
dict(roles),
213+
{"decoder": {"max_position_embeddings": 4096}},
214+
None,
215+
)
216+
assert resolved is None
166217

167218

168219
def _fake_pipeline_index(

0 commit comments

Comments
 (0)