Skip to content

Commit da854d7

Browse files
committed
Make CUTLASS detection options configurable and explicit
Signed-off-by: Santi Villalba <sdvillal@gmail.com>
1 parent 16b1e8e commit da854d7

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed

docs/_tutorials/ds4sci_evoformerattention.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ tags: training inference
1313

1414
### 3.1 Installation
1515

16-
`DS4Sci_EvoformerAttention` is released as part of DeepSpeed >= 0.10.3. `DS4Sci_EvoformerAttention` is implemented based on [CUTLASS](https://github.com/NVIDIA/cutlass). You need to clone the CUTLASS repository and specify the path to it in the environment variable `CUTLASS_PATH`.
16+
`DS4Sci_EvoformerAttention` is released as part of DeepSpeed >= 0.10.3.
1717

18+
`DS4Sci_EvoformerAttention` is implemented based on [CUTLASS](https://github.com/NVIDIA/cutlass). You need to clone the CUTLASS repository and specify the path to it in the environment variable `CUTLASS_PATH`.
19+
CUTLASS setup detection can be ignored by setting ```CUTLASS_PATH="DS_IGNORE_CUTLASS_DETECTION"```, which is useful if you have a well setup compiler (e.g., compiling in a conda package with cutlass and the cuda compilers installed).
20+
CUTLASS location can be automatically inferred using pypi's [nvidia-cutlass](https://pypi.org/project/nvidia-cutlass/) package by setting ```CUTLASS_PATH="DS_USE_CUTLASS_PYTHON_BINDINGS"```. Note that this is discouraged as ```nvidia-cutlass``` is not maintained anymore and outdated.
21+
22+
You can always simply clone cutlass and setup ```CUTLASS_PATH```:
1823
```shell
1924
git clone https://github.com/NVIDIA/cutlass
2025
export CUTLASS_PATH=/path/to/cutlass

op_builder/evoformer_attn.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from .builder import CUDAOpBuilder, installed_cuda_version
77
import os
8-
from packaging.version import Version
8+
from pathlib import Path
99

1010

1111
class EvoformerAttnBuilder(CUDAOpBuilder):
@@ -37,28 +37,25 @@ def is_compatible(self, verbose=False):
3737
if verbose:
3838
self.warning("Please install torch if trying to pre-compile kernels")
3939
return False
40+
4041
if self.cutlass_path is None:
4142
if verbose:
42-
self.warning("Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH")
43+
self.warning("Please specify CUTLASS location directory as environment variable CUTLASS_PATH")
44+
self.warning("Possible values are: a path, DS_IGNORE_CUTLASS_DETECTION and DS_USE_CUTLASS_PYTHON_BINDINGS")
4345
return False
44-
if os.path.exists(f'{self.cutlass_path}/CHANGELOG.md'):
45-
with open(f'{self.cutlass_path}/CHANGELOG.md', 'r') as f:
46-
if '3.1.0' not in f.read():
47-
if verbose:
48-
self.warning("Please use CUTLASS version >= 3.1.0")
49-
return False
50-
else:
51-
# pip install nvidia-cutlass package
46+
47+
if self.cutlass_path != "DS_IGNORE_CUTLASS_DETECTION":
5248
try:
53-
import cutlass
54-
except ImportError:
55-
if verbose:
56-
self.warning("Please pip install nvidia-cutlass if trying to pre-compile kernels")
57-
return False
58-
if Version(cutlass.__version__) < Version('3.1.0'):
59-
if verbose:
60-
self.warning("Please use CUTLASS version >= 3.1.0")
49+
self.include_paths()
50+
except (RuntimeError, ImportError):
6151
return False
52+
# Check version in case it is a CUTLASS_PATH points to a CUTLASS checkout
53+
if os.path.exists(f'{self.cutlass_path}/CHANGELOG.md'):
54+
with open(f'{self.cutlass_path}/CHANGELOG.md', 'r') as f:
55+
if '3.1.0' not in f.read():
56+
if verbose:
57+
self.warning("Please use CUTLASS version >= 3.1.0")
58+
return False
6259

6360
cuda_okay = True
6461
if not self.is_rocm_pytorch() and torch.cuda.is_available(): #ignore-cuda
@@ -76,5 +73,27 @@ def is_compatible(self, verbose=False):
7673
return super().is_compatible(verbose) and cuda_okay
7774

7875
def include_paths(self):
79-
includes = [f'{self.cutlass_path}/include', f'{self.cutlass_path}/tools/util/include']
80-
return includes
76+
# Assume the user knows best and CUTLASS location is already setup externally
77+
if self.cutlass_path == "DS_IGNORE_CUTLASS_DETECTION":
78+
return []
79+
# Use header files vendored with deprecated python packages
80+
if self.cutlass_path == "DS_USE_CUTLASS_PYTHON_BINDINGS":
81+
try:
82+
import cutlass_library
83+
cutlass_path = Path(cutlass_library.__file__).parent / "source"
84+
except ImportError:
85+
self.warning(
86+
"Please pip install nvidia-cutlass (note that this is deprecated and likely outdated)"
87+
)
88+
raise
89+
# Use hardcoded path in CUTLASS_PATH
90+
else:
91+
cutlass_path = Path(self.cutlass_path)
92+
cutlass_path = cutlass_path.resolve()
93+
if not cutlass_path.is_dir():
94+
raise RuntimeError(f"CUTLASS_PATH {cutlass_path} does not exist")
95+
include_dirs = cutlass_path / "include", cutlass_path / "tools" / "util" / "include"
96+
include_dirs = [include_dir for include_dir in include_dirs if include_dir.is_dir()]
97+
if not include_dirs:
98+
raise RuntimeError(f"CUTLASS_PATH {cutlass_path} does not contain any include directories")
99+
return include_dirs

0 commit comments

Comments
 (0)