Skip to content

[dynamo] Name inlined code by the file that defines it - #195914

Closed
bobrenjc93 wants to merge 53 commits into
gh/bobrenjc93/1116/basefrom
gh/bobrenjc93/1116/head
Closed

bobrenjc93 wants to merge 53 commits into
gh/bobrenjc93/1116/basefrom
gh/bobrenjc93/1116/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The source checksum a package records for an inlined code object was keyed on
inspect.getmodule(code).__name__, and that name is wrong in two ways.
getmodule can hand back a module that merely re-exports the code from a
private implementation file that sets its own __name__ to the public name
-- _collections_abc, whose __name__ is "collections.abc", is the stdlib
instance -- so SourceInfo.add_code compared the code's line range against a
file that does not contain it and aborted the capture with its Source mismatch
assertion. And that __name__ is not importable back to the same object: it
imports to the shim. (On CPython 3.11+ the stdlib copy is frozen, co_filename
is <frozen _collections_abc> and getmodule already returns None, so the
checksum is skipped either way; the fix matters on 3.10 and for any module that
uses the same rename idiom.)

_defining_module_name returns the sys.modules KEY whose file is
code.co_filename, falling back to a memoized scan of sys.modules. A hit is
cached for as long as the key still names a module with that file; a miss is
cached only while sys.modules has not changed size, because the usual reason
for one is that the module has not been imported yet, and caching that
permanently would silently drop the checksum for every lazily imported file.
SourceInfo.add_code uses it and skips the checksum rather than record one
against the wrong file; the cold path of CompilePackage.initialize uses it
as the entry code's python_module and falls back to fn.__module__ when no
loaded module owns the file.

Test Plan:

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

Authored with an AI assistant.

[no ci]

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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 Sep 3, 2026
This was referenced Sep 3, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 closed this Oct 16, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1116/head branch November 17, 2026 01:46
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 release notes: dynamo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant