Skip to content
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

feat: Add Selective ATen decompositions #2173

Merged
merged 5 commits into from
Aug 17, 2023
Merged

Conversation

gs-olive
Copy link
Collaborator

@gs-olive gs-olive commented Aug 3, 2023

Description

  • Add sets to selectively enable or disable decompositions in Torch
  • Add new runtime argument enable_experimental_decompositions to enable all core aten decompositions, or a pre-selected subset thereof
  • Improve documentation of compilation settings overall

Fixes #2160

Type of change

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

Checklist:

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

@gs-olive gs-olive added component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths Story: Export/Compile Unification Issues relating to unification of Dynamo compile/export paths labels Aug 3, 2023
@gs-olive gs-olive requested a review from peri044 August 3, 2023 22:30
@gs-olive gs-olive self-assigned this Aug 3, 2023
@github-actions github-actions bot added component: api [Python] Issues re: Python API component: lowering Issues re: The lowering / preprocessing passes component: torch_compile labels Aug 3, 2023
@gs-olive gs-olive changed the title fix: Add enabled/disabled sets for decompositions feat: Add Selective ATen decompositions Aug 3, 2023
@gs-olive gs-olive requested a review from narendasan August 3, 2023 22:31
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the selective_decompositions branch from 34a190e to bdb06d8 Compare August 4, 2023 21:56
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the selective_decompositions branch from bdb06d8 to 368a20e Compare August 4, 2023 22:12
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Comment on lines 176 to 178
ENABLED_TORCH_DECOMPOSITIONS: Dict[
torch._ops.OpOverload, Callable
] = get_torch_decompositions(enabled_decompositions)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, the decompositions are sourced directly from Torch's main registry (via get_torch_decompositions) and may not exactly match with the _core_aten_decompositions. This is because certain decompositions which we depend on (such as native_layer_norm, may occasionally be removed from the core set).

Whenever Torch versions are upgraded, this list should be updated as well.

ENABLED_TORCH_DECOMPOSITIONS: Dict[
torch._ops.OpOverload, Callable
] = get_torch_decompositions(enabled_decompositions)
TORCH_TRT_DECOMPOSITIONS: Dict[torch._ops.OpOverload, Callable] = {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The decompositions are three dictionaries:

  • ENABLED_TORCH_DECOMPOSITIONS - the enabled decompositions we've pre-selected
  • CORE_ATEN_DECOMPOSITIONS_FILTERED (defined in get_decompositions below) - the complete set of _core_aten_decompositions Torch provides, minus the set of disabled decompositions. Note that TORCH_DECOMPOSITIONS may not be a subset of this set
  • TORCH_TRT_DECOMPOSITIONS - the decompositions we've written ourselves

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would TORCH_DECOMPOSITIONS only include decompositions from the get_torch_decompoistions set?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that TORCH_DECOMPOSITIONS may not be a subset of this set
From what I understand,

  • it seems like some decompositions in _core_aten_decompositions have been removed eg: aten.native_layer_norm. ENABLED_TORCH_DECOMPOSITIONS is a more complete set (from previous commit maybe ). Is this correct ?
  • In that case, what if we move aten.native.layer_norm to TORCH_TRT_DECOMPOSITIONS since it is useful to us and maybe other useful ones instead of maintaining a ENABLED_TORCH_DECOMPOSITIONS which overlaps with _core_aten_decompositions one ?

Copy link
Collaborator Author

@gs-olive gs-olive Aug 7, 2023

Choose a reason for hiding this comment

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

@narendasan
ENABLED_TORCH_DECOMPOSITIONS would only include decompositions from the _core_aten_decompositions set which are not also in disabled_decompositions

@peri044

  • The interpretation of ENABLED_TORCH_DECOMPOSITIONS is correct
  • My initial intent for TORCH_TRT_DECOMPOSITIONS was that it would only store decompositions we specifically (custom) wrote, not ones sourced from Torch, as layer_norm would be.

def reciprocal_replacement(
input_: torch.Tensor,
) -> torch.Tensor:
return torch.div(1, input_)


def get_decompositions():
return DECOMPOSITIONS
def get_decompositions(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The dictionary returned by get_decompositions is either ENABLED_TORCH_DECOMPOSITIONS or CORE_ATEN_DECOMPOSITIONS_FILTERED concatenated with our TORCH_TRT_DECOMPOSITIONS

@narendasan
Copy link
Collaborator

Have we thought about what this might look like if its user accessible?

@narendasan
Copy link
Collaborator

Can we add a tool to monitor these decomposition sets similar to the opset coverage tool?

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive gs-olive force-pushed the selective_decompositions branch from 8b12de5 to 806b348 Compare August 8, 2023 00:47
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

@gs-olive
Copy link
Collaborator Author

gs-olive commented Aug 8, 2023

The existing opset coverage tool is compatible with this PR, meaning that get_decompositions will reflect the degree of coverage of the lowering passes we currently apply via decompositions. It will not show the coverage percentages of using the core_aten_decompositions, but this is also not the default usage as of now. We can add in coverage for the enable_experimental_decompositions set to the tool as a command line argument, if preferred.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

@gs-olive gs-olive force-pushed the selective_decompositions branch from 7fa036f to d49cadb Compare August 9, 2023 05:32
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

- Add sets to selectively enable or disable decompositions in Torch
- Add new runtime argument `enable_experimental_decompositions` to
enable all core aten decompositions, or a pre-selected subset thereof
- Improve documentation of compilation settings overall
- Add decorator-wrapper to perform import-time checks on decompositions
and alert the user if any custom decompositions conflict with existing
registered or specified operators
- Simplify code logic for dictionary merging in `get_decompositions`
function
- Add safety logic to ensure invariants about the decompositions are
not violated
@gs-olive gs-olive force-pushed the selective_decompositions branch from d49cadb to 1e3d12e Compare August 15, 2023 22:01
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

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

@gs-olive gs-olive force-pushed the selective_decompositions branch from 1e3d12e to 2064f4f Compare August 17, 2023 20:13
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

@gs-olive gs-olive merged commit 91fcea4 into main Aug 17, 2023
@gs-olive gs-olive deleted the selective_decompositions branch August 17, 2023 23:37
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: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: torch_compile Story: Export/Compile Unification Issues relating to unification of Dynamo compile/export paths
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨[Improvement] Unified + Selective Decomposition System for Dynamo
4 participants