-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing op_builder.hpu component for HPU accelerator (#4963)
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
'''Copyright The Microsoft DeepSpeed Team''' | ||
|
||
from .cpu_adam import CPUAdamBuilder | ||
from .fused_adam import FusedAdamBuilder | ||
from .no_impl import NotImplementedBuilder |
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,35 @@ | ||
# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
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 # type: ignore | ||
from op_builder.builder import OpBuilder | ||
except ImportError: | ||
from deepspeed.ops.op_builder.builder import OpBuilder | ||
|
||
|
||
class CPUOpBuilder(OpBuilder): | ||
|
||
def builder(self): | ||
from torch.utils.cpp_extension import CppExtension as ExtensionBuilder | ||
|
||
compile_args = {'cxx': self.strip_empty_entries(self.cxx_args())} | ||
|
||
cpp_ext = ExtensionBuilder(name=self.absolute_name(), | ||
sources=self.strip_empty_entries(self.sources()), | ||
include_dirs=self.strip_empty_entries(self.include_paths()), | ||
libraries=self.strip_empty_entries(self.libraries_args()), | ||
extra_compile_args=compile_args) | ||
|
||
return cpp_ext | ||
|
||
def cxx_args(self): | ||
return ['-O3', '-g', '-Wno-reorder'] | ||
|
||
def libraries_args(self): | ||
return [] |
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,33 @@ | ||
# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
from .builder import CPUOpBuilder | ||
|
||
|
||
class CPUAdamBuilder(CPUOpBuilder): | ||
BUILD_VAR = "DS_BUILD_CPU_ADAM" | ||
NAME = "cpu_adam" | ||
|
||
def __init__(self): | ||
super().__init__(name=self.NAME) | ||
|
||
def absolute_name(self): | ||
return f'deepspeed.ops.adam.{self.NAME}_op' | ||
|
||
def sources(self): | ||
return ['csrc/adam/cpu_adam.cpp', 'csrc/adam/cpu_adam_impl.cpp'] | ||
|
||
def cxx_args(self): | ||
args = super().cxx_args() | ||
args += ['-DENABLE_BFLOAT16'] | ||
return args | ||
|
||
def libraries_args(self): | ||
args = super().libraries_args() | ||
return args | ||
|
||
def include_paths(self): | ||
return ['csrc/includes'] |
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,29 @@ | ||
# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
from .builder import CPUOpBuilder | ||
|
||
|
||
class FusedAdamBuilder(CPUOpBuilder): | ||
BUILD_VAR = "DS_BUILD_FUSED_ADAM" | ||
NAME = "fused_adam" | ||
|
||
def __init__(self): | ||
super().__init__(name=self.NAME) | ||
|
||
def absolute_name(self): | ||
return f'deepspeed.ops.adam.{self.NAME}_op' | ||
|
||
def sources(self): | ||
return ['csrc/cpu/adam/fused_adam.cpp', 'csrc/adam/cpu_adam_impl.cpp'] | ||
|
||
def cxx_args(self): | ||
args = super().cxx_args() | ||
args += ['-DENABLE_BFLOAT16'] | ||
return args | ||
|
||
def include_paths(self): | ||
return ['csrc/includes'] |
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,24 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# DeepSpeed Team | ||
|
||
from .builder import CPUOpBuilder | ||
|
||
|
||
class NotImplementedBuilder(CPUOpBuilder): | ||
BUILD_VAR = "DS_BUILD_NOT_IMPLEMENTED" | ||
NAME = "deepspeed_not_implemented" | ||
|
||
def __init__(self, name=None): | ||
name = self.NAME if name is None else name | ||
super().__init__(name=name) | ||
|
||
def absolute_name(self): | ||
return f'deepspeed.ops.comm.{self.NAME}_op' | ||
|
||
def load(self, verbose=True): | ||
raise ValueError("This op had not been implemented on HPU backend.") | ||
|
||
def sources(self): | ||
return [] |