Skip to content

[precompile] Record entry defaults and emit the multi-graph driver - #197990

Closed
bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1404/basefrom
gh/bobrenjc93/1404/head
Closed

bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1404/basefrom
gh/bobrenjc93/1404/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Summary. Two small pieces complete the multi-graph artifact plumbing in torch/_precompile.py. _entry_binding(fn) records the entry's __defaults__ and __kwdefaults__, which a code object does not carry; without them a defaulted parameter is absent from the served call's f_locals and every guard misses. Closure cells are deliberately not recorded: a closure entry is refused earlier (a rebuilt cell would be a new object Dynamo's identity guard misses anyway), and the driver refuses one that arrives regardless rather than rebuilding it over empty cells. _emit_multigraph_driver_source() renders _build_multigraph_forward into the artifact with inspect.getsource, the same path the other drivers use, followed by forward = _build_multigraph_forward() and the same if __name__ == "__main__" hint block the single-graph artifacts end in. import inspect moves to module scope, replacing the function-local import _emit_driver_source had. Because that section ends in a top-level assignment, _parse_artifact_metadata no longer describes one as hypothetical and skips forward without the "unrecognized assignment" debug line, which stays a signal for a malformed artifact.

Examples

def step(model, x, scale=2.0, *, mode="sum"):
    ...
_entry_binding(step)
# {"defaults": (2.0,), "kwdefaults": {"mode": "sum"}}

_emit_multigraph_driver_source()
# "\ndef _build_multigraph_forward():\n ...\n\n\nforward = _build_multigraph_forward()\n\n\nif __name__ == \"__main__\":\n ..."

Test Plan:

python test/test_precompile.py -k test_entry_binding_records_defaults -k test_emit_multigraph_driver_source_is_a_complete_section
python test/test_precompile.py
lintrunner torch/_precompile.py test/test_precompile.py

Authored with an AI assistant.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5.1 [email protected]

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (2 Unrelated Failures)

As of commit 9b8d0c4 with merge base d78bbf2 (image):

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

  • Correctness
    • _entry_binding's {"defaults", "kwdefaults"} keys match the consumer at torch/_precompile_driver.py:573-579, which reads entry_binding.get("defaults")/get("kwdefaults")
    • The omitted closure cells are justified: _precompile_driver.py:531-538 refuses an entry with co_freevars rather than rebuilding over empty cells
    • _emit_multigraph_driver_source emits only _build_multigraph_forward, which needs no sibling helper — _fail/_extract_param_buffers/_check_structure last appear at _precompile_driver.py:361, above its def at line 388
  • Scope
    • Adds two functions in torch/_precompile.py (lines 1696-1724) plus two tests; neither new symbol has a caller yet per grep across ./pytorch, so no existing path changes behavior
    • The only edit to live code is hoisting import inspect out of _emit_driver_source to module scope at torch/_precompile.py:232; the docstring's laziness claim is about the getsource call, which still runs only on the emit path
  • Testing
    • test_entry_binding_records_defaults covers both the defaulted and the plain-signature None case (test/test_precompile.py:885-897)
    • test_emit_multigraph_driver_source_is_a_complete_section parses the emitted text and asserts the FunctionDef/Assign/If shape ending in _DRIVER_MAIN (test/test_precompile.py:899-910)
  • Safety
    • No secrets, auth, or CI/release plumbing touched; the diff is confined to torch/_precompile.py and test/test_precompile.py

reason: clean
Reviewed commit: 9b8d0c4

Inference job

🐛 Report a wrong verdict

CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:

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

This was referenced Sep 21, 2026
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 0 checks:

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

@github-actions
github-actions Bot deleted the gh/bobrenjc93/1404/head branch November 27, 2026 01:48
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 Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants