Skip to content

Conversation

priyaramani
Copy link
Contributor

@priyaramani priyaramani commented Apr 11, 2022

Stack from ghstack (oldest at bottom):

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

Differential Revision: D35510644

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Apr 11, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 5f2af30 (more details on the Dr. CI page):

Expand to see more
  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages

See GitHub Actions build pull / pytorch-xla-linux-bionic-py3.7-clang8 / test (xla, 1, 1, linux.2xlarge) (1/1)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-04-22T00:40:54.0636616Z �[1A�[K�[31m�[1mER...nclusion(s) in rule '@llvm-project//mlir:Support':
2022-04-22T00:40:54.0070752Z     Compiling mlir/lib/Support/FileUtilities.cpp; 0s remote-cache
2022-04-22T00:40:54.0632976Z 
2022-04-22T00:40:54.0633458Z �[1A�[K
2022-04-22T00:40:54.0633841Z �[1A�[K
2022-04-22T00:40:54.0634141Z �[1A�[K
2022-04-22T00:40:54.0634398Z �[1A�[K
2022-04-22T00:40:54.0634684Z �[1A�[K
2022-04-22T00:40:54.0634965Z �[1A�[K
2022-04-22T00:40:54.0635238Z �[1A�[K
2022-04-22T00:40:54.0635529Z �[1A�[K
2022-04-22T00:40:54.0636616Z �[1A�[K�[31m�[1mERROR: �[0m/home/jenkins/.cache/bazel/_bazel_jenkins/b463291cb8b07b4bfde1e3a43733cd1a/external/llvm-project/mlir/BUILD.bazel:2992:11: Compiling mlir/lib/Support/TypeID.cpp failed: undeclared inclusion(s) in rule '@llvm-project//mlir:Support':
2022-04-22T00:40:54.0638104Z this rule is missing dependency declarations for the following files included by 'mlir/lib/Support/TypeID.cpp':
2022-04-22T00:40:54.0638859Z   'bazel-out/k8-opt-exec-50AE0418/bin/external/llvm-project/llvm/config.cppmap'
2022-04-22T00:40:54.0639567Z   'bazel-out/k8-opt-exec-50AE0418/bin/external/llvm-project/llvm/Demangle.cppmap'
2022-04-22T00:40:54.0640261Z   'bazel-out/k8-opt-exec-50AE0418/bin/external/llvm_terminfo/terminfo.cppmap'
2022-04-22T00:40:54.0640911Z   'bazel-out/k8-opt-exec-50AE0418/bin/external/llvm_zlib/zlib.cppmap'
2022-04-22T00:40:54.0641421Z �[32m[54 / 6,500]�[0m 13 actions, 12 running
2022-04-22T00:40:54.0641979Z     Compiling mlir/lib/Support/IndentedOstream.cpp; 0s local, remote-cache
2022-04-22T00:40:54.0642580Z     Compiling mlir/lib/Support/Timing.cpp; 0s local, remote-cache
2022-04-22T00:40:54.0643292Z     Compiling mlir/lib/Support/ToolUtilities.cpp; 0s local, remote-cache
2022-04-22T00:40:54.0643936Z     Compiling mlir/lib/Support/StorageUniquer.cpp; 0s local, remote-cache

This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
@priyaramani
Copy link
Contributor Author

@priyaramani has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

elif len(keys) == 0:
return generate_static_dispatch(f, cpp_sig, method=method, backend_index=backend_indices[0])
else:
return f'TORCH_CHECK(false, "Static dispatch does not support backends with multiple kernels");'
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... if you pass in two backends to the codegen (say CPU and QuantizedCPU), then won't the codegen emit this torch check for every f.structured_delegate NativeFunction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The else part is implemented later in the stack #75607. Split them up to keep diff sizes manageable.
Also if we pass in multiple backends for a native function, and if they have a structured_delegate and one or more kernels for the same, then this torch check will be emitted as of this diff.

if len(keys) == 1:
return generate_static_dispatch(f, cpp_sig, method=method, backend_index=keys[0])
elif len(keys) == 0:
return generate_static_dispatch(f, cpp_sig, method=method, backend_index=backend_indices[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the idea behind passing backend_indices[0] here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@larryliu0820
If none of the static dispatch backends have kernels for the native function, then we just pass in the first one in the list, could be any one of them, as in generate_static_dispatch(f, ..) if the backend doesn't have a kernel or if the native function doesn't have a structured delegate we only see if the native function has compositeImplicitAugradKernel or compositeImplicitAugradKernel and use that if not emit a TORCH_CHECK https://github.com/pytorch/pytorch/pull/75605/files#diff-6382c847dac2d011f822c492e61f9fa0eceb47c2d6fc5fb4f0c42af726c1a3aaR283-R288

…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

Is it possible to add a unit test before commit? Just to demonstrate the ability we are adding to static dispatch. You can find two operators with different kernels and write a small model.

…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
…nds"

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels

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

[ghstack-poisoned]
priyaramani added a commit that referenced this pull request Apr 22, 2022
Pull Request resolved: #75605

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels
ghstack-source-id: 154525738

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35510644/)!
facebook-github-bot pushed a commit that referenced this pull request Apr 22, 2022
Summary:
Pull Request resolved: #75605

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels
ghstack-source-id: 154525738

(Note: this ignores all push blocking failures!)

Test Plan:
Builds lite_predictor_flatbuffer with multiple backends

```
buck build --config pt.enable_lightweight_dispatch=1 --config pt.static_dispatch_backend=CPU,QuantizedCPU,CompositeExplicitAutograd //xplat/caffe2/fb/lite_predictor:lite_predictor_flatbuffer
```

Reviewed By: larryliu0820

Differential Revision: D35510644

fbshipit-source-id: f985718ad066f8578b006b4759c4a3bd6caac176
@github-actions
Copy link
Contributor

Hey @priyaramani.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@facebook-github-bot facebook-github-bot deleted the gh/priyaramani/10/head branch April 26, 2022 14:17
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.

4 participants