Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions csrc/includes/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ class TrainingContext {
_gemm_algos.push_back(test_attn_context->TestAlgo(100));
} else {
// Use default algo.
_gemm_algos.push_back(std::array<int, 3>({99, 99, 99}));
_gemm_algos.push_back(std::array<int, 3>({99, 99, 99}));
_gemm_algos.push_back(std::array<int, 3>({99, 99, 99}));
_gemm_algos.push_back(std::array<int, 3>({99, 99, 99}));
_gemm_algos.push_back(std::array<int, 3>({99, 99, 99}));
// hipify maps this name for ROCm, but would not map its CUDA value 99.
const int default_algo = CUBLAS_GEMM_DEFAULT_TENSOR_OP;
_gemm_algos.push_back(std::array<int, 3>({default_algo, default_algo, default_algo}));
_gemm_algos.push_back(std::array<int, 3>({default_algo, default_algo, default_algo}));
_gemm_algos.push_back(std::array<int, 3>({default_algo, default_algo, default_algo}));
_gemm_algos.push_back(std::array<int, 3>({default_algo, default_algo, default_algo}));
_gemm_algos.push_back(std::array<int, 3>({default_algo, default_algo, default_algo}));
}
}

Expand Down
9 changes: 9 additions & 0 deletions op_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@ class CUDAOpBuilder(OpBuilder):
# filter_ccs() drops older build targets, and is_compatible() requires torch and, when a GPU is visible, a CUDA
# toolkit and a GPU that is not older.
MIN_COMPUTE_CAPABILITY = None
# False for an op that only builds with CUDA, which is_compatible() then rejects when torch is built with ROCm.
# Builders that override is_compatible() call it first, so ROCm is reported rather than a missing dependency.
ROCM_SUPPORTED = True

def __init__(self, name):
super().__init__(name)
Expand Down Expand Up @@ -780,6 +783,12 @@ def filter_ccs(self, ccs: List[CudaArch]):
return ccs_retained

def is_compatible(self, verbose=False):
if not self.ROCM_SUPPORTED and self.is_rocm_pytorch():
# Recorded even when not verbose, so that jit_load() can report it as the reason.
self.error_log = f"{self.name} is not supported on ROCm"
if verbose:
self.warning(self.error_log)
return False
if self.MIN_COMPUTE_CAPABILITY is None:
return super().is_compatible(verbose)
# setup.py checks every op, even when torch is not installed.
Expand Down
10 changes: 5 additions & 5 deletions op_builder/evoformer_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EvoformerAttnBuilder(CUDAOpBuilder):
BUILD_VAR = "DS_BUILD_EVOFORMER_ATTN"
NAME = "evoformer_attn"
MIN_COMPUTE_CAPABILITY = 7 # The kernels use Tensor Cores.
ROCM_SUPPORTED = False # The kernels are built on CUTLASS.
CUTLASS_IGNORE = "DS_IGNORE_CUTLASS_DETECTION"
CUTLASS_PYTHON_BINDINGS = "DS_USE_CUTLASS_PYTHON_BINDINGS"

Expand All @@ -27,10 +28,7 @@ def absolute_name(self):
return f"deepspeed.ops.{self.NAME}_op"

def extra_ldflags(self):
if not self.is_rocm_pytorch():
return ["-lcurand"]
else:
return []
return ["-lcurand"]

def sources(self):
src_dir = "csrc/deepspeed4science/evoformer_attn"
Expand All @@ -43,6 +41,8 @@ def nvcc_args(self):
return super().nvcc_args()

def is_compatible(self, verbose=False):
if not super().is_compatible(verbose):
return False
if self.cutlass_path != self.CUTLASS_IGNORE:
try:
self.include_paths()
Expand All @@ -62,7 +62,7 @@ def is_compatible(self, verbose=False):
self.warning("Please use CUTLASS version >= 3.1.0")
return False

return super().is_compatible(verbose)
return True

@staticmethod
def _repo_root():
Expand Down
7 changes: 3 additions & 4 deletions op_builder/gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class GDSBuilder(CUDAOpBuilder):
BUILD_VAR = "DS_BUILD_GDS"
NAME = "gds"
ROCM_SUPPORTED = False # GPUDirect Storage (cuFile) is CUDA only.

def __init__(self):
super().__init__(name=self.NAME)
Expand Down Expand Up @@ -50,9 +51,7 @@ def load(self, verbose=False):
return super().load(verbose=verbose)

def is_compatible(self, verbose=False):
if self.is_rocm_pytorch():
if verbose:
self.warning(f'{self.NAME} is not compatible with ROCM')
if not super().is_compatible(verbose):
return False

try:
Expand All @@ -77,4 +76,4 @@ def is_compatible(self, verbose=False):
),
verbose=verbose)

return gds_compatible and self.async_io.is_compatible(verbose) and super().is_compatible(verbose)
return gds_compatible and self.async_io.is_compatible(verbose)
1 change: 1 addition & 0 deletions op_builder/inference_core_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class InferenceCoreBuilder(CUDAOpBuilder):
BUILD_VAR = "DS_BUILD_INFERENCE_CORE_OPS"
NAME = "inference_core_ops"
MIN_COMPUTE_CAPABILITY = 6
ROCM_SUPPORTED = False # The sources do not build with ROCm yet.

def __init__(self, name=None):
name = self.NAME if name is None else name
Expand Down
15 changes: 15 additions & 0 deletions op_builder/inference_cutlass_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class InferenceCutlassBuilder(CUDAOpBuilder):
BUILD_VAR = "DS_BUILD_CUTLASS_OPS"
NAME = "cutlass_ops"
MIN_COMPUTE_CAPABILITY = 8 # Only support Ampere and newer.
ROCM_SUPPORTED = False # The op links CUDA libraries from deepspeed-kernels.

def __init__(self, name=None):
name = self.NAME if name is None else name
Expand All @@ -34,6 +35,20 @@ def sources(self):
sources = [os.path.join(prefix, src) for src in sources]
return sources

def is_compatible(self, verbose=False):
if not super().is_compatible(verbose):
return False
# The op links libraries shipped by the deepspeed-kernels package, which DeepSpeed does not install.
try:
import dskernels # noqa: F401
except ImportError:
# Recorded even when not verbose, so that jit_load() can report it as the reason.
self.error_log = f"{self.name} requires dskernels, please pip install deepspeed-kernels"
if verbose:
self.warning(self.error_log)
return False
return True

def extra_ldflags(self):
import dskernels
lib_path = dskernels.library_path()
Expand Down
15 changes: 15 additions & 0 deletions op_builder/ragged_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RaggedOpsBuilder(CUDAOpBuilder):
BUILD_VAR = "DS_BUILD_RAGGED_DEVICE_OPS"
NAME = "ragged_device_ops"
MIN_COMPUTE_CAPABILITY = 8 # Blocked flash has a dependency on Ampere + newer.
ROCM_SUPPORTED = False # The op links CUDA libraries from deepspeed-kernels.

def __init__(self, name=None):
name = self.NAME if name is None else name
Expand Down Expand Up @@ -48,6 +49,20 @@ def sources(self):
sources = [os.path.join(prefix, src) for src in sources]
return sources

def is_compatible(self, verbose=False):
if not super().is_compatible(verbose):
return False
# The op links libraries shipped by the deepspeed-kernels package, which DeepSpeed does not install.
try:
import dskernels # noqa: F401
except ImportError:
# Recorded even when not verbose, so that jit_load() can report it as the reason.
self.error_log = f"{self.name} requires dskernels, please pip install deepspeed-kernels"
if verbose:
self.warning(self.error_log)
return False
return True

def extra_ldflags(self):
import dskernels
lib_path = dskernels.library_path()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.inference_utils import ActivationType, DtypeEnum
from deepspeed.inference.v2.kernels.core_ops import CUDABiasActivation
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import get_dtypes, allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)
Comment thread
hwchen2017 marked this conversation as resolved.
Resolved


def reference_bias_act_implementation(input: torch.Tensor, bias: Optional[torch.Tensor],
act_type: ActivationType) -> torch.Tensor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.core_ops import BlasLibLinear
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)

# Note: only testing with FP16 and BF16 because we use TF32 on Ampere and we don't have a good
# set of tolerances. Since this is just on top of BLAS though, the test is more about
# making sure the stride/contiguity is correct and that's data type agnostic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.core_ops import CUDAGatedActivation
from deepspeed.inference.v2.inference_utils import ActivationType
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import get_dtypes, allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)


def reference_geglu_implementation(input: torch.Tensor,
bias: Optional[torch.Tensor] = None,
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/inference/v2/kernels/core_ops/test_post_ln.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.core_ops import CUDAFPPostLN
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import get_dtypes, allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)


def reference_implementation(residual: torch.Tensor, hidden_states: torch.Tensor, gamma: torch.Tensor,
beta: torch.Tensor, epsilon: float) -> torch.Tensor:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/inference/v2/kernels/core_ops/test_pre_ln.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.core_ops import CUDAFPPreLN
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import get_dtypes, allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)


def reference_implementation(residual: torch.Tensor, hidden_states: torch.Tensor, gamma: torch.Tensor,
beta: torch.Tensor, epsilon: float) -> torch.Tensor:
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/inference/v2/kernels/core_ops/test_rms_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.inference_utils import DtypeEnum
from deepspeed.inference.v2.kernels.core_ops import CUDARMSNorm, CUDARMSPreNorm
from deepspeed.ops.op_builder import InferenceCoreBuilder
from ....v2.inference_test_utils import get_dtypes, allclose

if not deepspeed.ops.__compatible_ops__[InferenceCoreBuilder.NAME]:
pytest.skip("Inference core ops are not available on this system", allow_module_level=True)


def reference_rms_norm(vals: torch.Tensor, gamma: torch.Tensor, epsilon: float = 1e-5) -> torch.Tensor:
variance = vals.to(torch.float32).pow(2).mean(-1, keepdim=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.inference_utils import ActivationType, DtypeEnum
from deepspeed.inference.v2.kernels.cutlass_ops import MoEGEMM
from deepspeed.ops.op_builder import InferenceCutlassBuilder
from ....v2.inference_test_utils import allclose

if not deepspeed.ops.__compatible_ops__[InferenceCutlassBuilder.NAME]:
pytest.skip("Cutlass ops are not available on this system", allow_module_level=True)

SINGLE_EXPERT_CASES = [(13, 2048, 2048), (256, 1024, 4096), (278, 5120, 2048), (893, 5120, 2560)]

PYTORCH_ACT_FN_MAP = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import pytest
import torch

import deepspeed
from deepspeed.inference.v2.kernels.ragged_ops import AtomBuilder
from deepspeed.ops.op_builder import RaggedOpsBuilder
from .ragged_testing_utils import build_complex_batch

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)

Q_BLOCK_SIZE = 128
KV_BLOCK_SIZE = 128

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.inference_utils import DtypeEnum
from deepspeed.inference.v2.kernels.ragged_ops import (
Expand All @@ -20,11 +21,14 @@
LinearBlockedKVCopy,
)
from deepspeed.inference.v2.ragged import split_kv
from deepspeed.ops.op_builder import RaggedUtilsBuilder
from deepspeed.ops.op_builder import RaggedOpsBuilder, RaggedUtilsBuilder

from .ragged_testing_utils import build_batch_and_manager
from ....v2.inference_test_utils import allclose

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)

try:
from flash_attn.flash_attn_interface import flash_attn_varlen_func
validate_accuracy = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.ragged_ops import LinearBlockedKVCopy
from deepspeed.ops.op_builder import RaggedOpsBuilder
from .ragged_testing_utils import build_batch_and_manager, validate_kv_cache

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)


@pytest.mark.inference_v2_ops
@pytest.mark.parametrize("n_tokens, history_size", [(1, 0), (17, 0), (33, 8), (63, 1)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.ragged_ops import BlockedRotaryEmbeddings, BlockedTrainedRotaryEmbeddings
from deepspeed.inference.v2.ragged import RaggedBatchWrapper, DSSequenceDescriptor
from deepspeed.ops.op_builder import RaggedOpsBuilder
from .ragged_testing_utils import build_batch_and_manager, validate_kv_cache
from ....v2.inference_test_utils import allclose

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)
"""
NOTE(cmikeh2): It is very possible to see unit test failures (even on FP16) depending on when
certain values are casted up to or down from float32. If we are seeing accuracy issues, we should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.kernels.ragged_ops import RaggedLogitsGather
from deepspeed.ops.op_builder import RaggedOpsBuilder
from ....v2.inference_test_utils import allclose, get_dtypes
from .ragged_testing_utils import build_simple_batch

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)


def baseline_implementation(hidden_states: torch.Tensor, seq_lens: List[int]) -> torch.Tensor:
output = torch.empty((len(seq_lens), hidden_states.shape[1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import pytest
import torch

import deepspeed
from deepspeed.accelerator import get_accelerator
from deepspeed.inference.v2.inference_utils import DtypeEnum
from deepspeed.inference.v2.kernels.ragged_ops import (
MoEGather,
MoEScatter,
RaggedTopKGating,
)
from deepspeed.ops.op_builder import RaggedOpsBuilder
from .ragged_testing_utils import build_simple_batch

if not deepspeed.ops.__compatible_ops__[RaggedOpsBuilder.NAME]:
pytest.skip("Ragged device ops are not available on this system", allow_module_level=True)
"""
For simplicity's sake, these tests do rely on ``RaggedTopKGating`` and
``MoEScatter`` to produce correct inputs. If either of these kernels is broken
Expand Down
Loading
Loading