Skip to content

Commit b75abd0

Browse files
justinchubyCopilot
andcommitted
Align workflow metadata batching contract
Remove retired profile-wide batch invariance production and its CTC graph metadata source. Keep unproven encoders fail closed by omitting component batch_capacity, sync the merged onnx-genai schema, regenerate affected fixtures, and add producer/schema conformance coverage. Signed-off-by: justinchuby <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 8513774 commit b75abd0

11 files changed

Lines changed: 2379 additions & 2700 deletions

File tree

‎src/mobius/integrations/onnx_genai/_schema/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ python -m pytest src/mobius/integrations/onnx_genai/ -q
2727
Set `ONNX_GENAI_SCHEMA=/path/to/inference_metadata.schema.json` to validate
2828
against a different revision without editing this copy.
2929

30-
Synced from onnx-genai `10dfcd788` (2026-08-22).
30+
Synced from onnx-genai `cb7baf924` (2026-08-25).

‎src/mobius/integrations/onnx_genai/_schema/inference_metadata.schema.json‎

Lines changed: 2286 additions & 2615 deletions
Large diffs are not rendered by default.

‎src/mobius/integrations/onnx_genai/ctc_runtime_test.py‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
build_ctc_asr_workflow_metadata,
1515
)
1616
from mobius.models.wav2vec2_ctc import Wav2Vec2ForCTCModel
17-
from mobius.tasks._ctc_asr import BATCH_PADDING_SENSITIVE_KEY, CTCAsrTask
17+
from mobius.tasks._ctc_asr import CTCAsrTask
1818

1919

2020
def _tiny_config(**overrides) -> MMSConfig:
@@ -69,21 +69,7 @@ def test_rejects_unknown_feature_normalization(self):
6969
_tiny_config(feat_extract_norm="batch")
7070

7171

72-
class TestBatchPaddingSensitivity:
73-
"""Padding sensitivity is a property of the feature normalization."""
74-
75-
def test_group_normalization_is_padding_sensitive(self):
76-
module = Wav2Vec2ForCTCModel(_tiny_config(feat_extract_norm="group"))
77-
assert module.batch_padding_sensitive is True
78-
79-
def test_layer_normalization_is_row_independent(self):
80-
module = Wav2Vec2ForCTCModel(_tiny_config(feat_extract_norm="layer"))
81-
assert module.batch_padding_sensitive is False
82-
83-
def test_task_records_sensitivity_on_the_built_graph(self):
84-
pkg = _build(_tiny_config(feat_extract_norm="group"))
85-
assert pkg["model"].metadata_props[BATCH_PADDING_SENSITIVE_KEY] == "true"
86-
72+
class TestArchitectureRouting:
8773
def test_config_class_survives_architecture_rerouting(self):
8874
# Config resolution reaches this module by re-routing model_type
8975
# "wav2vec2" to the "mms" registration, so the module must name its own
@@ -120,16 +106,21 @@ def test_transcription_profile_carries_a_ctc_decoding_contract(self, metadata):
120106
assert decoding["collapse_repeats"] is True
121107
assert (decoding["time_axis"], decoding["class_axis"]) == (1, 2)
122108

123-
def test_padding_sensitive_profile_binds_per_row_lengths(self, metadata):
109+
def test_frame_lengths_bind_the_ctc_decode(self, metadata):
124110
profile = metadata["profiles"]["transcription"]
125-
assert profile["batch_invariance"] == "padding_sensitive"
126111
assert profile["decoding"]["lengths"] == "frame_lengths"
127112
assert profile["outputs"]["frame_lengths"] == "frame_lengths"
128113

129-
def test_row_independent_when_feature_norm_is_layer(self):
130-
config = _tiny_config(feat_extract_norm="layer")
114+
@pytest.mark.parametrize("normalization", ["group", "layer"])
115+
def test_batch_permission_is_never_inferred_from_shape_or_normalization(
116+
self, normalization
117+
):
118+
config = _tiny_config(feat_extract_norm=normalization)
131119
metadata = build_ctc_asr_workflow_metadata(_build(config), config)
132-
assert metadata["profiles"]["transcription"]["batch_invariance"] == ("row_independent")
120+
profile = metadata["profiles"]["transcription"]
121+
component = metadata["pipeline"]["workflow"]["components"]["encoder"]
122+
assert "batch_invariance" not in profile
123+
assert "batch_capacity" not in component
133124

134125
def test_workflow_is_a_plain_sequence_with_no_generation_loop(self, metadata):
135126
steps = metadata["pipeline"]["workflow"]["steps"]

‎src/mobius/integrations/onnx_genai/encoder_embedding_metadata_test.py‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
from __future__ import annotations
1313

14+
import json
15+
from pathlib import Path
1416
from typing import Any
1517

1618
import pytest
19+
import yaml
1720

1821
from mobius._passes import RemoveDeadGraphInputsPass
1922
from mobius.integrations.onnx_genai.auto_export import (
@@ -42,6 +45,10 @@ def _protbert_package():
4245

4346

4447
_PACKAGES = {"esm2": _esm2_package, "protbert": _protbert_package}
48+
_FIXTURE_ROOT = (
49+
Path(__file__).resolve().parents[4] / "tests" / "fixtures" / "onnx_genai_workflows"
50+
)
51+
_SCHEMA_PATH = Path(__file__).with_name("_schema") / "inference_metadata.schema.json"
4552

4653

4754
@pytest.fixture(scope="module")
@@ -112,7 +119,14 @@ def test_pooling_uses_the_sequence_axis(self, metadata) -> None:
112119
workflow = metadata["pipeline"]["workflow"]
113120
assert profile["pooling"] == {"kind": "mean", "axis": 1, "normalize": False}
114121
assert "request.attention_mask" in workflow["inputs"]
115-
assert profile["batch_invariance"] == "row_independent"
122+
123+
def test_request_axis_does_not_grant_grouped_execution(self, metadata) -> None:
124+
"""Dynamic row shape is not evidence that co-batching preserves results."""
125+
profile = metadata["profiles"]["embedding"]
126+
component = metadata["pipeline"]["workflow"]["components"]["encoder"]
127+
assert "batch_invariance" not in profile
128+
assert "batch_capacity" not in component
129+
assert metadata["schema_version"] == "v1"
116130

117131
def test_every_bound_port_exists_in_the_artifact(self, metadata, package) -> None:
118132
graph = package["model"].graph
@@ -171,6 +185,22 @@ def test_the_export_entry_point_picks_the_encoder_builder(self, tmp_path) -> Non
171185
assert "max_output_tokens" not in text
172186

173187

188+
class TestBatchingContractConformance:
189+
def test_schema_exposes_only_component_batch_capacity(self) -> None:
190+
schema = json.loads(_SCHEMA_PATH.read_text(encoding="utf-8"))
191+
workflow_component = schema["$defs"]["WorkflowComponent"]["properties"]
192+
assert "batch_capacity" in workflow_component
193+
assert "batch_invariance" not in schema["$defs"]["TaskProfile"]["properties"]
194+
assert "continuous_batching" not in json.dumps(schema)
195+
196+
@pytest.mark.parametrize("name", sorted(_PACKAGES))
197+
def test_checked_in_hf_example_fixture_matches_generation(self, name, built) -> None:
198+
generated = build_encoder_embedding_workflow_metadata(built[name], built[name].config)
199+
fixture_path = _FIXTURE_ROOT / f"{name}_protein_embeddings" / "inference_metadata.yaml"
200+
fixture = yaml.safe_load(fixture_path.read_text(encoding="utf-8"))
201+
assert fixture == generated
202+
203+
174204
class TestRejections:
175205
def test_a_package_without_last_hidden_state_is_refused(self) -> None:
176206
package = _esm2_package()

‎src/mobius/integrations/onnx_genai/workflow_metadata.py‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
attach_package_facts,
128128
source_declared_value,
129129
)
130-
from mobius.tasks._ctc_asr import BATCH_PADDING_SENSITIVE_KEY
131130

132131

133132
class _NoAliasSafeDumper(yaml.SafeDumper):
@@ -225,6 +224,11 @@ def _component(
225224
Only ports in this producer's own vocabulary get a role, and state ports
226225
never need one: the group that carries them already names its pairs, which
227226
is also where the fixed-capacity scatter ABI is stated.
227+
228+
``batch_capacity`` is intentionally absent. A request-aligned or dynamic
229+
batch axis is structural shape information, not proof that co-batching
230+
preserves each request's result. Builders may add that semantic permission
231+
only after the complete grouped contract has been authored and validated.
228232
"""
229233
del effects
230234
named = [str(value.name) for value in (*model.graph.inputs, *model.graph.outputs)]
@@ -9957,35 +9961,13 @@ def build_ctc_asr_workflow_metadata(
99579961
if has_frame_lengths:
99589962
decoding["lengths"] = "frame_lengths"
99599963

9960-
# A feature extractor that reduces over the padded time axis makes a row's
9961-
# values depend on the width of the batch it was padded into. The fact is
9962-
# recorded by the task on the built graph; when nobody stated it we leave
9963-
# the field absent rather than claim rows are independent.
9964-
normalization = getattr(config, "feat_extract_norm", None)
9965-
if normalization == "group":
9966-
batch_invariance = "padding_sensitive"
9967-
elif normalization == "layer":
9968-
batch_invariance = "row_independent"
9969-
else:
9970-
recorded = model.metadata_props.get(BATCH_PADDING_SENSITIVE_KEY)
9971-
batch_invariance = (
9972-
None
9973-
if recorded is None
9974-
else ("padding_sensitive" if recorded == "true" else "row_independent")
9975-
)
9976-
99779964
profile: dict[str, Any] = {
99789965
"kind": "transcription",
99799966
"version": "1.0",
99809967
"requirement": "required",
99819968
"outputs": profile_outputs,
99829969
"decoding": decoding,
99839970
}
9984-
# The claim is only checkable when the package also publishes per-row
9985-
# lengths; without them a reader cannot isolate a row's valid region.
9986-
if batch_invariance == "row_independent" or has_frame_lengths:
9987-
if batch_invariance is not None:
9988-
profile["batch_invariance"] = batch_invariance
99899971

99909972
metadata: dict[str, Any] = {
99919973
"schema_version": "v1",
@@ -10187,7 +10169,6 @@ def build_encoder_embedding_workflow_metadata(
1018710169
"axis": 1,
1018810170
"normalize": False,
1018910171
}
10190-
profile["batch_invariance"] = "row_independent"
1019110172

1019210173
return {
1019310174
"schema_version": "v1",

‎src/mobius/models/wav2vec2.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,6 @@ def __init__(self, config: ArchitectureConfig):
397397
)
398398
self.encoder = encoder_class(config, eps=eps)
399399

400-
@property
401-
def batch_padding_sensitive(self) -> bool:
402-
"""Whether a row's outputs depend on the padded width of its batch.
403-
404-
``feat_extract_norm="group"`` puts a ``GroupNorm`` with one group per
405-
channel on the first convolution, which reduces over the *time* axis.
406-
Its statistics therefore include whatever padding was appended to reach
407-
the batch width, so co-batching rows of unequal length perturbs every
408-
frame of the shorter rows. ``"layer"`` reduces over channels instead
409-
and leaves rows independent.
410-
"""
411-
return getattr(self.config, "feat_extract_norm", None) == "group"
412-
413400
def frame_lengths(self, op: OpBuilder, attention_mask: ir.Value) -> ir.Value:
414401
"""Return the per-row valid frame count for a sample-level mask.
415402

‎src/mobius/tasks/_ctc_asr.py‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@
1919
from mobius._model_package import ModelPackage
2020
from mobius.tasks._base import ModelTask, _make_graph, _make_model
2121

22-
#: Graph metadata key recording whether a row's outputs depend on the padded
23-
#: width of its batch. Carried on the ONNX model so a metadata producer can
24-
#: publish the fact without knowing anything about the architecture, and so it
25-
#: survives a round trip through the serialized file.
26-
BATCH_PADDING_SENSITIVE_KEY = "mobius.batch_padding_sensitive"
27-
28-
29-
def _record_batch_padding_sensitivity(model: ir.Model, module: object) -> None:
30-
"""Copy a module's batch-padding sensitivity onto the built ONNX model.
31-
32-
Modules that do not answer the question leave the key absent, which readers
33-
must treat as unstated rather than as "rows are independent".
34-
"""
35-
sensitive = getattr(module, "batch_padding_sensitive", None)
36-
if isinstance(sensitive, bool):
37-
model.metadata_props[BATCH_PADDING_SENSITIVE_KEY] = "true" if sensitive else "false"
38-
3922

4023
class CTCAsrTask(ModelTask):
4124
"""Build ONNX graph for CTC-based ASR (raw waveform → frame logits).
@@ -88,9 +71,7 @@ def build(
8871
frame_lengths = frame_lengths_fn(builder.op, attention_mask)
8972
builder.add_output(frame_lengths, "frame_lengths")
9073

91-
model = _make_model(graph)
92-
_record_batch_padding_sensitivity(model, module)
93-
return ModelPackage({"model": model}, config=config)
74+
return ModelPackage({"model": _make_model(graph)}, config=config)
9475

9576

9677
class FeatureCTCAsrTask(ModelTask):

‎tests/canonical_workflow_contract_test.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727
import copy
2828
import glob
29+
import json
2930
import os
3031
import re
3132
from typing import Any
3233

34+
import jsonschema
3335
import onnx_ir as ir
3436
import pytest
3537
import yaml
@@ -54,6 +56,18 @@
5456
DEEP_LAYERS = 12
5557

5658
FIXTURE_ROOT = os.path.join(os.path.dirname(__file__), "fixtures", "onnx_genai_workflows")
59+
SCHEMA_PATH = os.path.join(
60+
os.path.dirname(__file__),
61+
"..",
62+
"src",
63+
"mobius",
64+
"integrations",
65+
"onnx_genai",
66+
"_schema",
67+
"inference_metadata.schema.json",
68+
)
69+
with open(SCHEMA_PATH, encoding="utf-8") as _schema_handle:
70+
ONNX_GENAI_SCHEMA = json.load(_schema_handle)
5771

5872

5973
def _text_config(**overrides: Any) -> ArchitectureConfig:
@@ -227,6 +241,12 @@ def test_the_workflow_is_where_a_package_describes_itself(self, package):
227241
_, metadata = package
228242
assert "workflow" in metadata["pipeline"]
229243

244+
def test_no_producer_emits_retired_batching_declarations(self, package):
245+
_, metadata = package
246+
serialized = yaml.safe_dump(metadata)
247+
assert "batch_invariance:" not in serialized
248+
assert "continuous_batching:" not in serialized
249+
230250
def test_no_package_states_its_graph_abi_a_second_time(self, package):
231251
"""The point of one representation is that there is no other one.
232252
@@ -831,6 +851,24 @@ def _metadata(directory: str) -> dict[str, Any]:
831851
) as handle:
832852
return yaml.safe_load(handle)
833853

854+
def test_no_fixture_contains_retired_batching_declarations(self, directory):
855+
serialized = yaml.safe_dump(self._metadata(directory))
856+
assert "batch_invariance:" not in serialized
857+
assert "continuous_batching:" not in serialized
858+
859+
def test_fixture_validates_against_current_onnx_genai_schema(self, directory):
860+
jsonschema.validate(self._metadata(directory), ONNX_GENAI_SCHEMA)
861+
862+
def test_fixture_matches_regenerated_metadata(
863+
self, directory, materialized_workflow_packages
864+
):
865+
relative = os.path.relpath(directory, FIXTURE_ROOT)
866+
regenerated = os.path.join(
867+
materialized_workflow_packages, relative, "inference_metadata.yaml"
868+
)
869+
with open(regenerated, encoding="utf-8") as handle:
870+
assert self._metadata(directory) == yaml.safe_load(handle)
871+
834872
@staticmethod
835873
def _artifact_root(directory: str, materialized: str) -> str:
836874
"""Where this package's graphs live once they have been generated."""

‎tests/fixtures/onnx_genai_workflows/esm2_protein_embeddings/inference_metadata.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ profiles:
1010
kind: mean
1111
axis: 1
1212
normalize: false
13-
batch_invariance: row_independent
1413
pipeline:
1514
workflow:
1615
manifest:

‎tests/fixtures/onnx_genai_workflows/protbert_protein_embeddings/inference_metadata.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ profiles:
1010
kind: mean
1111
axis: 1
1212
normalize: false
13-
batch_invariance: row_independent
1413
pipeline:
1514
workflow:
1615
manifest:

0 commit comments

Comments
 (0)