Skip to content

Commit b65bbd9

Browse files
justinchubyCopilot
andauthored
Migrate onnx-genai metadata emitters to the current pipeline/speculative contract (#554)
Fixes six long-standing schema-conformance failures caused by mobius's legacy onnx-genai emitters drifting from the runtime's published JSON schema. ## Why the drift was invisible The conformance tests searched a couple of hard-coded local onnx-genai checkout paths and `pytest.skip`ped when none was found. CI has no such checkout, so **six tests never ran there**; on the machines that did have one, the result depended on whatever revision that clone happened to sit on. Two upstream contract redesigns accumulated unnoticed. ## The two contract redesigns 1. **`pipeline` is now `PipelineSpec`** — a single property, `workflow` (a typed SSA graph), with `additionalProperties: false`. The legacy emitters produced `{models, dataflow, strategy, phases}`, all of which the schema now rejects. 2. **`speculative` is now `SpeculativeContract`** — requires `{proposer, target, vocabulary, max_proposal_width}` and forbids every field of the old flat MTP block. The flat `SpeculatorConfig` that block was modelled on still exists upstream, but it describes a HuggingFace `config.json` section, not `InferenceMetadata.speculative`. ## What was migrated ### Diffusion — `build_diffusion_pipeline_metadata` Now emits the denoise loop explicitly: the solver, sigma/alpha schedule, timestep table, guidance combine and output clamp are real ONNX components built from mobius's policy library and shipped with the document. It **cannot** delegate to `build_diffusion_workflow_metadata`: the ComfyUI conversion path has no component graphs at all (it deliberately does not build or export them), and that builder derives everything from live `ir.Model`s. So the workflow is built directly, reusing `workflow_metadata`'s `_invoke` / `_publish_workflow_v1` and `mobius.generation`'s solver builders. The schedule is derived from the scheduler's own betas through the same diffusers-compatible helpers the package exporter uses, so a ComfyUI conversion and a package export of the same checkpoint describe the same dynamics. img2img's `start_step` lowers to a sliced schedule; the VAE `scaling_factor` and the sigma-space initial-state scale are emitted as explicit components. Three cases now **fail closed** instead of being silently mis-described: - an ancestral sampler (mobius ships no stochastic solver), - Karras/exponential sigma spacing (the workflow ships the sigma table as a constant, so a `use_karras_sigmas` hint is no longer sufficient), - a latent-only graph with no VAE decode. ### MTP — `write_mtp_speculator_metadata` Emits a `SpeculativeContract` anchored to the backbone's workflow: it registers the head as a workflow component, names the target by its declared `logits` port role, states the hidden handoff as `port_bindings.target_hidden_context` plus a `hidden_states` role on the target output, and completes the rollback capacity its own claim requires. It is declared `block`, not `chained`: a chained proposer must expose a `logits_output` carrying the next-token distribution, and this sidecar emits only `mtp_hidden` — the runtime decodes it through the target's shared LM head, which is why that initializer is listed in `shared_weights`. ### VLM `build_native_vlm_package_metadata` produces mobius's **internal** structural descriptor, not a publishable document — `build_vlm_workflow_metadata` already consumes it and republishes only `preprocessing` under a real `pipeline.workflow`. The actual bug was that `write_native_vlm_package_metadata` wrote that descriptor to `inference_metadata.yaml`. It now writes the workflow document, and the tests validate the published document instead of the descriptor. ### CI visibility The upstream schema is vendored under `src/mobius/integrations/onnx_genai/_schema/` and is the default, so conformance never skips and drift becomes a test failure. A local checkout is no longer consulted implicitly — one that is ahead of or behind `main` reintroduces exactly the machine-dependent result that hid this bug. Set `ONNX_GENAI_SCHEMA` to validate against a specific revision. Three further conformance tests (codec, speech-to-text, duplex workflows) were skipping for the same reason and now run. ## Tests Migrated in the same change rather than loosened: - `TestMtpSpeculatorMetadata::test_exact_schema_keys_and_values` asserts the new contract; `test_no_legacy_field_names` is repointed at the now-legacy field names. - A new MTP test anchors against a workflow `write_decoder_workflow_metadata` actually emits (which ships ~11 generated policy components), so target selection can't regress to "the only ONNX component". - New tests pin that the solver schedule comes from the scheduler's betas rather than a placeholder ramp. - Diffusion/ComfyUI tests assert workflow structure instead of the removed `strategy` block; scheduler facts that were duplicated into the document are asserted on the parsed `ComfyUIWorkflow` where they actually live. ## Verification Rebased onto current `main` (includes #552 and #553). ``` python -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q \ -k "not phi4mm and not apply_weights_unknown" -n auto ``` | | before (`main` at branch point) | after | |---|---|---| | full suite | 8 failed / 4613 passed | **0 failed / 4641 passed** | | `src/mobius/integrations/onnx_genai/` with `ONNX_GENAI_SCHEMA` at upstream `main` | 7 failed / 240 passed | **258 passed / 1 skipped** | Six of those eight failures are the schema-drift ones fixed here. The other two — `qwen_image_test.py::test_deterministic_l4_l5_image_edit_golden` and `TestNativeVlmPackageMetadata::test_cached_gemma_processor_matches_emitted_patch_budget` — were fixed by #553, which is now merged; this branch preserves both of its changes through the rebase. `lintrunner` is clean. ## Sequencing note `workflow_metadata.py` and `auto_export.py` are **not modified** (both are read from only), so this does not conflict with #551. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent 77ade40 commit b65bbd9

14 files changed

Lines changed: 7132 additions & 411 deletions

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ where = ["src"]
6060

6161
[tool.setuptools.package-data]
6262
"mobius.upstream_patches" = ["data/*/*/*.patch", "data/*/*/*.json", "data/*/*/*.md"]
63+
"mobius.integrations.onnx_genai" = ["_schema/*.json"]
6364

6465
[tool.setuptools.dynamic]
6566
version = { attr = "mobius.__version__" }

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
:func:`write_audio_codec_workflow_metadata` emits typed codec SSA, while
2323
:func:`write_tts_workflow_metadata` reports the current nested-loop induction
2424
contract blocker precisely.
25-
* **Diffusion pipelines** — :func:`write_diffusion_pipeline_metadata` emits an
26-
iterative pipeline for a denoiser plus optional VAE / text encoder.
25+
* **Diffusion pipelines** — :func:`write_diffusion_pipeline_metadata` emits a
26+
typed SSA denoise loop for a denoiser plus VAE and optional text encoder,
27+
shipping the sampler's solver/schedule components alongside it.
2728
2829
:func:`write_onnx_genai_config` is the unified entry point: it inspects the
2930
built package and dispatches to the matching writer, so
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Vendored onnx-genai metadata schema
2+
3+
`inference_metadata.schema.json` is a verbatim copy of onnx-genai's published
4+
`schema/inference_metadata.schema.json`, which that repo generates from its Rust
5+
types (`crates/onnx-genai-metadata/src/schema/`).
6+
7+
**Why it is vendored.** The schema conformance tests used to look for a local
8+
onnx-genai checkout and `pytest.skip` when they could not find one. CI has no
9+
such checkout, so every one of those tests skipped there and the emitters were
10+
only ever validated on the few developer machines that happened to have
11+
onnx-genai cloned — and then only against whatever revision that clone sat on.
12+
Two upstream contract redesigns (`pipeline` becoming a `PipelineSpec` whose only
13+
property is `workflow`, and `speculative` becoming a `SpeculativeContract`) went
14+
unnoticed for exactly that reason. Pinning the schema here makes the contract
15+
mobius targets an explicit, reviewable file and makes drift a CI failure rather
16+
than a silent skip.
17+
18+
**Updating it.** Copy the file from onnx-genai `main` and run the onnx-genai
19+
tests in this package:
20+
21+
```bash
22+
cp <onnx-genai>/schema/inference_metadata.schema.json \
23+
src/mobius/integrations/onnx_genai/_schema/
24+
python -m pytest src/mobius/integrations/onnx_genai/ -q
25+
```
26+
27+
Set `ONNX_GENAI_SCHEMA=/path/to/inference_metadata.schema.json` to validate
28+
against a different revision without editing this copy.
29+
30+
Synced from onnx-genai `10dfcd788` (2026-08-22).

0 commit comments

Comments
 (0)