|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Install Triton kernels from triton-lang/triton/python/triton_kernels |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +echo "🚀 Installing Triton kernels from triton-lang/triton/python/triton_kernels..." |
| 8 | +START_TIME=$(date +%s) |
| 9 | + |
| 10 | +# Function to show elapsed time |
| 11 | +show_elapsed() { |
| 12 | + CURRENT_TIME=$(date +%s) |
| 13 | + ELAPSED=$((CURRENT_TIME - START_TIME)) |
| 14 | + echo "⏱️ Elapsed time: ${ELAPSED}s" |
| 15 | +} |
| 16 | + |
| 17 | +# Set Triton version/commit for cache consistency |
| 18 | +TRITON_COMMIT=${TRITON_COMMIT:-"main"} |
| 19 | +echo "🎯 Target Triton commit/branch: $TRITON_COMMIT" |
| 20 | +TRITON_SOURCE_DIR="/tmp/triton" |
| 21 | + |
| 22 | +# Ensure we're in the conda environment |
| 23 | +if [ -z "$CONDA_ENV" ]; then |
| 24 | + echo "ERROR: CONDA_ENV is not set" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Activate conda environment |
| 29 | +source /opt/miniconda3/etc/profile.d/conda.sh |
| 30 | +conda activate "$CONDA_ENV" |
| 31 | + |
| 32 | +# Ensure TRITON_SOURCE_DIR contains Triton source; otherwise, clone it |
| 33 | +echo "🔧 Ensuring Triton source exists at $TRITON_SOURCE_DIR..." |
| 34 | + |
| 35 | +if [ -d "$TRITON_SOURCE_DIR/.git" ]; then |
| 36 | + REMOTE_URL=$(git -C "$TRITON_SOURCE_DIR" remote get-url origin 2>/dev/null || echo "") |
| 37 | + if [[ "$REMOTE_URL" == *"triton-lang/triton"* ]]; then |
| 38 | + echo "✅ Found existing Triton repository: $REMOTE_URL" |
| 39 | + else |
| 40 | + echo "⚠️ Existing directory is not triton-lang/triton (origin: $REMOTE_URL). Re-cloning..." |
| 41 | + rm -rf "$TRITON_SOURCE_DIR" |
| 42 | + fi |
| 43 | +fi |
| 44 | + |
| 45 | +if [ ! -d "$TRITON_SOURCE_DIR/.git" ]; then |
| 46 | + echo "Cloning Triton repository..." |
| 47 | + if ! git clone https://github.com/triton-lang/triton.git "$TRITON_SOURCE_DIR"; then |
| 48 | + echo "❌ ERROR: Failed to clone Triton repository" |
| 49 | + echo "This might be due to network issues or GitHub rate limiting" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +fi |
| 53 | + |
| 54 | +echo "Checking out Triton commit/branch: $TRITON_COMMIT" |
| 55 | +if ! git -C "$TRITON_SOURCE_DIR" checkout "$TRITON_COMMIT"; then |
| 56 | + echo "❌ ERROR: Failed to checkout $TRITON_COMMIT" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +# Install triton_kernels in editable mode |
| 61 | +KERNELS_DIR="$TRITON_SOURCE_DIR/python/triton_kernels" |
| 62 | +if [ ! -d "$KERNELS_DIR" ]; then |
| 63 | + echo "❌ ERROR: triton_kernels directory not found at $KERNELS_DIR" |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | + |
| 67 | +echo "📦 Installing triton_kernels from $KERNELS_DIR (editable)..." |
| 68 | +pip install -e "$KERNELS_DIR" |
| 69 | +show_elapsed |
| 70 | + |
| 71 | +# Verify installation with a simple import |
| 72 | +echo "🔎 Verifying triton_kernels installation..." |
| 73 | +set +e |
| 74 | +KERNELS_IMPORT_OUTPUT=$(python -c "import triton_kernels; import os; print('triton_kernels OK'); print(getattr(triton_kernels, '__file__', 'no_file'))" 2>&1) |
| 75 | +KERNELS_IMPORT_EXITCODE=$? |
| 76 | +set -e |
| 77 | + |
| 78 | +echo "Import exit code: $KERNELS_IMPORT_EXITCODE" |
| 79 | +echo "Import output: $KERNELS_IMPORT_OUTPUT" |
| 80 | + |
| 81 | +if [ $KERNELS_IMPORT_EXITCODE -ne 0 ]; then |
| 82 | + echo "❌ ERROR: Failed to import triton_kernels" |
| 83 | + exit 1 |
| 84 | +fi |
| 85 | + |
| 86 | +echo "✅ triton_kernels installation verified" |
| 87 | +show_elapsed |
0 commit comments