Skip to content

Studio tests: pin that pip_install_try clears the torch probe memo too - #8796

Closed
danielhanchen wants to merge 1 commit into
mainfrom
studio-torch-probe-regression-tests
Closed

danielhanchen wants to merge 1 commit into
mainfrom
studio-torch-probe-regression-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #8779. Tests only, no source change.

#8779 memoizes the torch classification and clears it on a pip operation. Both entry points do that now, but only pip_install has a test, so the pip_install_try half can be removed and nothing goes red.

Why that half is the one worth pinning

_ensure_rocm_torch reinstalls the ROCm torch trio through pip_install_try (studio/install_python_stack.py, the Windows AMD path), and the repair paths run at two points with the torchao version probe between them:

lines what runs
4481-4484 _ensure_cuda_torch / _ensure_rocm_torch / _ensure_xpu_torch / _ensure_cpu_torch
4566-4567 _probe_installed_torch_version() then _select_torchao_spec(...)
4695-4698 the four repair paths again

A memo that survives the reinstall pins torchao against the torch that was just replaced, and _ensure_cpu_torch reads the same stale answer two lines after the install.

The tests

  • test_pip_install_try_invalidates_the_cache: probe, reinstall through pip_install_try, probe again, and the second call both re-spawns and reports the new build
  • test_the_torchao_probe_sees_the_reinstalled_torch: the same through _probe_installed_torch_version, which is the consumer that actually reads the stale value

Both fail with the _invalidate_torch_runtime_probe() call removed from pip_install_try, and pass with it.

Not added

The strict-decode half is already covered by test_undecodable_import_chatter_does_not_escape, which drives the real subprocess rather than a mock. I wrote a second pair for it before noticing, and dropped them as redundant.

Verification

  • tests/studio/install/ plus tests/studio/test_xpu_triton_swap.py: 2608 passed, 2 skipped
  • ruff check: clean

#8779 memoizes the torch classification and invalidates it on a pip
operation. Both entry points do that now, but only pip_install has a test,
so the pip_install_try half can be dropped without anything going red.

It is the half that matters on Windows AMD. _ensure_rocm_torch reinstalls
the ROCm torch trio through pip_install_try, and the repair paths run at
two points with the torchao version probe between them. A memo that
survives that install pins torchao against the torch that was just
replaced.

Two tests: the memo is cleared, and the torchao consumer specifically sees
the reinstalled version. Both fail with the invalidate call removed.

The decode half is already covered by
test_undecodable_import_chatter_does_not_escape, which drives the real
subprocess, so nothing is added there.
danielhanchen added a commit that referenced this pull request Aug 14, 2026
Folds in the one test #8796 had that this branch did not. The other two
there duplicate what is already here, so #8796 closes in favour of this.

_select_torchao_spec reads _probe_installed_torch_version() between the
two repair points, which makes it the consumer that would actually read
a memo left over from before a reinstall, and pin torchao against the
torch that was just replaced. The existing cases assert on
_probe_torch_runtime directly; this one goes through the accessor that
the torchao path really calls.

Fails with the _invalidate_torch_runtime_probe() line removed from
pip_install_try, along with the three siblings, and passes with it.
@danielhanchen

Copy link
Copy Markdown
Member Author

Closing in favour of #8795, which pins the same invariant on the same file.

The two overlap on test_pip_install_try_invalidates_the_cache. #8795 also carries the parametrised real-reinstall case and a test_every_installer_entry_point_invalidates guard that fails if a third pip entry point is ever added without invalidation, so it is the better base. The one test here that #8795 did not have, test_the_torchao_probe_sees_the_reinstalled_torch, is now on that branch, so no coverage is lost.

Verified there: 24 pass, and removing the _invalidate_torch_runtime_probe() line from pip_install_try fails 4 of them, the ported test among them.

danielhanchen added a commit that referenced this pull request Aug 14, 2026
…llers (#8795)

* Studio tests: pin the torch probe invalidation contract to both installers

#8779 made pip_install_try() drop the memoized torch classification, because it
installs the Windows AMD ROCm trio and a memo it does not clear can answer for
the build it just replaced. That fix shipped with no test: only pip_install()
was covered, so reverting the pip_install_try() line kept the suite green.

Three tests, each of which fails with that line removed:

- pip_install_try() drops the memo, mirroring the pip_install() case
- a real reinstall is really reclassified: two real torch packages on disk and a
  real probe subprocess either side of a real call into each installer, so the
  answer that replaces the memo is shown to come from the venv as it is now
  rather than from the mock that dropped it
- every function that builds a pip or uv install command invalidates. Read out
  of the module with ast rather than listed here, so a third installer helper
  cannot be added without either invalidating or failing this test

No production change.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Pin the torchao consumer to the reinstalled torch as well

Folds in the one test #8796 had that this branch did not. The other two
there duplicate what is already here, so #8796 closes in favour of this.

_select_torchao_spec reads _probe_installed_torch_version() between the
two repair points, which makes it the consumer that would actually read
a memo left over from before a reinstall, and pin torchao against the
torch that was just replaced. The existing cases assert on
_probe_torch_runtime directly; this one goes through the accessor that
the torchao path really calls.

Fails with the _invalidate_torch_runtime_probe() line removed from
pip_install_try, along with the three siblings, and passes with it.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: danielhanchen <[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.

1 participant