Repository navigation
Commit b65bbd9
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
File tree
- src/mobius/integrations/onnx_genai
- _schema
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
0 commit comments