Skip to content

[inductor][test] Keep the Inductor cache dir off sys.path in subprocess tests - #205060

Closed
georgehong wants to merge 1 commit into
pytorch:mainfrom
georgehong:export-D132158104
Closed

georgehong wants to merge 1 commit into
pytorch:mainfrom
georgehong:export-D132158104

Conversation

@georgehong

@georgehong georgehong commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary: The subprocess tests in test/inductor/test_gpu_cpp_wrapper.py ran with their Inductor cache dir as the working directory, which Python puts first on sys.path, so a cache entry directory could shadow a real module. Depending on the generated code's hashes, an entry such as z3/ can shadow the z3 package, which made test_lazy_compile_kernel_name_collision_across_modules fail with #199309 in some environments. Keep the cache in an inductor_cache/ subdirectory instead. Test-only change.

Test Plan: CI

Differential Revision: D132158104

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

…ss tests

Summary: The subprocess tests in `test/inductor/test_gpu_cpp_wrapper.py` ran with their Inductor cache dir as the working directory, which Python puts first on `sys.path`, so a cache entry directory could shadow a real module. Depending on the generated code's hashes, an entry such as `z3/` can shadow the `z3` package, which made `test_lazy_compile_kernel_name_collision_across_modules` fail with pytorch#199309 in some environments. Keep the cache in an `inductor_cache/` subdirectory instead. Test-only change.

Test Plan: CI

Differential Revision: D132158104
@pytorch-bot

pytorch-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

Three subprocess tests in test/inductor/test_gpu_cpp_wrapper.py now run from a
temp directory and keep the Inductor cache in a `<tmp>/inductor_cache`
subdirectory, so cache entries stay off the child's sys.path. Recommendation:
Approve. The review calls the fix correct and complete, and both of its points
are non-blocking: one on comment wording, one on style.

Findings (2):

[minor] test/inductor/test_gpu_cpp_wrapper.py:1067
Non-blocking: the new comment and the PR description get the failure mechanism
slightly wrong. The comment says a cache subdirectory such as `z3/` "would
shadow that module". Cache subdirs (codecache.py `get_path`, `basename[1:3]`)
have no `__init__.py`, so Python can only treat them as namespace-package
portions. The path finder picks a regular package anywhere on sys.path over a
namespace portion, so an installed `z3` still wins and nothing is shadowed. The
real failure happens when z3 is not installed: `import z3` returns an empty
namespace package instead of raising ImportError.
torch/fx/experimental/validator.py:30 then gets past its `try: import z3` guard
and raises AttributeError at line 66 on `z3.ExprRef`, which the `except
ImportError` at line 651 doesn't catch. Suggested wording: "a cache subdir such
as `z3/` would import as an empty namespace package, defeating `try: import z3 /
except ImportError` checks."

[minor] test/inductor/test_gpu_cpp_wrapper.py:1287
Non-blocking: mixed path styles. `cache_dir` is built with `os.path.join` and
the next line builds `script_path` with `Path(tmp_dir) / ...`. Using one style
for both lines would read more uniformly.

Reviewed commit: 5dc11ca

Review run

🐛 Report a bad review

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/205060

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5dc11ca with merge base 3886d18 (image):
💚 Looks good so far! There are no failures yet. 💚

🟢 GREEN LIGHT - PR approved to be merged without human review:

  • Triviality
    • Test changes: only test/inductor/test_gpu_cpp_wrapper.py changes, making three subprocess tests deterministic by keeping cache dirs off sys.path
  • Correctness
    • Each test now sets TORCHINDUCTOR_CACHE_DIR to tmp_dir/inductor_cache and runs the subprocess with cwd=tmp_dir, so cache entries like z3/ can no longer shadow modules
    • All three former cwd=cache_dir sites are updated; os and Path are already imported
  • Preservation
    • No assertions, skips, or expected values changed; the tests' subprocess scripts are untouched

reason: clean
Reviewed commit: 5dc11ca

Inference job

🐛 Report a wrong verdict

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-codesync

meta-codesync Bot commented Nov 15, 2026

Copy link
Copy Markdown

@georgehong has exported this pull request. If you are a Meta employee, you can view the originating Diff in D132158104.

@pytorchbot pytorchbot added the in progress PR is being worked on by the author, until the automated review accepts it label Nov 15, 2026
@pytorchgreenlight pytorchgreenlight Bot added the GL/approved Approved by GreenLight label Nov 15, 2026
@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 15, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review of 5dc11ca: nothing blocking; ready for human review.

Three subprocess tests in test/inductor/test_gpu_cpp_wrapper.py now run from a temp directory and keep the Inductor cache in a &lt;tmp&gt;/inductor_cache subdirectory, so cache entries stay off the child's sys.path. Recommendation: Approve. The review calls the fix correct and complete, and both of its points are non-blocking: one on comment wording, one on style.

⚪ 2 non-blocking findings

# cwd first, and a cache subdir such as "z3/" would shadow that module.

Non-blocking: the new comment and the PR description get the failure mechanism slightly wrong. The comment says a cache subdirectory such as z3/ "would shadow that module". Cache subdirs (codecache.py get_path, basename\[1:3\]) have no __init__.py, so Python can only treat them as namespace-package portions. The path finder picks a regular package anywhere on sys.path over a namespace portion, so an installed z3 still wins and nothing is shadowed. The real failure happens when z3 is not installed: import z3 returns an empty namespace package instead of raising ImportError. torch/fx/experimental/validator.py:30 then gets past its try: import z3 guard and raises AttributeError at line 66 on z3.ExprRef, which the except ImportError at line 651 doesn't catch. Suggested wording: "a cache subdir such as z3/ would import as an empty namespace package, defeating try: import z3 / except ImportError checks."


cache_dir = os.path.join(tmp_dir, "inductor_cache")

Non-blocking: mixed path styles. cache_dir is built with os.path.join and the next line builds script_path with Path(tmp_dir) / .... Using one style for both lines would read more uniformly.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 16, 2026
@meta-codesync

meta-codesync Bot commented Nov 17, 2026

Copy link
Copy Markdown

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request GL/approved Approved by GreenLight Merged meta-exported module: inductor ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants