Add custom vendored kernels - #3154
Draft
MarioSieg wants to merge 2 commits into
Draft
Conversation
Comment on lines
+51
to
+140
| name: Build wheel (${{ matrix.arch }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - runner: image-builder | ||
| arch: x86_64 | ||
| - runner: image-builder-arm-2204 | ||
| arch: aarch64 | ||
| runs-on: ${{ matrix.runner }} | ||
| container: nvidia/cuda:12.8.1-devel-ubuntu24.04 | ||
| steps: | ||
| - name: Install build tooling | ||
| run: | | ||
| apt-get update | ||
| apt-get install -y --no-install-recommends git curl ca-certificates build-essential | ||
|
|
||
| # Kernel sources live in this repo, so the checkout is all the build needs. | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| submodules: false | ||
| ref: ${{ inputs.ref }} | ||
|
|
||
| - name: Install uv | ||
| run: | | ||
| curl -LsSf https://astral.sh/uv/install.sh | env INSTALLER_NO_MODIFY_PATH=1 UV_INSTALL_DIR=/usr/local/bin sh | ||
| uv --version | ||
|
|
||
| # The wheel only imports under the exact torch it was compiled against, so build | ||
| # against the torch prime-rl resolves rather than whatever is newest today. | ||
| - name: Create build environment | ||
| env: | ||
| UV_TORCH_BACKEND: ${{ env.CUDA_TAG }} | ||
| run: | | ||
| TORCH_PIN=$(grep -A1 '^name = "torch"$' uv.lock | sed -n 's/^version = "\([^"+]*\).*"$/\1/p' | head -n1) | ||
| if [ -z "$TORCH_PIN" ]; then | ||
| echo "Could not read torch's version from uv.lock" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Building against torch==$TORCH_PIN" | ||
| uv venv --python 3.12 /tmp/build-env | ||
| VIRTUAL_ENV=/tmp/build-env uv pip install "torch==$TORCH_PIN" setuptools wheel ninja | ||
|
|
||
| # torch C++ extensions are bound to the torch and CUDA they were compiled against, so | ||
| # the wheel carries both in its local version. | ||
| - name: Stamp ABI into the version | ||
| run: | | ||
| TORCH_VERSION=$(/tmp/build-env/bin/python -c 'import torch; print(torch.__version__.split("+")[0])') | ||
| LOCAL="${CUDA_TAG}torch${TORCH_VERSION}" | ||
| sed -i -E "s/^version = \"([^\"]+)\"$/version = \"\1+${LOCAL}\"/" kernels/pyproject.toml | ||
| grep '^version' kernels/pyproject.toml | ||
|
|
||
| - name: Build wheel | ||
| env: | ||
| VIRTUAL_ENV: /tmp/build-env | ||
| CUDA_HOME: /usr/local/cuda | ||
| PRIME_KERNELS_REQUIRE: "1" | ||
| MAX_JOBS: "8" | ||
| run: uv build --wheel --no-build-isolation --out-dir dist kernels | ||
|
|
||
| - name: Inspect wheel | ||
| run: | | ||
| ls -lh dist/ | ||
| /tmp/build-env/bin/python - <<'PY' | ||
| import pathlib, zipfile | ||
| wheel = next(pathlib.Path("dist").glob("*.whl")) | ||
| extensions = [n for n in zipfile.ZipFile(wheel).namelist() if n.endswith(".so")] | ||
| assert extensions, f"{wheel.name} contains no compiled kernels" | ||
| print(wheel.name, *extensions, sep="\n ") | ||
| PY | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: prime-kernels-${{ matrix.arch }} | ||
| path: dist/*.whl | ||
| if-no-files-found: error | ||
|
|
||
| - name: Attach to release | ||
| if: inputs.release_tag != '' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ inputs.release_tag }} | ||
| run: | | ||
| gh release upload "$TAG" dist/*.whl --clobber | ||
| # The `[tool.uv.sources]` pin has to name the wheel exactly, ABI suffix and all. | ||
| WHEEL=$(basename dist/*.whl) | ||
| URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}/${WHEEL}" | ||
| echo "\`{ url = \"$URL\", marker = \"platform_machine == '${{ matrix.arch }}'\" },\`" >> "$GITHUB_STEP_SUMMARY" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for locall vendored kernels