@@ -26,28 +26,25 @@ conda activate "$CONDA_ENV"
26
26
# Create cache directory
27
27
mkdir -p " $TRITON_CACHE_DIR "
28
28
29
- # Check if Triton is already installed and working
30
- if python -c " import triton; print(f'Triton version: {triton.__version__}')" 2> /dev/null; then
31
- echo " Triton is already installed, checking commit compatibility..."
32
-
33
- # Check if the cached commit matches the target commit
34
- if [ -f " $TRITON_CACHE_DIR /commit" ]; then
35
- CACHED_COMMIT=$( cat " $TRITON_CACHE_DIR /commit" )
36
- if [ " $CACHED_COMMIT " = " $TRITON_COMMIT " ] && [ " $TRITON_COMMIT " != " main" ]; then
37
- echo " Triton is already installed with correct commit ($CACHED_COMMIT ), skipping installation"
38
- exit 0
39
- elif [ " $TRITON_COMMIT " = " main" ]; then
40
- echo " Target is 'main' branch (API fallback), will reinstall to get latest"
41
- echo " Cached commit: $CACHED_COMMIT "
42
- else
43
- echo " Triton installed but commit mismatch: cached=$CACHED_COMMIT , target=$TRITON_COMMIT "
44
- echo " Will reinstall Triton..."
45
- fi
29
+ # Check if we have cached source with correct commit
30
+ if [ -f " $TRITON_CACHE_DIR /commit" ] && [ -d " $TRITON_SOURCE_DIR " ]; then
31
+ CACHED_COMMIT=$( cat " $TRITON_CACHE_DIR /commit" )
32
+ if [ " $CACHED_COMMIT " = " $TRITON_COMMIT " ] && [ " $TRITON_COMMIT " != " main" ]; then
33
+ echo " Found cached Triton source with correct commit ($CACHED_COMMIT )"
34
+ echo " Will use cached source and re-install to new conda environment"
35
+ USE_CACHED_SOURCE=true
36
+ elif [ " $TRITON_COMMIT " = " main" ]; then
37
+ echo " Target is 'main' branch (API fallback), will rebuild from scratch"
38
+ echo " Cached commit: $CACHED_COMMIT "
39
+ USE_CACHED_SOURCE=false
46
40
else
47
- echo " Triton installed but no commit info found, will reinstall..."
41
+ echo " Cached source commit mismatch: cached=$CACHED_COMMIT , target=$TRITON_COMMIT "
42
+ echo " Will rebuild from scratch"
43
+ USE_CACHED_SOURCE=false
48
44
fi
49
45
else
50
- echo " Triton not installed or not working, proceeding with installation..."
46
+ echo " No cached source found or no commit info, will build from scratch"
47
+ USE_CACHED_SOURCE=false
51
48
fi
52
49
53
50
# Update libstdc++ to match system version
@@ -71,25 +68,28 @@ if [ -n "$TRITON_PKG_DIR" ] && [ -d "$TRITON_PKG_DIR" ]; then
71
68
rm -rf " $TRITON_PKG_DIR "
72
69
fi
73
70
74
- # Clone or update Triton repository
75
- echo " Setting up Triton repository..."
76
- if [ -d " $TRITON_SOURCE_DIR " ]; then
71
+ # Setup Triton repository based on cache status
72
+ if [ " $USE_CACHED_SOURCE " = " true" ]; then
77
73
echo " Using cached Triton source..."
78
74
cd " $TRITON_SOURCE_DIR "
79
- # Reset to clean state and fetch latest
80
- git reset --hard HEAD
81
- git clean -fd
82
- git fetch origin
75
+ ACTUAL_COMMIT=$( git rev-parse HEAD)
76
+ echo " Using cached Triton commit: $ACTUAL_COMMIT "
83
77
else
78
+ echo " Setting up Triton repository from scratch..."
79
+ if [ -d " $TRITON_SOURCE_DIR " ]; then
80
+ echo " Removing existing source directory..."
81
+ rm -rf " $TRITON_SOURCE_DIR "
82
+ fi
83
+
84
84
echo " Cloning Triton repository..."
85
85
git clone https://github.com/triton-lang/triton.git " $TRITON_SOURCE_DIR "
86
86
cd " $TRITON_SOURCE_DIR "
87
- fi
88
87
89
- # Checkout specific commit for reproducibility
90
- git checkout " $TRITON_COMMIT "
91
- ACTUAL_COMMIT=$( git rev-parse HEAD)
92
- echo " Using Triton commit: $ACTUAL_COMMIT "
88
+ # Checkout specific commit for reproducibility
89
+ git checkout " $TRITON_COMMIT "
90
+ ACTUAL_COMMIT=$( git rev-parse HEAD)
91
+ echo " Using Triton commit: $ACTUAL_COMMIT "
92
+ fi
93
93
94
94
# Install build dependencies
95
95
echo " Installing build dependencies..."
@@ -107,7 +107,13 @@ echo "Using CC: $CC"
107
107
echo " Using CXX: $CXX "
108
108
109
109
# Install Triton in editable mode with clang
110
- echo " Installing Triton in editable mode with clang..."
110
+ if [ " $USE_CACHED_SOURCE " = " true" ]; then
111
+ echo " Installing cached Triton to new conda environment..."
112
+ echo " This should be fast since build artifacts are cached"
113
+ else
114
+ echo " Compiling and installing Triton from scratch..."
115
+ echo " This will take 30-50 minutes for compilation"
116
+ fi
111
117
pip install -e .
112
118
113
119
# Verify Triton installation
@@ -124,6 +130,6 @@ python -c "import triton; print(f'Triton version: {triton.__version__}')" || {
124
130
python -c " import triton; print(f'Triton path: {triton.__file__}')"
125
131
126
132
# Save commit info for cache validation
127
- echo " $ACTUAL_COMMIT " > " $TRITON_CACHE_DIR /commit"
133
+ echo " $ACTUAL_COMMIT " > " $TRITON_CACHE_DIR /commit"
128
134
129
135
echo " Triton installation completed successfully!"
0 commit comments