Skip to content

Fix two environment-sensitive test failures (qwen_image golden tolerance, Gemma4 cache skip) - #553

Merged
justinchuby merged 2 commits into
mainfrom
justinchuby-fix-golden-tolerance-and-cache-skip
Aug 23, 2026
Merged

justinchuby merged 2 commits into
mainfrom
justinchuby-fix-golden-tolerance-and-cache-skip

Conversation

@justinchuby

Copy link
Copy Markdown
Member

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_golden

Root 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:

  • The divergence is stable and deterministic: identical value under OMP_NUM_THREADS=1 and =4, and byte-identical across runs. Not flaky.
  • It is a single isolated element moving in the last decimal place (1.5196e-6), not a broad shift — a logic bug would move many values or move one a lot.
  • Magnitude analysis: these tensors peak near |x| ≈ 3.3, where one float32 ULP is ≈ 2.4e-7. So atol=1e-6 was only ~4 ULP of headroom for a chain of one transformer layer + three scheduler steps + a VAE decode. The observed drift is ~6 ULP.
  • The sibling golden comparisons in the same test already sit at 6.3e-7 and 5.8e-7 against the same 1e-6 bound — i.e. the whole test was riding the float32 noise floor and would have tipped over on the next platform change regardless.

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 the 1e-4 this 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, including quant_conv (encoder side) and post_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_budget

Root 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:

  1. assert cached_config is not None on google/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 reports model_type == "gemma4_assistant".
  2. max(processor_cache.glob("*/processor_config.json"), ...) on google/gemma-4-E2B-it — would raise ValueError: max() arg is an empty sequence if 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 already pytest.skip.

Fix (surgical, confined to the cache lookup to minimise conflict with the schema PR):

  • The assistant config.json cross-check becomes conditional — still asserted when the repo is cached, skipped as a check when it is not.
  • Missing processor config now 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_type cross-check and the (1, 2520, 768) / 252 patch-budget parity. Without them it skips cleanly.

Verification

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 after
failed 8 6
passed 4613 4621

Remaining 6 are exactly the out-of-scope jsonschema.exceptions.ValidationError failures in comfyui_test.py / inference_metadata_test.py. No new failures.

lintrunner f --output oneline --all-files then lintrunner → ok No lint issues. Commit is signed off.

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]>
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 23, 2026 00:58
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 4f7e5c8 → 6228731

Model Sub-model Changes Status
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.skip cleanly 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.

Comment thread src/mobius/models/qwen_image_test.py Resolved
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 4f7e5c8 → 6228731

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby merged commit 77ade40 into main Aug 23, 2026
16 checks passed
@justinchuby
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants