Skip to content

feat: second attempt to support DDS and NonZero op #3388

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

Merged
merged 17 commits into from
Mar 13, 2025
Merged

Conversation

zewenli98
Copy link
Collaborator

Description

Added a new path to support Data Dependent Shape (DDS) and NonZero op in this PR.
Static and dynamic shapes go the original path; DDS goes the new path with IOutputAllocator.

Fixes #2516

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@zewenli98 zewenli98 self-assigned this Feb 11, 2025
@github-actions github-actions bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: runtime component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Feb 11, 2025
@github-actions github-actions bot requested a review from apbose February 11, 2025 00:41
@github-actions github-actions bot added the component: lowering Issues re: The lowering / preprocessing passes label Feb 26, 2025
@zewenli98 zewenli98 force-pushed the dds_support2 branch 2 times, most recently from 9a9852f to d718464 Compare February 28, 2025 18:20
if (
node != output_node
and len(node.users) == 0
and len(node.all_input_nodes) > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably better to add an assert checking if if has only one input (print the number in the string if it fails)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I previously reused the code from other lowering pass. it looks like we can directly remove unused ops right?

if (
node != output_node
and len(node.users) == 0
and len(node.all_input_nodes) > 0
):
gm.graph.erase_node(node)
gm = clean_up_graph_after_modifications(gm)
logger.debug(f"Removed ops that [num_users=0] nodes:\n{gm.graph}")

do you think if there's any potential issues?

shape_changed = self.validate_input_shapes(inputs)
(
need_cudagraphs_record,
can_use_pre_allocated_outputs,
need_cudagraphs_reset,
) = self.runtime_states.set_runtime_states(
cudagraphs_enabled, self.use_pre_allocated_outputs, shape_changed
self.cudagraphs_enabled, self.use_pre_allocated_outputs, shape_changed
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is use_pre_allocated_outputs valid now that you're adding OA feature ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the OA feature will not affact use_pre_allocated_outputs because I didn't change the behavior of CG and use_pre_allocated_outputs has its own context manager as well.

raise RuntimeError(
"Both CUDA Graphs and OutputAllocator are enabled. Please disable either one."
)
if self.use_output_allocator_outputs:
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is use_output_allocator_outputs set ? Is it by using the with context manager by the user ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, it will be set by the with context manager by the user. If users don't set it, it will choose standard exec or OA according to the converter decorator.

@zewenli98 zewenli98 requested review from peri044 and narendasan March 4, 2025 05:34
@zewenli98 zewenli98 force-pushed the dds_support2 branch 2 times, most recently from 28b27c5 to 7e1a1ca Compare March 11, 2025 00:04
@github-actions github-actions bot added the component: core Issues re: The core compiler label Mar 11, 2025
Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

LGTM after minor change

@zewenli98 zewenli98 merged commit 10d7c61 into main Mar 13, 2025
14 checks passed
@zewenli98 zewenli98 deleted the dds_support2 branch March 13, 2025 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: runtime component: tests Issues re: Tests documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aten.nonzero
5 participants