Skip to content

[dynamo] Revalidate a memoized module-by-file hit before handing it back - #194952

Closed
bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1074/basefrom
gh/bobrenjc93/1074/head
Closed

bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1074/basefrom
gh/bobrenjc93/1074/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

_scan_sys_modules_for_file caches a hit outright and re-scans a miss only while
len(sys.modules) is unchanged. That length is an ABA check rather than a
version, so a plain del sys.modules[m] with no re-import is invisible to it,
and the memo kept handing back a name that no longer resolved. SourceInfo.
add_code indexes sys.modules with it directly and raised KeyError on the dead
name -- a hazard the function's own docstring described.

A cached hit is now checked against sys.modules before it is returned, for one
dict lookup rather than the O(len(sys.modules)) scan the memo exists to avoid.
A stale hit falls through and re-scans, so the miss path stays as it was.

Test Plan:

python test/test_precompile.py
python test/dynamo/test_package.py

test_precompile_stale_module_memo_is_revalidated imports a temp module, scans
it, deletes it from sys.modules without re-importing, and calls add_code. It
raises KeyError unfixed.

Authored with the assistance of an AI coding agent.

[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 26, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 17 New Failures, 1 Unrelated Failure

As of commit 577104b with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 26, 2026
This was referenced Aug 25, 2026
This was referenced Aug 26, 2026
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362; this change lives in #195362 (with the guard-drop policy half in #195360). Closing to consolidate review there. The branch is kept on GitHub.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1074/head branch November 11, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request module: dynamo topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant