Skip to content

Tests: make the diffusion LM tests import inference on their own, count the diffusion shard - #17736

Merged
danielhanchen merged 2 commits into
mainfrom
ci-diffusion-shard-isolation
Nov 14, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci-diffusion-shard-isolation

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #17723, which moved test_diffusion* into its own (Python 3.13, diffusion) backend shard. Two things went red once that shard ran (seen on a staging run against current main):

  1. Repo tests (CPU, studio) and workflow-trigger lint:

    tests/studio/test_backend_ci_parallel_isolation.py::test_the_command_scan_sees_the_parallel_run_and_the_serial_steps
    AssertionError: expected fourteen parallel pytest runs, four shards of the backend matrix and ten of repo-cpu-tests ... assert 15 == 14
    

    That test pins the number of parallel pytest runs on purpose, so a new shard has to be stated there. Backend CI: run test_diffusion* in its own pytest shard #17723 updated test_ci_backend_pytest_shards.py but missed this one. My mistake.

  2. (Python 3.13, diffusion): five tests in studio/backend/tests/test_diffusion_lm_studio.py fail with PackageNotFoundError: No package metadata was found for unsloth_zoo:

    • test_frame_relay_throttles_and_never_raises_into_the_sampler
    • test_frame_relay_sends_zero_based_steps_and_honours_stop_sequences
    • test_frame_relay_cuts_frames_at_the_first_eos
    • test_diffusion_eos_ids_match_the_sampler_cut
    • test_chat_diffusion_load_refuses_an_unmarked_model_and_keeps_the_token_boundary

    They import core.inference.inference, which imports unsloth, and the backend job installs neither unsloth_zoo nor trl. They only passed in the old a-f shard because an earlier file on the same worker (test_audio_chat_load.py, test_chat_prompt_bos.py) had already imported that module with its own unsloth stubs and left it cached. In a shard of only test_diffusion* files that never happens. So these tests have depended on xdist scheduling since Studio: live denoising canvas for transformers diffusion LMs #13593; the split only made it deterministic.

Change

  • tests/studio/test_backend_ci_parallel_isolation.py: 15 parallel runs, 5 backend shards.
  • studio/backend/tests/test_diffusion_lm_studio.py: a small inference_mod fixture the five tests now take.
    • When unsloth_zoo is installed, or the module is already imported, it returns the real module. Nothing changes there.
    • Otherwise it stubs unsloth and unsloth.chat_templates (the same two names the other backend tests stub) through monkeypatch, and also drops the freshly imported core.inference.inference. So no later test inherits a module bound to these stubs.
    • The tests keep running in the backend job instead of being skipped there.

Testing

  • Locally, with diffusers, unsloth_zoo and trl hidden from import (the backend job's environment): test_diffusion_lm_studio.py, test_diffusion_int8_attention.py and test_diffusion_rocm_tag_detect.py on their own. The five tests fail on main with the same error and pass here. They also pass with the real packages installed.
  • The same files in one process, before and after test_audio_chat_load.py and test_chat_prompt_bos.py: 78 passed, 33 skipped in both orders.
  • Every test that reads studio-backend-ci.yml (15 files): 341 passed, 3 skipped. The isolation test fails on main.
  • test_backend_tests_stub_heavy_imports.py and test_sibling_imported_tests_import_their_helpers_top_level.py: pass.

The other failures on the new shard come from #17718 and are fixed in #17737.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T10:26:51.951014Z b435a5b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ef3f1519b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

monkeypatch.delitem(sys.modules, "core.inference.inference", raising = False)
return importlib.import_module("core.inference.inference")

P2 Badge Remove the stub-bound inference module during fixture teardown

When unsloth_zoo is absent and inference has not already been imported, the early-return guard guarantees that this delitem operates on a missing key. In that case pytest records no undo action, so the subsequent import remains in sys.modules after teardown, still bound to the temporary MagicMock loaders and chat-template helper even though the unsloth stubs themselves are restored. Subsequent calls to this fixture then take the cached-module branch and reuse those mocks, preserving the cross-test import contamination this fixture intends to prevent. Use an explicit teardown/finalizer to remove the newly imported module and restore its package attribute.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: b435a5b21c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit f294c54 into main Nov 14, 2026
@danielhanchen
danielhanchen deleted the ci-diffusion-shard-isolation branch November 14, 2026 10:29
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.

1 participant