ATen DerivedType is dead, long live ATen RegisterDispatchKey#47011
ATen DerivedType is dead, long live ATen RegisterDispatchKey#47011ezyang wants to merge 3 commits intogh/ezyang/863/basefrom
Conversation
smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 22d3fd7 Pull Request resolved: #47011
| backends = [ | ||
| # NB: substrings in these dispatch keys matter, we do tests to see if | ||
| # a key contains, e.g., CUDA to classify it as a CUDA backend | ||
| dispatch_keys = [ |
There was a problem hiding this comment.
Btw a quick comment since I ran into this PR ;)
I tried to use dispatch_keywords to reference the keys we support in native_functions.yaml to disambiguate from the real dispatch keys. One main confusion if we keep using dispatch_keys is developers would naturally think all dispatch keys are supported (like XLA/Autograd/Autocast etc) but in fact not all dispatch keys are supported in native_functions.yaml.
There was a problem hiding this comment.
Ah, so it wasn't just a typo!
Here's a take: what if we hypothetically, we should support all dispatch keys in native_functions.yaml? Then dispatch key naming would be appropriate.
smessmer
left a comment
There was a problem hiding this comment.
thanks, I like the new file names better.
smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D24600806](https://our.internmc.facebook.com/intern/diff/D24600806) [ghstack-poisoned]
smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 8a19f48 Pull Request resolved: #47011
💊 CI failures summary and remediationsAs of commit b92c492 (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 7 times. |
| "aten/src/ATen/RegisterSparseCPU.cpp", | ||
| "aten/src/ATen/RegisterMath.cpp", | ||
| "aten/src/ATen/RegisterDefaultBackend.cpp", | ||
| "aten/src/ATen/RegisterSchema.cpp", |
There was a problem hiding this comment.
minor, but is it worth globbing these?
There was a problem hiding this comment.
It's not worth because cmake and buck limitations on generated files means they can't be globbed.
| # Dispatch keys that "support all backends". These codegen slightly differently | ||
| # then backend specific keys. | ||
| def is_generic_dispatch_key(dk: str) -> bool: | ||
| return dk in {'DefaultBackend', 'Math'} |
There was a problem hiding this comment.
Personally I'd rather retain a top-level definition for this than sink it into a helper like this (though adding a helper that tests it is fine by me) - feels fragmented to have part of the data model hidden in a function.
There was a problem hiding this comment.
I'll leave this to future work
There was a problem hiding this comment.
I'll leave this to future work
What, putting the top-level definition back? 😁
I probably wasn't clear - what I meant was, the function you added is fine by me, but I'd rather see it use the existing top-level definition, rather than capture it. Like:
GENERIC_DISPATCH_KEYS = ('DefaultBackend', 'Math')
def is_generic_dispatch_key(dk: str) -> bool:
return dk in GENERIC_DISPATCH_KEYS
Not a super strong opinion, just a personal pref. But wanted to clarify
There was a problem hiding this comment.
Yeah, haha (because I had a clean land bill so it was ready to land).
I do understand the suggestion here... it just conflicts with another pref I have, which is default lots of encapsulation (hide everything by default) and then make it visible. But it's NBD, and there's more refactoring for Dispatch Keys that probably could be done (like making it into an enum)
smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D24600806](https://our.internmc.facebook.com/intern/diff/D24600806) [ghstack-poisoned]
…#47011) Summary: Pull Request resolved: pytorch#47011 smessmer has complained about how it is difficult to find generated code. Well hopefully this diffs helps a bit with that. There are three components to this refactor: - Rename TypeDerived (CPUType) to RegisterDispatchKey (RegisterCPU). The 'Type' nomenclature is vestigial and I think Register says what these files do a lot more clearly. I also got rid of the CPUType namespace; everything just goes in anonymous namespace now, less moving parts this way. - Give Math and DefaultBackend their own files (RegisterMath and RegisterDefaultBackend) - Restructure code generation so that schema definition is done completely separately from RegisterDispatchKey I decided to name the files RegisterCPU rather than the old convention BackendSelectRegister, because it seems better to me if these files clump together in an alphabetical listing rather than being spread out everywhere. There are a few manual registration files which should probably get similar renaming. I also did a little garden cleaning about how we identify if a dispatch key is a cuda key or a generic key (previously called KEYWORD_ALL_BACKENDS but I like my naming better). Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: D24600806 Test Plan: Imported from OSS Reviewed By: smessmer Pulled By: ezyang fbshipit-source-id: c1b510dd7515bd95e3ad25b8edf961b2fb30a25a

Stack from ghstack:
smessmer has complained about how it is difficult to find generated
code. Well hopefully this diffs helps a bit with that.
There are three components to this refactor:
The 'Type' nomenclature is vestigial and I think Register says
what these files do a lot more clearly. I also got rid of
the CPUType namespace; everything just goes in anonymous
namespace now, less moving parts this way.
RegisterDefaultBackend)
completely separately from RegisterDispatchKey
I decided to name the files RegisterCPU rather than the old convention
BackendSelectRegister, because it seems better to me if these
files clump together in an alphabetical listing rather than being
spread out everywhere. There are a few manual registration files
which should probably get similar renaming.
I also did a little garden cleaning about how we identify if a
dispatch key is a cuda key or a generic key (previously called
KEYWORD_ALL_BACKENDS but I like my naming better).
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D24600806