Skip to content

[precompile] Make the installed-artifact regenerate hint conditional on a source change - #200526

Closed
bobrenjc93 wants to merge 54 commits into
gh/bobrenjc93/1558/basefrom
gh/bobrenjc93/1558/head
Closed

bobrenjc93 wants to merge 54 commits into
gh/bobrenjc93/1558/basefrom
gh/bobrenjc93/1558/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Problem. When an installed artifact fails to install, its error ends "If that source changed since capture, regenerate the artifact against it.", which reads as pointing at the entry function even when the source that changed is an inlined helper in another module, or when no source changed at all.

Fix. The hint is now conditional on the cause, which the error already appends: "If the cause names a source that changed since capture, regenerate the artifact against it."

Summary. When _build_installed_forward cannot rebuild or install an artifact's package, it raises a PrecompileError that appends the cause and ended "If that source changed since capture, regenerate the artifact against it." Here "that source" read as {module_name}.{FN_NAME}, the entry function, but the package also checksums every inlined source, and those often live in other modules; the same except Exception also catches causes that name no source at all (an AssertionError inside install, say). Only the "Source code changes detected for (line a - line b)" RuntimeError from CompilePackage names the source that changed, so the hint now says "If the cause names a source that changed since capture, regenerate the artifact against it." Giving the hint only for that RuntimeError would mean matching its text, which this driver avoids elsewhere (it catches the refusal by type), so the hint is left to the reader, who can see the cause. This addresses review comments on #198556, which introduced the message; that PR is approved, so the change goes here at the top of the stack instead of being amended into it.

Example

The new test captures an entry whose graph-breaking frame inlines helper.scaled from a separate module, then edits only the helper before loading:

# helper module, after capture:
def scaled(y):
    return y.sin() * 1   # was: return y.sin()

torch.compiler.precompile.load(artifact, cache)
# PrecompileError: precompile: this installed artifact could not be installed onto
#   <entry module>.<fn> (RuntimeError: Source code changes detected for <helper module> (line a - line b) ...).
# parent: "... If that source changed since capture, regenerate the artifact against it."
# now:    "... If the cause names a source that changed since capture, regenerate the artifact against it."

test_an_installed_artifact_names_a_changed_helper_module_at_load asserts that the error contains Source code changes detected for <helper module> and the new conditional sentence.

Test Plan:

test_an_installed_artifact_names_a_changed_helper_module_at_load changes a module the entry inlines, not the entry's own module, and checks that the cause names that module and the message carries the conditional hint. The existing install-failure tests still pass:

python test/test_precompile.py -k test_an_installed_artifact_names_a_changed_helper_module_at_load
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
lintrunner -a --skip PYREFLY,CLANGTIDY torch/_precompile_driver.py

This PR was authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 [email protected]

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 6434204 with merge base 80c4d80 (image):
💚 Looks good so far! There are no failures yet. 💚

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

This was referenced Oct 10, 2026
@claude

claude Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 26s —— View job


This PR is still correct and self-contained after the tb103 rebase. The nested_graph_breaks=False pin I asked for in the last two reviews is now on the new test, so I have nothing left to flag.

PR Review: #200526

Summary

This PR makes the regenerate hint in _build_installed_forward's catch-all install error (torch/_precompile_driver.py:848-854) conditional on the cause naming a changed source. It also adds test_an_installed_artifact_names_a_changed_helper_module_at_load. The diff against origin/gh/bobrenjc93/1558/base is +49/-2 across two files: the same as before plus the one-line pin. The base is an ancestor of HEAD.

What I checked at this position:

  • The pin is fixed. @torch._dynamo.config.patch(nested_graph_breaks=False) now sits under @skipIfCrossRef (test/test_precompile.py:5448), matching its sibling test_an_installed_artifact_refuses_changed_source_at_load (5421). The test now keeps breaking as its own frame with helper.scaled inlined into it, whatever the config default is.
  • [no-ci] [precompile] Bind an inlined frame's continuation in the root frame's module #201256 (bound_in) and [no-ci] [precompile] Record a package frame under the module its globals belong to #200826 (root_scope) are below this PR. _add_function(..., bound_in=...) (torch/_dynamo/package.py:1306-1338) and add_resume_function(..., root_scope) (1474-1485) are both in the base, and this PR's diff touches neither.
  • The cause the test expects is unaffected. The Source code changes detected for {code.module} error is raised by the inlined_sources check in CompilePackage initialization (package.py:1260). That check runs before any resume function is installed and doesn't read bound_in.
  • Nothing the PR uses comes from a PR above it. The setUp fixtures, _capture, skipIfCrossRef and the imports are all in the base.

I didn't run the tests. This comes from reading the code.

Recommendation

Approve

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude review

Rebase round (tb104): #201256 below this PR gained tests only: closure and multi-level cases, plus a test of the driver's conflict check against the root module. This PR changes only by being rebased onto it. Please check that it is still correct and self-contained at its position.

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 25s —— View job


This PR is still correct and self-contained after the tb104 rebase, and I found no issues.

PR Review: #200526

Summary

This PR makes the regenerate hint in _build_installed_forward's catch-all install error (torch/_precompile_driver.py:848-854) conditional on the cause naming a changed source. It also adds test_an_installed_artifact_names_a_changed_helper_module_at_load. The diff against origin/gh/bobrenjc93/1558/base is the same as at the last review (+49/-2, two files, including the nested_graph_breaks=False pin), and the base is an ancestor of HEAD.

What I checked at this position:

  • [no-ci] [precompile] Bind an inlined frame's continuation in the root frame's module #201256 added only tests. Its new tests are in the base, and this PR's diff doesn't touch them. The new test's hunk applies after test_an_installed_artifact_refuses_changed_source_at_load without conflict.
  • The cause the test expects is in the base. Source code changes detected for {code.module} is raised at torch/_dynamo/package.py:1260. It comes from CompilePackage(fn, dynamo), which runs inside the same try that the reworded except Exception handles.
  • Nothing it uses comes from a PR above it. The setUp fixtures, _capture, skipIfCrossRef and the imports are all in the base.

I didn't run the tests. This comes from reading the code.

Recommendation

Approve

[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Oct 17, 2026
…itional on a source change

When `_build_installed_forward` cannot rebuild or install an artifact's package, it raises a PrecompileError that appends the cause and ended "If that source changed since capture, regenerate the artifact against it." Here "that source" read as `{module_name}.{FN_NAME}`, the entry function, but the package also checksums every inlined source, and those often live in other modules. The same `except Exception` also catches causes that name no source at all (an AssertionError inside install, say). Only the "Source code changes detected for <module> (line a - line b)" RuntimeError from `CompilePackage` names the source that changed.

The hint is now conditional: "If the cause names a source that changed since capture, regenerate the artifact against it." Giving the regenerate hint only for the source-mismatch RuntimeError would mean matching that error's text, which this driver avoids elsewhere (it catches the refusal by type). So the hint is left to the reader, who can see the cause.

This addresses review comments on the commit that introduced the message (#198556). That PR is approved, so the change goes here at the top of the stack instead of being amended into it.

Test Plan:

`test_an_installed_artifact_names_a_changed_helper_module_at_load` changes a module the entry inlines, not the entry's own module, and checks that the cause names that module and the message carries the conditional hint. The existing install-failure tests still pass:

```
python test/test_precompile.py -k test_an_installed_artifact_names_a_changed_helper_module_at_load
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
lintrunner -a --skip PYREFLY,CLANGTIDY torch/_precompile_driver.py
```

This PR was authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ghstack-source-id: 3c000d6
Pull-Request: #200526
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 25s —— View job


I found no issues. The diff is the same one approved at the last review.

PR Review: #200526

Summary

This PR changes the regenerate hint in the catch-all install error of _build_installed_forward (torch/_precompile_driver.py:843-849). The hint now applies only when the cause names a source that changed since capture. The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, pinned to nested_graph_breaks=False.

Against origin/gh/bobrenjc93/1558/base the diff is +49/-2 across two files, the same as at the last review, and the base is an ancestor of HEAD. What I checked:

  • The cause the test expects is in the base. The Source code changes detected for {code.module} check is at torch/_dynamo/package.py:1260.
  • The reworded handler catches it. That check runs inside CompilePackage(fn, dynamo) (driver line 800), which is inside the try that the reworded except Exception handles.
  • Nothing the PR uses comes from a PR above it.

I didn't run the tests. This comes from reading the code.

Recommendation

Approve

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 26s —— View job


I found no issues. The diff is the same one approved at the last review.

PR Review: #200526

Summary

This PR changes the regenerate hint in the catch-all install error of _build_installed_forward (torch/_precompile_driver.py:843-849). The hint now reads "If the cause names a source that changed since capture, regenerate the artifact against it." The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, which has @skipIfCrossRef and is pinned to nested_graph_breaks=False.

Compared with origin/gh/bobrenjc93/1558/base, the diff is +49/-2 across two files, the same as at the last review. The base is an ancestor of HEAD.

  • The cause the test expects is in the base. Source code changes detected for {code.module} is raised at torch/_dynamo/package.py:1260.
  • The reworded handler catches it. That check runs inside CompilePackage(fn, dynamo), which sits in the same try as the reworded except Exception.
  • Nothing it uses comes from a PR above it.

I didn't run the tests. This comes from reading the code.

Recommendation

Approve

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 13s —— View job


I found no issues; the diff is the same one approved at the last review.

PR Review: #200526

Summary

This PR changes the regenerate hint in _build_installed_forward's catch-all install error (torch/_precompile_driver.py:843-849). It now says "If the cause names a source that changed since capture, regenerate the artifact against it." The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, which has @skipIfCrossRef and is pinned to nested_graph_breaks=False.

Against origin/gh/bobrenjc93/1558/base, the diff is +49/-2 across two files, the same as at the previous review.

Recommendation

Approve

I didn't run the tests; this comes from reading the code.

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 19s —— View job


I found no issues. The diff hasn't changed since the last approved review.

PR Review: #200526

Summary

This PR changes the regenerate hint in the catch-all install error in _build_installed_forward (torch/_precompile_driver.py:843-849). The hint now reads "If the cause names a source that changed since capture, regenerate the artifact against it." The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, which has @skipIfCrossRef and is pinned to nested_graph_breaks=False.

Against origin/gh/bobrenjc93/1558/base, the diff is +49/-2 across two files, the same as at the previous review. The base is an ancestor of HEAD.

Recommendation

Approve

I didn't run the tests. This comes from reading the code.

[ghstack-poisoned]
@bobrenjc93 bobrenjc93 changed the title [no-ci] [precompile] Make the installed-artifact regenerate hint conditional on a source change [precompile] Make the installed-artifact regenerate hint conditional on a source change Oct 17, 2026
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 15s —— View job


I found no issues. The diff is the same one approved at the last review.

PR Review: #200526

Summary

This PR changes the regenerate hint in the catch-all install error in _build_installed_forward (torch/_precompile_driver.py:838-844). The hint now reads "If the cause names a source that changed since capture, regenerate the artifact against it." The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, which has @skipIfCrossRef and is pinned to nested_graph_breaks=False.

Against origin/gh/bobrenjc93/1558/base, the diff is +49/-2 across two files, the same as at the previous review.

Recommendation

Approve

I didn't run the tests. This comes from reading the code.

[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 16s —— View job


I found no issues. The diff is the same one approved at the last review.

PR Review: #200526

Summary

This PR changes the regenerate hint in the catch-all install error in _build_installed_forward (torch/_precompile_driver.py:838-844). The hint now reads "If the cause names a source that changed since capture, regenerate the artifact against it." The PR also adds test_an_installed_artifact_names_a_changed_helper_module_at_load, which has @skipIfCrossRef and is pinned to nested_graph_breaks=False.

Against origin/gh/bobrenjc93/1558/base, the diff is +49/-2 across two files, the same as at the previous review.

Recommendation

Approve

I didn't run the tests. This comes from reading the code.

@bobrenjc93 bobrenjc93 closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant