Skip to content

Commit 589a203

Browse files
committed
Update GitHub workflows
1 parent 5b31610 commit 589a203

File tree

1 file changed

+32
-82
lines changed

1 file changed

+32
-82
lines changed

.github/workflows/pypi.yaml

Lines changed: 32 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
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-
61
name: Build and Publish Python 🐍 distributions
72

83
on:
@@ -12,106 +7,61 @@ on:
127

138
jobs:
149
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 }}
2112
strategy:
2213
fail-fast: false
2314
matrix:
2415
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" }
3139

3240
steps:
3341
- name: Checkout repository
3442
uses: actions/checkout@v4
3543

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 }}
4148

4249
- name: Install Rust
4350
uses: dtolnay/rust-toolchain@stable
4451

45-
- name: Install Python build dependencies
52+
- name: Install dependencies
4653
run: pip install maturin>=1.8.6 numpy>=1.26.4
4754

48-
- name: Generate pyproject.toml
55+
- name: Generate pyproject.toml for ${{ matrix.variant.name }}
4956
run: python generate_configs.py ${{ matrix.variant.name }}
5057

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-
6458
- name: Build wheel
65-
env:
66-
LD_LIBRARY_PATH: ${{ env.CUDA_LIB_DIR }}:${LD_LIBRARY_PATH}
67-
CUDA_COMPUTE_CAP: ${{ matrix.variant.compute-caps }}
6859
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
11060

11161
- name: Upload wheel artifact
11262
uses: actions/upload-artifact@v4
11363
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 }}
11565
path: dist/
11666

11767
publish:

0 commit comments

Comments
 (0)