fused_adam.py 1 KB
Newer Older
Samyam Rajbhandari's avatar
Samyam Rajbhandari committed
1
2
3
"""
Copyright 2020 The Microsoft DeepSpeed Team
"""
4
5
from .builder import CUDAOpBuilder

aiss's avatar
aiss committed
6
7
import sys

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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
23
        return ['csrc/includes', 'csrc/adam']
24
25

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

    def nvcc_args(self):
aiss's avatar
aiss committed
30
31
        nvcc_flags = ['-O3'] + self.version_dependent_macros()
        if not self.is_rocm_pytorch():
aiss's avatar
aiss committed
32
33
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