Repository navigation
Fix two environment-sensitive test failures (qwen_image golden tolerance, Gemma4 cache skip) - #553
Merged
justinchuby merged 2 commits intoAug 23, 2026
Conversation
Two unrelated, long-standing failures on main, both defects in the tests rather than in the product. qwen_image golden tolerance: the golden L4/L5 comparisons in test_deterministic_l4_l5_image_edit_golden check a pure float32 diffusers chain against values recorded in #465 on a different BLAS backend, at rtol=atol=1e-6. Those tensors peak near |x| ~= 3.3, where one float32 ULP is ~2.4e-7, so 1e-6 is only ~4 ULP of headroom for a chain of one transformer layer, three scheduler steps and a VAE decode. The observed drift is a stable, single-element 1.52e-6 (~6 ULP) that does not move with OMP/MKL thread count, and the sibling comparisons already sit at 6e-7 and 7e-7 -- i.e. the whole test was riding the float32 noise floor, not regressing. Widen the golden tolerance to rtol=1e-5 / atol=5e-6 (~20 ULP at that magnitude), still two orders of magnitude tighter than the 1e-4 used for ONNX-vs-torch parity in the same test, so a real logic regression still fails. The "Weight ... not found in the model. Skipped applying." warnings this test emits are expected, not a second bug: the full VAE state dict is applied to both halves of the split encoder/decoder package, and every skipped name is skipped exactly once, so each weight does land in its own model. Gemma4 cached-processor test: the test reads two artifacts straight out of the local Hugging Face cache, but hard-asserted that google/gemma-4-E2B-it-assistant config.json was present, and would have raised ValueError from max() on an empty glob if the google/gemma-4-E2B-it processor_config.json was missing. Both are optional local cache state, so an uncached machine failed instead of degrading. Make the assistant config.json a conditional cross-check (still asserted when cached) and pytest.skip with a clear reason when the processor config is absent, matching how the sibling Qwen and Phi tests already handle offline caches. With both artifacts cached the test runs and passes rather than skipping. Suite goes from 8 failed / 4613 passed to 6 failed / 4621 passed; the remaining 6 are the onnx-genai schema drift failures fixed elsewhere. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes two environment-sensitive failures on main by adjusting test logic (not production code): it relaxes an overly tight golden tolerance in the Qwen Image diffusers-only golden test, and makes a Gemma4 metadata test robust to missing local Hugging Face cache artifacts.
Changes:
- Centralize and loosen the Qwen Image diffusers golden comparison tolerances across L4/L5 assertions.
- Make Gemma4 processor/config cache lookups conditional and
pytest.skipcleanly when artifacts are not present offline.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/mobius/models/qwen_image_test.py | Adds a shared golden tolerance constant and explanatory comment for diffusers-only golden comparisons. |
| src/mobius/integrations/onnx_genai/inference_metadata_test.py | Avoids hard-failing when optional HF cache artifacts are absent; skips with a clear reason instead. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Performance Comparison
|
Co-authored-by: Copilot Autofix powered by AI <[email protected]> Signed-off-by: Justin Chu <[email protected]>
justinchuby
deleted the
justinchuby-fix-golden-tolerance-and-cache-skip
branch
August 23, 2026 01:09
justinchuby
added a commit
that referenced
this pull request
Aug 23, 2026
…ive 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two unrelated, long-standing failures on
main. Both turned out to be defects in the tests, not in the product. Suite goes from 8 failed / 4613 passed to 6 failed / 4621 passed; the remaining 6 are the onnx-genai schema-drift failures being fixed in a separate PR.Failure 1 —
qwen_image_test.py::test_deterministic_l4_l5_image_edit_goldenRoot cause: float32 noise floor, not a numerical regression.
The failing assertion compares a pure PyTorch/diffusers chain against golden values recorded in #465 on a different BLAS backend — no ONNX involved — at
rtol=atol=1e-6.Evidence gathered before changing anything:
OMP_NUM_THREADS=1and=4, and byte-identical across runs. Not flaky.|x| ≈ 3.3, where one float32 ULP is ≈ 2.4e-7. Soatol=1e-6was only ~4 ULP of headroom for a chain of one transformer layer + three scheduler steps + a VAE decode. The observed drift is ~6 ULP.Fix: a principled, commented bound of
rtol=1e-5 / atol=5e-6(~20 ULP at the peak magnitude, ~3x the observed drift) applied to the three golden comparisons via a shared named constant. That is still two orders of magnitude tighter than the1e-4this same test uses for ONNX-vs-torch parity, so a genuine logic regression still fails. The ONNX-vs-reference assertions are untouched.On the
Weight '...' not found in the model. Skipped applying.warnings — these are expected, not a second bug. The test applies the full VAE state dict to both halves of the split encoder/decoder package (apply_weights(vae_package["encoder"], vae_weights)and again for"decoder"), so each half warns about the other's weights. Verified by counting: 90 skip warnings, and no weight name is skipped twice — every weight lands in exactly one of the two models, includingquant_conv(encoder side) andpost_quant_conv(decoder side). Noisy, but correct. No follow-up needed.Failure 2 —
inference_metadata_test.py::TestNativeVlmPackageMetadata::test_cached_gemma_processor_matches_emitted_patch_budgetRoot cause: a hard assert on optional local Hugging Face cache state.
The test reads two artifacts straight out of the local HF cache (deliberately offline-style, like its siblings), but handled absence badly in both places:
assert cached_config is not Noneongoogle/gemma-4-E2B-it-assistant/config.json— hard failure when uncached. This value is never used again; it is only a sanity cross-check that the assistant variant reportsmodel_type == "gemma4_assistant".max(processor_cache.glob("*/processor_config.json"), ...)ongoogle/gemma-4-E2B-it— would raiseValueError: max() arg is an empty sequenceif uncached. This is the artifact the test actually needs.Neither repo is fetched by the test or vendored; they just happened to be in the author's cache at #416. Both exist on the Hub, so this is genuinely environmental/optional, matching how
_onnx_genai_schema_path(), the Qwen test and the Phi test in this same file alreadypytest.skip.Fix (surgical, confined to the cache lookup to minimise conflict with the schema PR):
config.jsoncross-check becomes conditional — still asserted when the repo is cached, skipped as a check when it is not.pytest.skips with an explicit reason instead of crashing.Verified it does not degrade into a silent skip: I fetched both artifacts into the cache and re-ran — the test runs and passes, exercising all original assertions including the
model_typecross-check and the(1, 2520, 768)/252patch-budget parity. Without them it skips cleanly.Verification
Remaining 6 are exactly the out-of-scope
jsonschema.exceptions.ValidationErrorfailures incomfyui_test.py/inference_metadata_test.py. No new failures.lintrunner f --output oneline --all-filesthenlintrunner→ok No lint issues.Commit is signed off.