8000 [HOP] Rework Autograd DispatchKey for scan and map by bohnstingl · Pull Request #153336 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[HOP] Rework Autograd DispatchKey for scan and map #153336

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 3 commits into
base: main
Choose a base branch
from

Conversation

bohnstingl
Copy link
Collaborator
@bohnstingl bohnstingl commented May 10, 2025

This PR introduces the py_autograd_impl instead of the DispatchKey.Autograd for some HOPs.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames

Copy link
pytorch-bot bot commented May 10, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 9f9adc1 with merge base 47df195 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@bohnstingl
Copy link
Collaborator Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label May 10, 2025
@bohnstingl bohnstingl changed the title [HOP] Reworke Autograd DispatchKey for HOPs [HOP] Rework Autograd DispatchKey for HOPs May 11, 2025
@bohnstingl bohnstingl changed the title [HOP] Rework Autograd DispatchKey for HOPs [HOP] Rework Autograd DispatchKey for scan and map May 12, 2025
Comment on lines +184 to +191
# outs = f(xs, *args)
# if pytree.tree_any(lambda elem: not isinstance(elem, torch.Tensor) if elem is not None else False, outs):
# raise RuntimeError(
# "Expect outputs of map only contains tensors or None. "
# f"Got types {[type(out) for out in pytree.tree_leaves(outs)]}."
# )
# return outs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When using the new key @map_impl.py_autograd_impl, the map_dense gets triggered directly and thus create_fw_bw_graph is not used. Therefore, the check of the outputs in create_fw_bw_graph is also not performed and the check can either be done here or below (see comment)

Comment on lines +269 to +277
outs_flatten = pytree.tree_leaves(pytrees)
if any(
# pytree.tree_map(lambda elem: not isinstance(elem, torch.Tensor), outs)
not isinstance(out, torch.Tensor) for out in outs_flatten if out is not None
):
raise RuntimeError(
"Expect outputs of map only contains tensors or None. "
f"Got types {[type(out) for out in outs_flatten]}."
)
Copy link
Collaborator Author
@bohnstingl bohnstingl May 12, 2025

Choose a reason for hiding this comment

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

or here.
Which option would be preferable?

@bohnstingl bohnstingl marked this pull request as ready for review May 12, 2025 18:37
@bohnstingl bohnstingl requested a review from zou3519 as a code owner May 12, 2025 18:37
@colesbury colesbury added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: dynamo 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.

3 participants
0