Repository navigation
Studio tests: reset the diffusers attention backend and dynamo's error knobs between tests - #18080
Merged
Merged
Conversation
…r knobs between tests diffusers' set_attention_backend sets the process-wide active backend, so a test that pinned _native_cudnn left every later CPU forward on its xdist worker without an SDPA kernel. The DiT trainer's compile step sets dynamo's suppress_errors and a 64 recompile limit process-wide, which made test_diffusion_multigpu.py's warm-signature test fail whenever it shared a worker with test_diffusion_train_compile_toolchain.py. conftest now puts both back after each test.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
added a commit
to Etherll/unsloth
that referenced
this pull request
Nov 17, 2026
…source lint red since unslothai#18070) (unslothai#18086) ## Summary `Source lint (Python + shell + YAML + JSON + safety nets)` fails on main since unslothai#18070 (seen on the staging runs for unslothai#18080 and unslothai#18082, both on `8c99caf36c`): ``` 1 risky loader call site(s) not in the baseline: unsloth/models/rl.py:5481 [dynamic-import] import_module ``` unslothai#18070 finds TRL's `AsyncGRPOTrainer` at its 1.18 location as well as the older experimental one, which needs a second `importlib.import_module(name)` call site. `scripts/lint_risky_loaders.py` flags every new dynamic import until someone reviews it and records it in `scripts/risky_loaders_baseline.json`, and that entry was not added. ## Review `name` comes from a fixed tuple of two literal module names, `trl.trainer.async_grpo_trainer` and `trl.experimental.async_grpo.async_grpo_trainer`, and each is checked with `importlib.util.find_spec` first. No user or remote input reaches it. It is the same kind of site as the other TRL `import_module` entries already recorded for `rl.py`. ## Change One entry added to `scripts/risky_loaders_baseline.json`, written by `python scripts/lint_risky_loaders.py --update` (which marks it `REVIEW ME`), with the reason filled in. No other entry moves. ## Verification In a clean `git archive` of main: - `python scripts/lint_risky_loaders.py` exits 1 on main (the site above) and exits 0 with this change (`ok: 118 risky loader call site(s), all recorded`). - `tests/security/test_lint_risky_loaders.py`: 46 passed.
danielhanchen
added a commit
that referenced
this pull request
Nov 17, 2026
…t alias (teardown errors since #18080) (#18097) Since #18080 the Studio CPU shards (`rest`, `g-l`, `m-r`) error at teardown on any worker that imported `torch._dynamo` earlier. Seen on the staging runs of #18003, #18080 and #18090, e.g.: ``` ERROR at teardown of test_torchao_export_rejected_early_when_stubbed[torchao_fp8] torch/overrides.py:1778: has_torch_function = _add_docstr( RuntimeError: function '_has_torch_function' already has a docstring ERROR at teardown of test_versions_are_checked_before_imports AssertionError: imported a package the version check already rejected ERROR at teardown of test_a_broken_torch_import_is_retried_once_per_detection_epoch OSError: libcudart.so.12: cannot open shared object file ``` ## Cause The `_restore_dynamo_process_knobs` fixture from #18080 snapshots and restores `cache_size_limit`. On torch 2.6+ that entry is an alias of `recompile_limit`, and torch resolves an alias read with `importlib.import_module("torch._dynamo.config")`. Several tests take torch out of `sys.modules` and block imports to exercise the no-torch paths (`test_torchao_select.py`, `test_mlx_stack_blockers.py`, `test_polled_probe_costs.py`, `test_warm_window_review_fixes.py`, `test_hub_download_transport_auto.py`, `test_mlx_repair.py`). The fixture teardown runs before their monkeypatches are undone, so the alias read re-imported torch under the blocker. Those tests are correct, and the reset itself is still wanted; only the alias read was wrong. ## Fix `_dynamo_own_knobs(cfg)` keeps only the config's own entries (`_config[k].alias is None`). Restoring `recompile_limit` already covers `cache_size_limit` on new torch, and on older torch, where `cache_size_limit` is a real entry, it is still restored. Reading an own entry never imports. New `test_conftest_teardown_imports_nothing.py` imports `torch._dynamo`, takes torch out of `sys.modules` and makes `importlib.import_module` fail for torch, so any conftest teardown that imports torch errors. ## Verification Run locally with `torch._dynamo` already imported on the worker, as in CI: - main conftest: 14 teardown errors across `test_torchao_select.py`, `test_mlx_stack_blockers.py`, `test_polled_probe_costs.py`, `test_warm_window_review_fixes.py`, `test_hub_download_transport_auto.py` and `test_mlx_repair.py` (the CI ones), and the new test errors too. - this branch: all pass (196 and 188 passed in the two runs). - `test_process_state_reset_between_tests.py` still passes, so the knob reset still works.
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.
Summary
Two pieces of process-wide state leaked from one Studio backend test into later tests on the same xdist worker, so test results depended on which tests a worker happened to run first.
ModelMixin.set_attention_backendalso sets diffusers' process-wide active backend, which every processor without a backend of its own then uses.test_diffusion_flux3_strided_attn.pyset_native_cudnnthat way. After it, every CPU forward on that worker failed with "No viable backend for scaled_dot_product_attention" (17 tests intest_diffusion_minimax_h3_image.py, 3 intest_diffusion_flux3_qk_rope.py, plus FLUX.2 / FLUX.3 ConvRot, VAE canvas and regional-compile tests).torch._dynamo.config.suppress_errorsand a 64 recompile limit process-wide (test_diffusion_train_compile_toolchain.pyruns it).test_diffusion_multigpu.py::test_a_warm_signature_never_compiles_on_a_changed_numberturns onfail_on_recompile_limit_hit, so on a shared worker it died with "Dynamo configs suppress_error and fail_on_recompile_limit_hit can not both be active at the same time".conftest.pynow puts both back after every test.test_process_state_reset_between_tests.pyholds two ordered pairs, kept on one worker with anxdist_group. In each pair, the first test changes the state the way the real code does, and the second fails unless conftest restored it.Testing
Full diffusion CPU suite (
tests/test_diffusion_*.pyplus the H3 attention files),-n 12, same venv, merge base vs this branch:test_diffusion_compat_preflight.py, which depends on the local environment).test_a_warm_signature...cases failed only on this branch's first full run. That turned out to be the second leak: adding a test file changed which tests shared a worker. The repro on the merge base istest_diffusion_train_compile_toolchain.pyfollowed by that test in one process (2 failed); with this change it passes (7 passed).--dist loadgroup(as CI runs), the new file passes on this branch and both reset checks fail on the merge base.