Skip to content

Studio tests: reset the diffusers attention backend and dynamo's error knobs between tests - #18080

Merged
danielhanchen merged 1 commit into
mainfrom
studio-test-flux3-strided-attn-leak
Nov 17, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-test-flux3-strided-attn-leak

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

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.

  • diffusers attention backend. ModelMixin.set_attention_backend also sets diffusers' process-wide active backend, which every processor without a backend of its own then uses. test_diffusion_flux3_strided_attn.py set _native_cudnn that way. After it, every CPU forward on that worker failed with "No viable backend for scaled_dot_product_attention" (17 tests in test_diffusion_minimax_h3_image.py, 3 in test_diffusion_flux3_qk_rope.py, plus FLUX.2 / FLUX.3 ConvRot, VAE canvas and regional-compile tests).
  • dynamo error knobs. The DiT trainer's compile step sets torch._dynamo.config.suppress_errors and a 64 recompile limit process-wide (test_diffusion_train_compile_toolchain.py runs it). test_diffusion_multigpu.py::test_a_warm_signature_never_compiles_on_a_changed_number turns on fail_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.py now puts both back after every test. test_process_state_reset_between_tests.py holds two ordered pairs, kept on one worker with an xdist_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_*.py plus the H3 attention files), -n 12, same venv, merge base vs this branch:

failed passed
merge base 67 21838
this branch 38 21870
  • Fixed: 29 failures that only appeared through the leaks.
  • Unchanged: the other 36 fail identically on both sides (mostly test_diffusion_compat_preflight.py, which depends on the local environment).
  • Not a regression: two 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 is test_diffusion_train_compile_toolchain.py followed by that test in one process (2 failed); with this change it passes (7 passed).
  • New tests: with --dist loadgroup (as CI runs), the new file passes on this branch and both reset checks fail on the merge base.

…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.
@danielhanchen danielhanchen self-assigned this Nov 17, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T05:38:03.998796Z 39fac47 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 39fac47ea3

ℹ️ 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 30f883a into main Nov 17, 2026
@danielhanchen
danielhanchen deleted the studio-test-flux3-strided-attn-leak branch November 17, 2026 05:49
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.
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