Skip to content

[precompile] Test that a custom op captures where an aliased autograd.Function cannot - #194455

Closed
bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1042/basefrom
gh/bobrenjc93/1042/head
Closed

bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1042/basefrom
gh/bobrenjc93/1042/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A hand-fused kernel is usually reached as a module-level alias of
SomeFunction.apply, chosen among several implementations by config. Capturing
a model that calls one fails the default gates, and not for a reason the caller
would guess from the error: the guards are CLASS_MATCH on the Function and
CLOSURE_MATCH on its two staticmethods, which are unserializable by
construction -- there is no portable spelling of "this exact object" -- so they
are dropped, and an alias is exactly the config-selected slot _is_risky_drop
exists to flag. The classification is right; the capture needs
require_no_risky_drops=False and an audit.

Registering the same math with torch.library instead replaces all three
guards with an operator looked up by qualified name, which serializes, so the
capture passes with the gates left on. That is the migration worth recommending
to anyone hitting this, and nothing pinned it, so a later relaxation of
_is_risky_drop could quietly make the two cases indistinguishable and remove
the reason to migrate.

No behaviour change; this documents what already happens.

Test Plan:

python test/test_precompile.py

The new test captures the same math both ways: the aliased .apply form is
asserted to fail on the dropped-guard gate, and the custom-op form is asserted
to capture with the default gates and to serve equal to eager.

Authored with an AI assistant.

Differential Revision: D117073079

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

pytorch-bot Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 23 New Failures

As of commit 5462f2a with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have failed:

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

This was referenced Aug 22, 2026
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Aug 22, 2026
….Function cannot

A hand-fused kernel is usually reached as a module-level alias of
`SomeFunction.apply`, chosen among several implementations by config. Capturing
a model that calls one fails the default gates, and not for a reason the caller
would guess from the error: the guards are CLASS_MATCH on the Function and
CLOSURE_MATCH on its two staticmethods, which are unserializable by
construction -- there is no portable spelling of "this exact object" -- so they
are dropped, and an alias is exactly the config-selected slot `_is_risky_drop`
exists to flag. The classification is right; the capture needs
`require_no_risky_drops=False` and an audit.

Registering the same math with `torch.library` instead replaces all three
guards with an operator looked up by qualified name, which serializes, so the
capture passes with the gates left on. That is the migration worth recommending
to anyone hitting this, and nothing pinned it, so a later relaxation of
`_is_risky_drop` could quietly make the two cases indistinguishable and remove
the reason to migrate.

No behaviour change; this documents what already happens.

Test Plan:

```
python test/test_precompile.py
```

The new test captures the same math both ways: the aliased `.apply` form is
asserted to fail on the dropped-guard gate, and the custom-op form is asserted
to capture with the default gates and to serve equal to eager.

Authored with an AI assistant.

ghstack-source-id: 16885b9
Pull-Request: #194455
bobrenjc93 added a commit that referenced this pull request Aug 22, 2026
….Function cannot

A hand-fused kernel is usually reached as a module-level alias of
`SomeFunction.apply`, chosen among several implementations by config. Capturing
a model that calls one fails the default gates, and not for a reason the caller
would guess from the error: the guards are CLASS_MATCH on the Function and
CLOSURE_MATCH on its two staticmethods, which are unserializable by
construction -- there is no portable spelling of "this exact object" -- so they
are dropped, and an alias is exactly the config-selected slot `_is_risky_drop`
exists to flag. The classification is right; the capture needs
`require_no_risky_drops=False` and an audit.

Registering the same math with `torch.library` instead replaces all three
guards with an operator looked up by qualified name, which serializes, so the
capture passes with the gates left on. That is the migration worth recommending
to anyone hitting this, and nothing pinned it, so a later relaxation of
`_is_risky_drop` could quietly make the two cases indistinguishable and remove
the reason to migrate.

No behaviour change; this documents what already happens.

Test Plan:

```
python test/test_precompile.py
```

The new test captures the same math both ways: the aliased `.apply` form is
asserted to fail on the dropped-guard gate, and the custom-op form is asserted
to capture with the default gates and to serve equal to eager.

Authored with an AI assistant.

ghstack-source-id: 16885b9
Pull-Request: #194455
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

This was referenced Aug 23, 2026
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@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/1042/head branch November 11, 2026 01:45
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