|
1 | | -# This workflow builds and publishes Python distributions to PyPI. |
2 | | -# It uses a self-hosted runner and a PyTorch container image |
3 | | -# to ensure the correct CUDA environment is available for the build. |
4 | | -# It relies on Trusted Publishing for secure authentication with PyPI. |
5 | | - |
6 | 1 | name: Build and Publish Python 🐍 distributions |
7 | 2 |
|
8 | 3 | on: |
|
12 | 7 |
|
13 | 8 | jobs: |
14 | 9 | build-wheels: |
15 | | - name: Build wheel for ${{ matrix.variant.name }} on self-hosted |
16 | | - runs-on: self-hosted |
17 | | - |
18 | | - container: |
19 | | - image: pytorch/pytorch:2.3.1-cuda12.1-cudnn8-devel |
20 | | - |
| 10 | + name: Build wheel for ${{ matrix.variant.name }} on ${{ matrix.variant.os }} (Python ${{ matrix.variant.python-version }}) |
| 11 | + runs-on: ${{ matrix.variant.os }} |
21 | 12 | strategy: |
22 | 13 | fail-fast: false |
23 | 14 | matrix: |
24 | 15 | variant: |
25 | | - - { |
26 | | - name: "cuda", |
27 | | - python-version: "3.10", |
28 | | - cuda-version: "12.1", |
29 | | - compute-caps: "80", |
30 | | - } |
| 16 | + # Default variant |
| 17 | + - { name: "default", os: "macos-latest", python-version: "3.9" } |
| 18 | + - { name: "default", os: "macos-latest", python-version: "3.10" } |
| 19 | + - { name: "default", os: "macos-latest", python-version: "3.11" } |
| 20 | + - { name: "default", os: "macos-latest", python-version: "3.12" } |
| 21 | + - { name: "default", os: "macos-latest", python-version: "3.13" } |
| 22 | + - { name: "default", os: "ubuntu-latest", python-version: "3.9" } |
| 23 | + - { name: "default", os: "ubuntu-latest", python-version: "3.10" } |
| 24 | + - { name: "default", os: "ubuntu-latest", python-version: "3.11" } |
| 25 | + - { name: "default", os: "ubuntu-latest", python-version: "3.12" } |
| 26 | + - { name: "default", os: "ubuntu-latest", python-version: "3.13" } |
| 27 | + # Metal variant |
| 28 | + - { name: "metal", os: "macos-latest", python-version: "3.9" } |
| 29 | + - { name: "metal", os: "macos-latest", python-version: "3.10" } |
| 30 | + - { name: "metal", os: "macos-latest", python-version: "3.11" } |
| 31 | + - { name: "metal", os: "macos-latest", python-version: "3.12" } |
| 32 | + - { name: "metal", os: "macos-latest", python-version: "3.13" } |
| 33 | + # Accelerate variant |
| 34 | + - { name: "accelerate", os: "macos-latest", python-version: "3.9" } |
| 35 | + - { name: "accelerate", os: "macos-latest", python-version: "3.10" } |
| 36 | + - { name: "accelerate", os: "macos-latest", python-version: "3.11" } |
| 37 | + - { name: "accelerate", os: "macos-latest", python-version: "3.12" } |
| 38 | + - { name: "accelerate", os: "macos-latest", python-version: "3.13" } |
31 | 39 |
|
32 | 40 | steps: |
33 | 41 | - name: Checkout repository |
34 | 42 | uses: actions/checkout@v4 |
35 | 43 |
|
36 | | - - name: Install build dependencies |
37 | | - run: | |
38 | | - apt-get update |
39 | | - apt-get install -y --no-install-recommends build-essential curl libssl-dev pkg-config unzip zip |
40 | | - shell: bash |
| 44 | + - name: Set up Python ${{ matrix.variant.python-version }} |
| 45 | + uses: actions/setup-python@v5 |
| 46 | + with: |
| 47 | + python-version: ${{ matrix.variant.python-version }} |
41 | 48 |
|
42 | 49 | - name: Install Rust |
43 | 50 | uses: dtolnay/rust-toolchain@stable |
44 | 51 |
|
45 | | - - name: Install Python build dependencies |
| 52 | + - name: Install dependencies |
46 | 53 | run: pip install maturin>=1.8.6 numpy>=1.26.4 |
47 | 54 |
|
48 | | - - name: Generate pyproject.toml |
| 55 | + - name: Generate pyproject.toml for ${{ matrix.variant.name }} |
49 | 56 | run: python generate_configs.py ${{ matrix.variant.name }} |
50 | 57 |
|
51 | | - - name: Find NVIDIA Driver Library Path |
52 | | - id: find_cuda_lib |
53 | | - run: | |
54 | | - LIB_PATH=$(find / -name libcuda.so.1 2>/dev/null | head -n 1) |
55 | | - if [ -z "$LIB_PATH" ]; then |
56 | | - echo "::error::libcuda.so.1 not found on the runner. Please ensure the NVIDIA driver is correctly installed and accessible within the container." |
57 | | - exit 1 |
58 | | - fi |
59 | | - LIB_DIR=$(dirname "$LIB_PATH") |
60 | | - echo "Found libcuda.so.1 in: $LIB_DIR" |
61 | | - echo "CUDA_LIB_DIR=$LIB_DIR" >> $GITHUB_ENV |
62 | | - shell: bash |
63 | | - |
64 | 58 | - name: Build wheel |
65 | | - env: |
66 | | - LD_LIBRARY_PATH: ${{ env.CUDA_LIB_DIR }}:${LD_LIBRARY_PATH} |
67 | | - CUDA_COMPUTE_CAP: ${{ matrix.variant.compute-caps }} |
68 | 59 | run: maturin build --release --out dist |
69 | | - shell: bash |
70 | | - |
71 | | - - name: Strip CUDA libraries and Verify |
72 | | - run: | |
73 | | - set -e |
74 | | - echo "--- Stripping CUDA libraries from the wheel ---" |
75 | | - # Get the full path to the original wheel file |
76 | | - ORIGINAL_WHEEL_PATH=$(ls dist/*.whl) |
77 | | - echo "Original wheel size:" |
78 | | - ls -lh "$ORIGINAL_WHEEL_PATH" |
79 | | -
|
80 | | - # Get just the filename of the wheel |
81 | | - WHEEL_FILENAME=$(basename "$ORIGINAL_WHEEL_PATH") |
82 | | -
|
83 | | - # Create a temporary directory for unpacking |
84 | | - UNPACK_DIR=$(mktemp -d) |
85 | | - unzip -q "$ORIGINAL_WHEEL_PATH" -d "$UNPACK_DIR" |
86 | | -
|
87 | | - echo "Deleting CUDA libraries..." |
88 | | - # This find command will print the files being deleted, which is useful for debugging. |
89 | | - find "$UNPACK_DIR" -type f \( \ |
90 | | - -name 'libc*.so*' \ |
91 | | - \) -print -delete |
92 | | -
|
93 | | - echo "Re-packing the wheel..." |
94 | | - # The new wheel will be created with the original filename inside UNPACK_DIR |
95 | | - (cd "$UNPACK_DIR" && zip -r -q "$WHEEL_FILENAME" .) |
96 | | -
|
97 | | - # Move the newly created wheel from UNPACK_DIR back to the dist directory |
98 | | - # and overwrite the original (unstripped) wheel. |
99 | | - mv "$UNPACK_DIR/$WHEEL_FILENAME" "$ORIGINAL_WHEEL_PATH" |
100 | | -
|
101 | | - # Clean up the temporary directory |
102 | | - rm -rf "$UNPACK_DIR" |
103 | | -
|
104 | | - echo "--- Verification ---" |
105 | | - echo "Final wheel size:" |
106 | | - ls -lh "$ORIGINAL_WHEEL_PATH" |
107 | | - echo "Final wheel contents:" |
108 | | - unzip -l "$ORIGINAL_WHEEL_PATH" | grep '\.so' |
109 | | - shell: bash |
110 | 60 |
|
111 | 61 | - name: Upload wheel artifact |
112 | 62 | uses: actions/upload-artifact@v4 |
113 | 63 | with: |
114 | | - name: wheels-${{ matrix.variant.name }}-cuda${{ matrix.variant.cuda-version }}-py${{ matrix.variant.python-version }} |
| 64 | + name: wheels-${{ matrix.variant.name }}-${{ matrix.variant.os }}-py${{ matrix.variant.python-version }} |
115 | 65 | path: dist/ |
116 | 66 |
|
117 | 67 | publish: |
|
0 commit comments