1+ #! /bin/bash
2+ # Script to install DeepGEMM from source
3+ # This script can be used both in Docker builds and by users locally
4+
5+ set -e
6+
7+ # Default values
8+ DEEPGEMM_GIT_REPO=" https://github.com/deepseek-ai/DeepGEMM.git"
9+ DEEPGEMM_GIT_REF=" 7b6b5563b9d4c1ae07ffbce7f78ad3ac9204827c"
10+
11+ # Parse command line arguments
12+ while [[ $# -gt 0 ]]; do
13+ case $1 in
14+ --ref)
15+ if [[ -z " $2 " || " $2 " =~ ^- ]]; then
16+ echo " Error: --ref requires an argument." >&2
17+ exit 1
18+ fi
19+ DEEPGEMM_GIT_REF=" $2 "
20+ shift 2
21+ ;;
22+ --cuda-version)
23+ if [[ -z " $2 " || " $2 " =~ ^- ]]; then
24+ echo " Error: --cuda-version requires an argument." >&2
25+ exit 1
26+ fi
27+ CUDA_VERSION=" $2 "
28+ shift 2
29+ ;;
30+ -h|--help)
31+ echo " Usage: $0 [OPTIONS]"
32+ echo " Options:"
33+ echo " --ref REF Git reference to checkout (default: $DEEPGEMM_GIT_REF )"
34+ echo " --cuda-version VER CUDA version (auto-detected if not provided)"
35+ echo " -h, --help Show this help message"
36+ exit 0
37+ ;;
38+ * )
39+ echo " Unknown option: $1 " >&2
40+ exit 1
41+ ;;
42+ esac
43+ done
44+
45+ # Auto-detect CUDA version if not provided
46+ if [ -z " $CUDA_VERSION " ]; then
47+ if command -v nvcc > /dev/null 2>&1 ; then
48+ CUDA_VERSION=$( nvcc --version | grep " release" | sed -n ' s/.*release \([0-9]\+\.[0-9]\+\).*/\1/p' )
49+ echo " Auto-detected CUDA version: $CUDA_VERSION "
50+ else
51+ echo " Warning: Could not auto-detect CUDA version. Please specify with --cuda-version"
52+ exit 1
53+ fi
54+ fi
55+
56+ # Extract major and minor version numbers
57+ CUDA_MAJOR=" ${CUDA_VERSION%% .* } "
58+ CUDA_MINOR=" ${CUDA_VERSION# ${CUDA_MAJOR} .} "
59+ CUDA_MINOR=" ${CUDA_MINOR%% .* } "
60+
61+ echo " CUDA version: $CUDA_VERSION (major: $CUDA_MAJOR , minor: $CUDA_MINOR )"
62+
63+ # Check CUDA version requirement
64+ if [ " $CUDA_MAJOR " -lt 12 ] || { [ " $CUDA_MAJOR " -eq 12 ] && [ " $CUDA_MINOR " -lt 8 ]; }; then
65+ echo " Skipping DeepGEMM installation (requires CUDA 12.8+ but got ${CUDA_VERSION} )"
66+ exit 0
67+ fi
68+
69+ echo " Installing DeepGEMM from source..."
70+ echo " Repository: $DEEPGEMM_GIT_REPO "
71+ echo " Reference: $DEEPGEMM_GIT_REF "
72+
73+ # Create a temporary directory for the build
74+ INSTALL_DIR=$( mktemp -d)
75+ trap ' rm -rf "$INSTALL_DIR"' EXIT
76+
77+ # Clone the repository
78+ git clone --recursive --shallow-submodules " $DEEPGEMM_GIT_REPO " " $INSTALL_DIR /deepgemm"
79+
80+ echo " 🏗️ Building DeepGEMM"
81+ pushd " $INSTALL_DIR /deepgemm"
82+
83+ # Checkout the specific reference
84+ git checkout " $DEEPGEMM_GIT_REF "
85+
86+ # Build DeepGEMM
87+ # (Based on https://github.com/deepseek-ai/DeepGEMM/blob/main/install.sh)
88+ rm -rf build dist
89+ rm -rf * .egg-info
90+ python3 setup.py bdist_wheel
91+
92+ # Install the wheel
93+ if command -v uv > /dev/null 2>&1 ; then
94+ echo " Installing DeepGEMM wheel using uv..."
95+ # Use --system in Docker contexts, respect user's environment otherwise
96+ if [ -n " $VLLM_DOCKER_BUILD_CONTEXT " ]; then
97+ uv pip install --system dist/* .whl
98+ else
99+ uv pip install dist/* .whl
100+ fi
101+ else
102+ echo " Installing DeepGEMM wheel using pip..."
103+ python3 -m pip install dist/* .whl
104+ fi
105+
106+ popd
107+
108+ echo " ✅ DeepGEMM installation completed successfully"
0 commit comments