|
1 |
| -# This workflow will: |
2 |
| -# - Create a new Github release |
3 |
| -# - Build wheels for supported architectures |
4 |
| -# - Deploy the wheels to the Github release |
5 |
| -# - Release the static code to PyPi |
6 |
| -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries |
| 1 | +# This workflow will upload a Python Package to Release asset |
| 2 | +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions |
7 | 3 |
|
8 |
| -name: Build wheels and deploy |
| 4 | +name: Create Release |
9 | 5 |
|
10 | 6 | on:
|
11 |
| - create: |
| 7 | + push: |
12 | 8 | tags:
|
13 | 9 | - v*
|
14 | 10 |
|
15 |
| -jobs: |
| 11 | +# Needed to create release and upload assets |
| 12 | +permissions: |
| 13 | + contents: write |
16 | 14 |
|
17 |
| - setup_release: |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + # Retrieve tag and create release |
18 | 18 | name: Create Release
|
19 | 19 | runs-on: ubuntu-latest
|
| 20 | + outputs: |
| 21 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
20 | 22 | steps:
|
21 |
| - - name: Get the tag version |
22 |
| - id: extract_branch |
23 |
| - run: echo ::set-output name=branch::${GITHUB_REF#refs/tags/} |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + |
| 26 | + - name: Extract branch info |
24 | 27 | shell: bash
|
| 28 | + run: | |
| 29 | + echo "release_tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
25 | 30 |
|
26 | 31 | - name: Create Release
|
27 | 32 | id: create_release
|
28 |
| - uses: actions/create-release@v1 |
| 33 | + uses: "actions/github-script@v6" |
29 | 34 | env:
|
30 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + RELEASE_TAG: ${{ env.release_tag }} |
31 | 36 | with:
|
32 |
| - tag_name: ${{ steps.extract_branch.outputs.branch }} |
33 |
| - release_name: ${{ steps.extract_branch.outputs.branch }} |
| 37 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 38 | + script: | |
| 39 | + const script = require('.github/workflows/scripts/create_release.js') |
| 40 | + await script(github, context, core) |
34 | 41 |
|
35 |
| - build_wheels: |
| 42 | + wheel: |
36 | 43 | name: Build Wheel
|
37 |
| - needs: setup_release |
38 | 44 | runs-on: ${{ matrix.os }}
|
| 45 | + needs: release |
39 | 46 |
|
40 | 47 | strategy:
|
41 | 48 | fail-fast: false
|
42 | 49 | matrix:
|
43 |
| - # Using ubuntu-20.04 instead of 22.04 for more compatibility (glibc). Ideally we'd use the |
44 |
| - # manylinux docker image, but I haven't figured out how to install CUDA on manylinux. |
45 |
| - os: [ubuntu-20.04] |
| 50 | + os: ['ubuntu-20.04'] |
46 | 51 | python-version: ['3.8', '3.9', '3.10', '3.11']
|
47 |
| - torch-version: ['2.3.0'] |
48 |
| - cuda-version: ['11.8.0', '12.1.1'] |
49 |
| - # We need separate wheels that either uses C++11 ABI (-D_GLIBCXX_USE_CXX11_ABI) or not. |
50 |
| - # Pytorch wheels currently don't use it, but nvcr images have Pytorch compiled with C++11 ABI. |
51 |
| - # Without this we get import error (undefined symbol: _ZN3c105ErrorC2ENS_14SourceLocationESs) |
52 |
| - # when building without C++11 ABI and using it on nvcr images. |
53 |
| - cxx11_abi: ['FALSE', 'TRUE'] |
| 52 | + pytorch-version: ['2.3.0'] # Must be the most recent version that meets requirements-cuda.txt. |
| 53 | + cuda-version: ['11.8', '12.1'] |
54 | 54 |
|
55 | 55 | steps:
|
56 | 56 | - name: Checkout
|
57 | 57 | uses: actions/checkout@v3
|
58 | 58 |
|
59 |
| - - name: Set up Python |
60 |
| - uses: actions/setup-python@v4 |
61 |
| - with: |
62 |
| - python-version: ${{ matrix.python-version }} |
| 59 | + - name: Setup ccache |
| 60 | + uses: hendrikmuhs/ccache-action@v1.2 |
63 | 61 |
|
64 |
| - - name: Set CUDA and PyTorch versions |
65 |
| - run: | |
66 |
| - echo "MATRIX_CUDA_VERSION=$(echo ${{ matrix.cuda-version }} | awk -F \. {'print $1 $2'})" >> $GITHUB_ENV |
67 |
| - echo "MATRIX_TORCH_VERSION=$(echo ${{ matrix.torch-version }} | awk -F \. {'print $1 "." $2'})" >> $GITHUB_ENV |
68 |
| - echo "MATRIX_PYTHON_VERSION=$(echo ${{ matrix.python-version }} | awk -F \. {'print $1 $2'})" >> $GITHUB_ENV |
69 |
| -
|
70 |
| - - name: Free up disk space |
| 62 | + - name: Set up Linux Env |
71 | 63 | if: ${{ runner.os == 'Linux' }}
|
72 |
| - # https://github.com/easimon/maximize-build-space/blob/master/action.yml |
73 |
| - # https://github.com/easimon/maximize-build-space/tree/test-report |
74 | 64 | run: |
|
75 |
| - sudo rm -rf /usr/share/dotnet |
76 |
| - sudo rm -rf /opt/ghc |
77 |
| - sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 65 | + bash -x .github/workflows/scripts/env.sh |
78 | 66 |
|
79 |
| - - name: Set up swap space |
80 |
| - if: runner.os == 'Linux' |
81 |
| - uses: pierotofy/set-swap-space@v1.0 |
| 67 | + - name: Set up Python |
| 68 | + uses: actions/setup-python@v4 |
82 | 69 | with:
|
83 |
| - swap-size-gb: 10 |
| 70 | + python-version: ${{ matrix.python-version }} |
84 | 71 |
|
85 | 72 | - name: Install CUDA ${{ matrix.cuda-version }}
|
86 |
| - if: ${{ matrix.cuda-version != 'cpu' }} |
87 |
| - uses: Jimver/cuda-toolkit@v0.2.14 |
88 |
| - id: cuda-toolkit |
89 |
| - with: |
90 |
| - cuda: ${{ matrix.cuda-version }} |
91 |
| - linux-local-args: '["--toolkit"]' |
92 |
| - # default method is "local", and we're hitting some error with caching for CUDA 11.8 and 12.1 |
93 |
| - # method: ${{ (matrix.cuda-version == '11.8.0' || matrix.cuda-version == '12.1.0') && 'network' || 'local' }} |
94 |
| - method: 'network' |
95 |
| - # We need the cuda libraries (e.g. cuSparse, cuSolver) for compiling PyTorch extensions, |
96 |
| - # not just nvcc |
97 |
| - # sub-packages: '["nvcc"]' |
98 |
| - |
99 |
| - - name: Install PyTorch ${{ matrix.torch-version }}+cu${{ matrix.cuda-version }} |
100 |
| - run: | |
101 |
| - pip install --upgrade pip |
102 |
| - # If we don't install before installing Pytorch, we get error for torch 2.0.1 |
103 |
| - # ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none) |
104 |
| - pip install lit |
105 |
| - # We want to figure out the CUDA version to download pytorch |
106 |
| - # e.g. we can have system CUDA version being 11.7 but if torch==1.12 then we need to download the wheel from cu116 |
107 |
| - # see https://github.com/pytorch/pytorch/blob/main/RELEASE.md#release-compatibility-matrix |
108 |
| - # This code is ugly, maybe there's a better way to do this. |
109 |
| - export TORCH_CUDA_VERSION=$(python -c "from os import environ as env; \ |
110 |
| - minv = {'1.12': 113, '1.13': 116, '2.0': 117, '2.1': 118, '2.2': 118, '2.3': 118}[env['MATRIX_TORCH_VERSION']]; \ |
111 |
| - maxv = {'1.12': 116, '1.13': 117, '2.0': 118, '2.1': 121, '2.2': 121, '2.3': 121}[env['MATRIX_TORCH_VERSION']]; \ |
112 |
| - print(max(min(int(env['MATRIX_CUDA_VERSION']), maxv), minv))" \ |
113 |
| - ) |
114 |
| - if [[ ${{ matrix.torch-version }} == *"dev"* ]]; then |
115 |
| - if [[ ${MATRIX_TORCH_VERSION} == "2.2" ]]; then |
116 |
| - # --no-deps because we can't install old versions of pytorch-triton |
117 |
| - pip install typing-extensions jinja2 |
118 |
| - pip install --no-cache-dir --no-deps --pre https://download.pytorch.org/whl/nightly/cu${TORCH_CUDA_VERSION}/torch-${{ matrix.torch-version }}%2Bcu${TORCH_CUDA_VERSION}-cp${MATRIX_PYTHON_VERSION}-cp${MATRIX_PYTHON_VERSION}-linux_x86_64.whl |
119 |
| - else |
120 |
| - pip install --no-cache-dir --pre torch==${{ matrix.torch-version }} --index-url https://download.pytorch.org/whl/nightly/cu${TORCH_CUDA_VERSION} |
121 |
| - fi |
122 |
| - else |
123 |
| - pip install --no-cache-dir torch==${{ matrix.torch-version }} --index-url https://download.pytorch.org/whl/cu${TORCH_CUDA_VERSION} |
124 |
| - fi |
125 |
| - nvcc --version |
126 |
| - python --version |
127 |
| - python -c "import torch; print('PyTorch:', torch.__version__)" |
128 |
| - python -c "import torch; print('CUDA:', torch.version.cuda)" |
129 |
| - python -c "from torch.utils import cpp_extension; print (cpp_extension.CUDA_HOME)" |
130 |
| - shell: |
131 |
| - bash |
132 |
| - |
133 |
| - - name: Build wheel |
134 | 73 | run: |
|
135 |
| - # We want setuptools >= 49.6.0 otherwise we can't compile the extension if system CUDA version is 11.7 and pytorch cuda version is 11.6 |
136 |
| - # https://github.com/pytorch/pytorch/blob/664058fa83f1d8eede5d66418abff6e20bd76ca8/torch/utils/cpp_extension.py#L810 |
137 |
| - # However this still fails so I'm using a newer version of setuptools |
138 |
| - pip install setuptools==68.0.0 |
139 |
| - pip install ninja packaging wheel |
140 |
| - export PATH=/usr/local/nvidia/bin:/usr/local/nvidia/lib64:$PATH |
141 |
| - export LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH |
142 |
| - # Limit MAX_JOBS otherwise the github runner goes OOM |
143 |
| - MAX_JOBS=2 FLASH_ATTENTION_FORCE_BUILD="TRUE" FLASH_ATTENTION_FORCE_CXX11_ABI=${{ matrix.cxx11_abi}} python setup.py bdist_wheel --dist-dir=dist |
144 |
| - tmpname=cu${MATRIX_CUDA_VERSION}torch${MATRIX_TORCH_VERSION}cxx11abi${{ matrix.cxx11_abi }} |
145 |
| - wheel_name=$(ls dist/*whl | xargs -n 1 basename | sed "s/-/+$tmpname-/2") |
146 |
| - ls dist/*whl |xargs -I {} mv {} dist/${wheel_name} |
147 |
| - echo "wheel_name=${wheel_name}" >> $GITHUB_ENV |
| 74 | + bash -x .github/workflows/scripts/cuda-install.sh ${{ matrix.cuda-version }} ${{ matrix.os }} |
148 | 75 |
|
149 |
| - - name: Log Built Wheels |
| 76 | + - name: Install PyTorch ${{ matrix.pytorch-version }} with CUDA ${{ matrix.cuda-version }} |
150 | 77 | run: |
|
151 |
| - ls dist |
| 78 | + bash -x .github/workflows/scripts/pytorch-install.sh ${{ matrix.python-version }} ${{ matrix.pytorch-version }} ${{ matrix.cuda-version }} |
152 | 79 |
|
153 |
| - - name: Get the tag version |
154 |
| - id: extract_branch |
155 |
| - run: echo ::set-output name=branch::${GITHUB_REF#refs/tags/} |
156 |
| - |
157 |
| - - name: Get Release with tag |
158 |
| - id: get_current_release |
159 |
| - uses: joutvhu/get-release@v1 |
160 |
| - with: |
161 |
| - tag_name: ${{ steps.extract_branch.outputs.branch }} |
| 80 | + - name: Build wheel |
| 81 | + shell: bash |
162 | 82 | env:
|
163 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + CMAKE_BUILD_TYPE: Release # do not compile with debug symbol to reduce wheel size |
| 84 | + run: | |
| 85 | + bash -x .github/workflows/scripts/build.sh ${{ matrix.python-version }} ${{ matrix.cuda-version }} |
| 86 | + wheel_name=$(ls dist/*whl | xargs -n 1 basename) |
| 87 | + asset_name=${wheel_name//"linux"/"manylinux1"} |
| 88 | + echo "wheel_name=${wheel_name}" >> $GITHUB_ENV |
| 89 | + echo "asset_name=${asset_name}" >> $GITHUB_ENV |
164 | 90 |
|
165 | 91 | - name: Upload Release Asset
|
166 |
| - id: upload_release_asset |
167 | 92 | uses: actions/upload-release-asset@v1
|
168 | 93 | env:
|
169 | 94 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
170 | 95 | with:
|
171 |
| - upload_url: ${{ steps.get_current_release.outputs.upload_url }} |
172 |
| - asset_path: ./dist/${{env.wheel_name}} |
173 |
| - asset_name: ${{env.wheel_name}} |
| 96 | + upload_url: ${{ needs.release.outputs.upload_url }} |
| 97 | + asset_path: ./dist/${{ env.wheel_name }} |
| 98 | + asset_name: ${{ env.asset_name }} |
174 | 99 | asset_content_type: application/*
|
175 |
| - |
176 |
| - publish_package: |
177 |
| - name: Publish package |
178 |
| - needs: [build_wheels] |
179 |
| - |
180 |
| - runs-on: ubuntu-latest |
181 |
| - |
182 |
| - steps: |
183 |
| - - uses: actions/checkout@v3 |
184 |
| - |
185 |
| - - uses: actions/setup-python@v4 |
186 |
| - with: |
187 |
| - python-version: '3.10' |
188 |
| - |
189 |
| - - name: Install dependencies |
190 |
| - run: | |
191 |
| - pip install ninja packaging setuptools wheel twine |
192 |
| - # We don't want to download anything CUDA-related here |
193 |
| - pip install torch --index-url https://download.pytorch.org/whl/cpu |
194 |
| -
|
195 |
| - - name: Build core package |
196 |
| - env: |
197 |
| - FLASH_ATTENTION_SKIP_CUDA_BUILD: "TRUE" |
198 |
| - run: | |
199 |
| - python setup.py sdist --dist-dir=dist |
200 |
| -
|
201 |
| - - name: Deploy |
202 |
| - env: |
203 |
| - TWINE_USERNAME: "__token__" |
204 |
| - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
205 |
| - run: | |
206 |
| - python -m twine upload dist/* |
0 commit comments