Repository navigation
Studio: check local single-file checkpoints without importing the diffusion stack - #15587
Conversation
|
This is a false positive. Retargeting those two local imports is the point of the PR (they must stop importing the diffusion stack), so nothing in the PR needs to change for this. The lint red is safe to merge past once the rest is green. |
|
Correction to my note above: the import-hoist check reports a third blocker here that I missed, and it is not a false positive. The two |
… moved is not a clash (#15622) `Source lint` blocks refactors that move helpers into a new module, because `scripts/verify_import_hoist.py` reads every re-pointed function-local import as a rename clash. Two open PRs are stuck on it today: - #15596 (moves the GGUF chat and compaction helpers out of `llama_cpp.py`): 63 `TARGET-CHANGED` blockers, e.g. `'_can_reset_epoch' ... ['from:core.inference.llama_cpp:_can_reset_epoch'] -> ['from:core.inference.chat_compaction:_can_reset_epoch']`. - #15587 (moves `resolve_local_single_file` into `diffusion_local_files.py`): 2 of the same. ## Cause `TARGET-CHANGED` exists to catch a same-name load that now resolves to a different object. Its only exemption is a module-level import removed and re-added in the same file. A refactor that moves a definition and updates `from old import N` inside a function to `from new import N` binds the same object, but neither import is module-level, so it is reported as a clash. ## Change `compare()` takes an optional `moved(old_target, new_target)` predicate. `main()` builds it from git: modules are resolved to files at the before and after refs, the same way the importing file would see them (relative imports against its package, absolute ones against its ancestor directories). A `TARGET-CHANGED` is downgraded to an INFO `MOVED` line only when every lost `from:old:N` pairs with exactly one gained `from:new:N` of the same name, and either: - both imports reach one definition, following top-level `from ... import` re-exports at their own ref (the old and new module re-export it); or - `N` was defined at the top level of the old module before, is defined at the top level of the new module after, and the old module no longer defines it, at most re-importing it from the new module. Anything else stays a blocker: a re-point to a different `N`, the old module keeping its own definition, or an alias rename across modules. The module-level relocation rule, the `HOISTED-IMPORT-UNUSED` check and its `__init__.py`-only `__all__` exemption are unchanged. ### When a re-point does not count as a move A re-pointed import keeps its TARGET-CHANGED blocker unless every one of the following holds: - the old and new targets name the same symbol, and each lost import pairs one-to-one with a gained import; - both modules resolve to exactly one file, meaning an absolute import is not ambiguous between roots, and a relative import does not climb to or past the repo root; - the destination did not bind the name before the change, and binds it exactly once now, unconditionally at module level. The last point treats a binding as ambiguous when any of these appears for the name: - a second binding site; - a binding inside an `if` / `try` / `with` / loop / `match` block, including `TYPE_CHECKING`; - a bare annotation; - `del`, `global`, `:=` (including in a lambda default), `except ... as`, or a match capture; - `import *`. ## Verification - `--self-test`: all cases pass, including three new ones (a re-point after a move, the same re-point when nothing moved, an alias rename across modules). - #15596 at its head against its merge base: main's verifier 63 blockers; this branch 0 blockers, 63 `MOVED`. - #15587: main's verifier 3 blockers; this branch 1, the `HOISTED-IMPORT-UNUSED` re-export in `diffusion.py`, which the existing rule keeps on purpose. - End to end through git refs in a scratch repo: a genuine move and a re-point through a shared re-export pass; a re-point to a different function of the same name, a move where the old module keeps its own definition, and an alias rename across modules all still fail.
…g (pytest 9.2) (#15638) ## Summary `studio/backend/tests/test_mcp_session_cache_reset_between_tests.py::test_the_next_test_starts_with_an_empty_cache_and_the_session_closed` has failed on the `(Python 3.13, g-r)` shard of #15587, #15593, #15601 and #15615 (`assert 0 == 1` on `_Session.closed`). ### Root cause CI now resolves pytest 9.2.0, and pytest-xdist 3.8.0 (the latest release) does not work with it: - `--dist loadgroup` keeps an `xdist_group` on one worker by rewriting `item._nodeid` to `<id>@<group>`. - pytest 9.2 builds `Item.nodeid` from a structured `_id` instead, so that write is lost. - Every grouped test is therefore scheduled like an ungrouped one. The MCP pair (and the other `*_reset_between_tests` pairs) only hold when both tests run on the same worker. With `-v`, the first test ran on `gw0` and the second on `gw3`. Minimal reproduction: ```python pytestmark = pytest.mark.xdist_group("g1") def test_one(): pass def test_two(): pass ``` `pytest -n 2 --dist loadgroup -v`: - pytest 9.1.1 reports `test_one@g1` and `test_two@g1`, both on `gw0`. - pytest 9.2.0 reports `test_one` on `gw0` and `test_two` on `gw1`. The same pytest release is behind the `torch._dynamo.config.* does not exist` failures (#15624 pins Backend CI below 9.2 for that; #15626 makes the suite tolerate it). ## Change This builds on #15624 (merged), which pins `'pytest<9.2'` in `studio-backend-ci.yml`, the only workflow that runs `--dist loadgroup`. - **`version-compat-ci.yml`**: `'pytest>=8'` becomes `'pytest>=8,<9.2'`. These lanes run the CPU-spoof fixtures that monkeypatch `torch._dynamo.config`, which pytest 9.2 deletes on undo. - **`tests/_shared/xdist_group_check.py`**, installed as a `trylast` `pytest_collection_modifyitems` hook in `tests/conftest.py` and `studio/backend/tests/conftest.py`: - On an xdist worker running `--dist loadgroup`, any test that carries an `xdist_group` mark but whose node id has no `@group` tag now fails with the reason. - Before, it would sometimes pass and sometimes fail depending on scheduling. If the pin is lifted before pytest-xdist catches up, the grouped tests fail by name with an explanation instead of flaking. - Raising a usage error at collection time would be swallowed into an xdist `INTERNALERROR`, so each affected test fails individually instead. - **`tests/test_xdist_group_check.py`**: unit tests for the check, the conftest wiring, and both pins (Backend CI from #15624 and version-compat from this PR). ## Testing Run on `studio/backend/tests/test_mcp_*.py` with `-n 4 --dist loadgroup`: - **pytest 9.1.1:** 2089 passed, twice. - **pytest 9.2.0:** the MCP pair failed in both runs. - **Serially on 9.2.0:** 2089 passed, so the failure needs xdist. With the check in place, the two grouped pair files under `-n 2 --dist loadgroup`: - **pytest 9.1.1:** 4 passed. - **pytest 9.2.0:** all 4 grouped tests fail with "--dist loadgroup did not tag this xdist_group test ...". `tests/test_xdist_group_check.py` with `tests/test_torch_config_guard.py` (from #15626) after merging main: 18 passed.
Codex Review SummaryThis 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. |
|
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". |
…e instead of re-exporting it from diffusion
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
1 similar comment
|
Codex Review: Didn't find any major issues. Bravo. 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". |
…o family matches [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Listing local models (
routes/models.py,_scan_models_dir) and catalog classification (hub/services/models/catalog_classification.py) only needresolve_local_single_file, a few lines of path checks, but they imported it fromcore.inference.diffusion. That pulled in the whole 15k-line diffusion module and about 80 sibling modules the first time a process listed a model folder.What changes
resolve_local_single_filemoves unchanged into a new light module,core/inference/diffusion_local_files.py, which only checks file paths.routes/models.py,catalog_classification.py, and the media-load paths (routes/inference.py,routes/video.py,media_locality.py,media_model_index.py).diffusion.pyno longer re-exports it (an ordinary-module re-export fails the import-hoist lint).diffusion.resolve_local_single_filenow patchdiffusion_local_files.resolve_local_single_file.Results
First folder scan in a fresh process (n=3 each):
This is paid once per process, on the first model list or catalog check.
Tests
studio/backend/tests/test_diffusion_local_files_light.py(2): listing a models folder through_scan_models_dir, and classifying it through_local_family_needles, each in a fresh process, find the checkpoint without importingcore.inference.diffusion. Both fail on main.Follow-up: catalog classification
Catalog classification also imported
core.inference.video(which pulls incore.inference.diffusion) before checking whether the model belongs to a video family. Both the local path (_local_model_task) and the cached repo path (_cached_repo_task) now import it only once a video family matches, so classification results are unchanged.Cached image repos still load the diffusion module for its trust check, as before.
The light-import tests now put the backend on the child's
sys.path(so they also pass withPYTHONSAFEPATH=1), have a timeout, and cover both classification paths end to end. The adapter folder comment was restored in the moved function.