This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the ONNX Runtime Eager Mode backend (pytorch#58248)
Summary: This PR implements the necessary hooks/stubs/enums/etc for complete ONNX Runtime (ORT) Eager Mode integration. The actual extension will live out of tree at https://github.com/pytorch/ort. We have been [working on this at Microsoft](https://github.com/microsoft/onnxruntime-pytorch/tree/eager-ort/torch_onnxruntime) for the last few months, and are finally ready to contribute the PyTorch core changes upstream (nothing major or exciting, just the usual boilerplate for adding new backends). The ORT backend will allow us to ferry [almost] all torch ops into granular ONNX kernels that ORT will eagerly execute against any devices it supports (therefore, we only need a single ORT backend from a PyTorch perspective). Pull Request resolved: pytorch#58248 Reviewed By: astaff Differential Revision: D30344992 Pulled By: albanD fbshipit-source-id: 69082b32121246340d686e16653626114b7714b2
- Loading branch information
1 parent
b95ce15
commit c78ab28
Showing
38 changed files
with
236 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <ATen/detail/ORTHooksInterface.h> | ||
|
||
#include <c10/util/Exception.h> | ||
|
||
#include <cstddef> | ||
#include <memory> | ||
#include <mutex> | ||
|
||
namespace at { | ||
namespace detail { | ||
|
||
// See getCUDAHooks for some more commentary | ||
const ORTHooksInterface& getORTHooks() { | ||
static std::unique_ptr<ORTHooksInterface> ort_hooks; | ||
static std::once_flag once; | ||
std::call_once(once, [] { | ||
ort_hooks = ORTHooksRegistry()->Create("ORTHooks", {}); | ||
if (!ort_hooks) { | ||
ort_hooks = | ||
// NOLINTNEXTLINE(modernize-make-unique) | ||
std::unique_ptr<ORTHooksInterface>(new ORTHooksInterface()); | ||
} | ||
}); | ||
return *ort_hooks; | ||
} | ||
} // namespace detail | ||
|
||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) | ||
C10_DEFINE_REGISTRY(ORTHooksRegistry, ORTHooksInterface, ORTHooksArgs) | ||
|
||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <c10/util/Exception.h> | ||
#include <c10/util/Registry.h> | ||
|
||
constexpr const char* ORT_HELP = | ||
" You need to 'import torch_ort' to use the 'ort' device in PyTorch. " | ||
"The 'torch_ort' module is provided by the ONNX Runtime itself " | ||
"(https://onnxruntime.ai)."; | ||
|
||
// NB: Class must live in `at` due to limitations of Registry.h. | ||
namespace at { | ||
|
||
struct TORCH_API ORTHooksInterface { | ||
// This should never actually be implemented, but it is used to | ||
// squelch -Werror=non-virtual-dtor | ||
virtual ~ORTHooksInterface() {} | ||
|
||
virtual std::string showConfig() const { | ||
TORCH_CHECK(false, "Cannot query detailed ORT version information.", ORT_HELP); | ||
} | ||
}; | ||
|
||
// NB: dummy argument to suppress "ISO C++11 requires at least one argument | ||
// for the "..." in a variadic macro" | ||
struct TORCH_API ORTHooksArgs {}; | ||
|
||
C10_DECLARE_REGISTRY(ORTHooksRegistry, ORTHooksInterface, ORTHooksArgs); | ||
#define REGISTER_ORT_HOOKS(clsname) \ | ||
C10_REGISTER_CLASS(ORTHooksRegistry, clsname, clsname) | ||
|
||
namespace detail { | ||
TORCH_API const ORTHooksInterface& getORTHooks(); | ||
} // namespace detail | ||
|
||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.