Skip to content

Moved Autograd Fallback Interface to Header for Use by Out-of-tree Backends #159639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: gh/fffrog/129/base
Choose a base branch
from

Conversation

FFFrog
Copy link
Collaborator

@FFFrog FFFrog commented Aug 1, 2025

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Aug 1, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 52c5b69 with merge base ff0d56d (image):
💚 Looks good so far! There are no failures yet. 💚

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

@FFFrog
Copy link
Collaborator Author

FFFrog commented Aug 1, 2025

@pytorchbot label "topic: not user facing"

@FFFrog FFFrog closed this Aug 1, 2025
@FFFrog FFFrog reopened this Aug 1, 2025
@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Aug 1, 2025
@FFFrog
Copy link
Collaborator Author

FFFrog commented Aug 1, 2025

@pytorchbot label "topic: not user facing"

FFFrog added 2 commits August 1, 2025 18:50
[ghstack-poisoned]
[ghstack-poisoned]
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will let @soulitzer review this one

@albanD albanD requested a review from soulitzer August 4, 2025 14:26
@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 4, 2025
@FFFrog
Copy link
Collaborator Author

FFFrog commented Aug 5, 2025

Will let @soulitzer review this one

Thank you.

@FFFrog
Copy link
Collaborator Author

FFFrog commented Aug 5, 2025

So sorry to you @soulitzer, could you help to take a look at this?

@FFFrog FFFrog requested a review from ezyang August 7, 2025 01:45
[ghstack-poisoned]
FFFrog added 2 commits August 8, 2025 18:31
[ghstack-poisoned]
[ghstack-poisoned]
@soulitzer
Copy link
Contributor

Sorry for the delay @FFFrog, I just returned from PTO
Could you share a code snippet of how this fallback will be used for out-of-tree backends?

Anyhow we probably don't want to expose the macro in the header, and instead just the function declaration

@FFFrog
Copy link
Collaborator Author

FFFrog commented Aug 12, 2025

Thank you for your reply :D

Could you share a code snippet of how this fallback will be used for out-of-tree backends?

Okay, here's the snippet:

TORCH_LIBRARY_IMPL(_, AutogradPrivateUse1, m) {
m.fallback(AUTOGRAD_FALLBACK);
}

New accelerators maybe want to add forward functions for new operators, so it would be convenient if we could expose autograd_fallback in the header file. However, AUTOGRAD_FALLBACK is not necessary.

@soulitzer
Copy link
Contributor

soulitzer commented Aug 12, 2025

Thanks for the context!

btw, we do already have fallback APIs exposed in torch/csrc/autograd/autograd_not_implemented_fallback.h.

  • The "autogradNotImplementedFallback" version attaches a node that errors upon backward.
  • There is also existing basicAutogradNotImplementedFallback that is a more "gentle" to maintain bc: warn instead of error, etc.

What this PR exposes is a wrapper on top of the latter API, that has another of layer of indirection handling the case where the particular build of PyTorch does not have autograd.

It's probably fine to expose the version (with better naming, and after collocating the wrapper next to the other APIs), but I wonder if the existing APIs already work for your case @FFFrog?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants