fused_adam.py 1.02 KB
Newer Older
aiss's avatar
aiss committed
1
2
3
4
5
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

6
7
from .builder import CUDAOpBuilder

aiss's avatar
aiss committed
8
9
import sys

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

class FusedAdamBuilder(CUDAOpBuilder):
    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/adam/fused_adam_frontend.cpp', 'csrc/adam/multi_tensor_adam.cu']

    def include_paths(self):
aiss's avatar
aiss committed
25
        return ['csrc/includes', 'csrc/adam']
26
27

    def cxx_args(self):
aiss's avatar
aiss committed
28
29
        args = super().cxx_args()
        return args + self.version_dependent_macros()
30
31

    def nvcc_args(self):
aiss's avatar
aiss committed
32
33
        nvcc_flags = ['-O3'] + self.version_dependent_macros()
        if not self.is_rocm_pytorch():
aiss's avatar
aiss committed
34
35
36
            nvcc_flags.extend(
                ['-allow-unsupported-compiler' if sys.platform == "win32" else '', '-lineinfo', '--use_fast_math'] +
                self.compute_capability_args())
aiss's avatar
aiss committed
37
        return nvcc_flags