Skip to content

Back out "Revert D25903846: [pytorch][PR] Structured kernel definition for upsample_nearest2d"#50794

Closed
ezyang wants to merge 2 commits intogh/ezyang/900/basefrom
gh/ezyang/900/head
Closed

Back out "Revert D25903846: [pytorch][PR] Structured kernel definition for upsample_nearest2d"#50794
ezyang wants to merge 2 commits intogh/ezyang/900/basefrom
gh/ezyang/900/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented Jan 20, 2021

Stack from ghstack:

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original. I can unbundle them, but I've opted to keep it with the port because it's the easiest way to make sure the changes are exercised.

  • There's a bugfix in the codegen to test if a dispatch key is structured before short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
  • Dispatch tables for functions which delegate to structured kernels don't have Math entries from generated for them.
  • It's now illegal to specify a structured dispatch key in a delegated structured kernel (it will be ignored!) add is now fixed to follow this
  • There are some extra sanity checks for NativeFunctions validation
  • Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.

Differential Revision: D25962873

Differential Revision: D25962873

…n for upsample_nearest2d"

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original:

* There's a bugfix in the codegen to test if a dispatch key is structured *before* short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
* Dispatch tables for structured kernels are explicitly zeroed, to prevent Math entries from being generated for them. Ideally this logic would happen in the code itself but I tried a simple version of this and it didn't work, so I'm going to do this workaround first and investigate more.
* Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.

Differential Revision: [D25962873](https://our.internmc.facebook.com/intern/diff/D25962873/)

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jan 20, 2021
…n for upsample_nearest2d"

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original:

* There's a bugfix in the codegen to test if a dispatch key is structured *before* short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
* Dispatch tables for structured kernels are explicitly zeroed, to prevent Math entries from being generated for them. Ideally this logic would happen in the code itself but I tried a simple version of this and it didn't work, so I'm going to do this workaround first and investigate more.
* Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.

Differential Revision: [D25962873](https://our.internmc.facebook.com/intern/diff/D25962873/)

ghstack-source-id: 120018465
Pull Request resolved: #50794
…l definition for upsample_nearest2d""

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original. I can unbundle them, but I've opted to keep it with the port because it's the easiest way to make sure the changes are exercised.

* There's a bugfix in the codegen to test if a dispatch key is structured *before* short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
* Dispatch tables for functions which delegate to structured kernels don't have Math entries from generated for them.
* It's now illegal to specify a structured dispatch key in a delegated structured kernel (it will be ignored!) add is now fixed to follow this
* There are some extra sanity checks for NativeFunctions validation
* Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.

Differential Revision: [D25962873](https://our.internmc.facebook.com/intern/diff/D25962873/)

Differential Revision: [D25962873](https://our.internmc.facebook.com/intern/diff/D25962873)

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Jan 20, 2021
…n for upsample_nearest2d"

Pull Request resolved: #50794

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original. I can unbundle them, but I've opted to keep it with the port because it's the easiest way to make sure the changes are exercised.

* There's a bugfix in the codegen to test if a dispatch key is structured *before* short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
* Dispatch tables for functions which delegate to structured kernels don't have Math entries from generated for them.
* It's now illegal to specify a structured dispatch key in a delegated structured kernel (it will be ignored!) add is now fixed to follow this
* There are some extra sanity checks for NativeFunctions validation
* Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.
ghstack-source-id: 120038038

Differential Revision: [D25962873](https://our.internmc.facebook.com/intern/diff/D25962873/)
Copy link
Copy Markdown
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for debugging this. I didn't realize that all the calls I made while trying to replicate this were actually going to the vec overload, so this cleared it up.

Some noob questions -

This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)

  • Whats a situation when the dispatch table is not present?
  • What do you mean by relevant structured key? It seems that if input is quantized for example, neither structured key is particularly relevant
  • Is there a reason why we only check the out variant to see if there is a matching dispatch before short circuiting. Seems like checking non-out variants would fix the issue as well here

@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Jan 21, 2021

Whats a situation when the dispatch table is not present?

Specifically referring to when you don't have a dispatch key in the YAML file

What do you mean by relevant structured key? It seems that if input is quantized for example, neither structured key is particularly relevant

Sorry, this wasn't very clear. The bug in question was when you were processing QuantizedCPU for the functional version of an operator, and that dispatch key didn't exist for the out version. If you first test if QuantizedCPU exists in the out version, you'll conclude there is nothing to do; but actually, you needed to fallback to unstructured generator case where there is something to do for the functional operator only.

Is there a reason why we only check the out variant to see if there is a matching dispatch before short circuiting. Seems like checking non-out variants would fix the issue as well here

For structured dispatch keys (CPU and CUDA), you are guaranteed to not have keys on anything besides the out variant.!

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 5e79b8e.

@facebook-github-bot facebook-github-bot deleted the gh/ezyang/900/head branch January 29, 2021 15:21
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…n for upsample_nearest2d" (pytorch#50794)

Summary:
Pull Request resolved: pytorch#50794

Original commit changeset: b4a7948088c0

There are some subtle extra tweaks on top of the original. I can unbundle them, but I've opted to keep it with the port because it's the easiest way to make sure the changes are exercised.

* There's a bugfix in the codegen to test if a dispatch key is structured *before* short circuiting because the dispatch key was missing in the table. This accounts for mixed structured-nonstructured situations where the dispatch table is present, but the relevant structured key isn't (because the dispatch table only exists to register, e.g., QuantizedCPU)
* Dispatch tables for functions which delegate to structured kernels don't have Math entries from generated for them.
* It's now illegal to specify a structured dispatch key in a delegated structured kernel (it will be ignored!) add is now fixed to follow this
* There are some extra sanity checks for NativeFunctions validation
* Finally, unlike the original PR, I switched the .vec variant of upsample_nearest2d to also be DefaultBackend, bringing it inline with upsample_nearest1d.
ghstack-source-id: 120038038

Test Plan:
```
buck test mode/dev //coreai/tiefenrausch:python_tests -- --exact 'coreai/tiefenrausch:python_tests - test_can_run_local_async_inference_cpu (coreai.tiefenrausch.tests.python_test.TiefenrauschPY)' --run-disabled
```

Reviewed By: ngimel

Differential Revision: D25962873

fbshipit-source-id: d29a9c97f15151db3066ae5efe7a0701e6dc05a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants