-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
import importlib | ||
|
||
try: | ||
# is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed | ||
# if successful this also means we're doing a local install and not JIT compile path | ||
from op_builder import __deepspeed__ # noqa: F401 | ||
from op_builder.builder import OpBuilder | ||
except ImportError: | ||
from deepspeed.ops.op_builder.builder import OpBuilder | ||
|
||
|
||
class InferenceBuilder(OpBuilder): | ||
BUILD_VAR = "DS_BUILD_TRANSFORMER_INFERENCE" | ||
NAME = "transformer_inference" | ||
|
||
def __init__(self, name=None): | ||
name = self.NAME if name is None else name | ||
super().__init__(name=self.NAME) | ||
|
||
def absolute_name(self): | ||
return f"deepspeed.ops.transformer.inference.{self.NAME}_op" | ||
|
||
def sources(self): | ||
return [] | ||
|
||
def load(self, verbose=True): | ||
if self.name in __class__._loaded_ops: | ||
return __class__._loaded_ops[self.name] | ||
|
||
from deepspeed.git_version_info import installed_ops # noqa: F401 | ||
if installed_ops.get(self.name, False): | ||
op_module = importlib.import_module(self.absolute_name()) | ||
__class__._loaded_ops[self.name] = op_module | ||
return op_module |