Skip to content

Commit 67032ff

Browse files
committed
Merge branch 'origin' into update_to_v2.0.8
2 parents e6b9d0d + 2286d7c commit 67032ff

File tree

22 files changed

+845
-529
lines changed

22 files changed

+845
-529
lines changed

.github/workflows/cuda/cu102-Linux-env.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/cuda/cu102-Linux.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/cuda/cu113-Linux-env.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/cuda/cu113-Linux.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/cuda/cu116-Linux-env.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/cuda/cu116-Linux.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/env.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 143 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
# This workflow will upload a Python Package to Release asset
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
26
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
37

4-
5-
name: Python Package
8+
name: Build wheels and deploy
69

710
on:
811
create:
912
tags:
10-
- '**'
13+
- v*
1114

1215
jobs:
13-
release:
16+
17+
setup_release:
1418
name: Create Release
1519
runs-on: ubuntu-latest
1620
steps:
@@ -27,69 +31,134 @@ jobs:
2731
with:
2832
tag_name: ${{ steps.extract_branch.outputs.branch }}
2933
release_name: ${{ steps.extract_branch.outputs.branch }}
30-
31-
wheel:
34+
35+
build_wheels:
3236
name: Build Wheel
37+
needs: setup_release
3338
runs-on: ${{ matrix.os }}
34-
needs: release
35-
39+
3640
strategy:
3741
fail-fast: false
3842
matrix:
39-
# os: [ubuntu-20.04]
40-
os: [ubuntu-18.04]
41-
python-version: ['3.7', '3.8', '3.9', '3.10']
42-
torch-version: [1.11.0, 1.12.0, 1.12.1]
43-
cuda-version: ['113', '116']
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]
46+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
47+
torch-version: ['1.12.1', '1.13.1', '2.0.1', '2.1.0.dev20230731']
48+
cuda-version: ['11.6.2', '11.7.1', '11.8.0', '12.1.0']
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']
4454
exclude:
45-
- torch-version: 1.11.0
46-
cuda-version: '116'
55+
# Pytorch <= 1.12 does not support Python 3.11
56+
- torch-version: '1.12.1'
57+
python-version: '3.11'
58+
# Pytorch >= 2.0 only supports Python >= 3.8
59+
- torch-version: '2.0.1'
60+
python-version: '3.7'
61+
- torch-version: '2.1.0.dev20230731'
62+
python-version: '3.7'
63+
# Pytorch <= 2.0 only supports CUDA <= 11.8
64+
- torch-version: '1.12.1'
65+
cuda-version: '12.1.0'
66+
- torch-version: '1.13.1'
67+
cuda-version: '12.1.0'
68+
- torch-version: '2.0.1'
69+
cuda-version: '12.1.0'
70+
# Pytorch >= 2.1 only supports CUDA 12.1
71+
- torch-version: '2.1.0.dev20230731'
72+
cuda-version: '11.6.2'
73+
- torch-version: '2.1.0.dev20230731'
74+
cuda-version: '11.7.1'
75+
- torch-version: '2.1.0.dev20230731'
76+
cuda-version: '11.8.0'
4777

4878
steps:
4979
- name: Checkout
5080
uses: actions/checkout@v3
51-
81+
5282
- name: Set up Python
53-
uses: actions/setup-python@v3
83+
uses: actions/setup-python@v4
5484
with:
5585
python-version: ${{ matrix.python-version }}
5686

57-
- name: Set up Linux Env
87+
- name: Set CUDA and PyTorch versions
88+
run: |
89+
echo "MATRIX_CUDA_VERSION=$(echo ${{ matrix.cuda-version }} | awk -F \. {'print $1 $2'})" >> $GITHUB_ENV
90+
echo "MATRIX_TORCH_VERSION=$(echo ${{ matrix.torch-version }} | awk -F \. {'print $1 "." $2'})" >> $GITHUB_ENV
91+
92+
- name: Free up disk space
5893
if: ${{ runner.os == 'Linux' }}
94+
# https://github.com/easimon/maximize-build-space/blob/master/action.yml
95+
# https://github.com/easimon/maximize-build-space/tree/test-report
5996
run: |
6097
sudo rm -rf /usr/share/dotnet
61-
bash .github/workflows/env.sh
62-
echo ${{ needs.create_release.outputs.upload_url }}
63-
echo ${{ needs.steps.extract_branch.outputs.upload_url }}
64-
shell:
65-
bash
98+
sudo rm -rf /opt/ghc
99+
sudo rm -rf /opt/hostedtoolcache/CodeQL
66100
67101
- name: Install CUDA ${{ matrix.cuda-version }}
68102
if: ${{ matrix.cuda-version != 'cpu' }}
69-
run: |
70-
bash .github/workflows/cuda/cu${{ matrix.cuda-version }}-${{ runner.os }}.sh
71-
shell:
72-
bash
73-
74-
- name: Check GPU Env
75-
if: ${{ matrix.cuda-version != 'cpu' }}
76-
run: |
77-
source .github/workflows/cuda/cu${{ matrix.cuda-version }}-${{ runner.os }}-env.sh
78-
nvcc --version
79-
shell:
80-
bash
103+
uses: Jimver/[email protected]
104+
id: cuda-toolkit
105+
with:
106+
cuda: ${{ matrix.cuda-version }}
107+
linux-local-args: '["--toolkit"]'
108+
# default method is "local", and we're hitting some error with caching for CUDA 11.8 and 12.1
109+
# method: ${{ (matrix.cuda-version == '11.8.0' || matrix.cuda-version == '12.1.0') && 'network' || 'local' }}
110+
method: 'network'
111+
# We need the cuda libraries (e.g. cuSparse, cuSolver) for compiling PyTorch extensions,
112+
# not just nvcc
113+
# sub-packages: '["nvcc"]'
81114

82115
- name: Install PyTorch ${{ matrix.torch-version }}+cu${{ matrix.cuda-version }}
83116
run: |
84-
pip install numpy pyyaml scipy ipython mkl mkl-include ninja cython typing pandas typing-extensions dataclasses && conda clean -ya
85-
pip install --no-index --no-cache-dir torch==${{ matrix.torch-version }} -f https://download.pytorch.org/whl/cu${{ matrix.cuda-version }}/torch_stable.html
117+
pip install --upgrade pip
118+
# If we don't install before installing Pytorch, we get error for torch 2.0.1
119+
# ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
120+
pip install lit
121+
# We want to figure out the CUDA version to download pytorch
122+
# 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
123+
# This code is ugly, maybe there's a better way to do this.
124+
export TORCH_CUDA_VERSION=$(python -c "import os; minv = {'1.12': 113, '1.13': 116, '2.0': 117, '2.1': 121}[os.environ['MATRIX_TORCH_VERSION']]; maxv = {'1.12': 116, '1.13': 117, '2.0': 118, '2.1': 121}[os.environ['MATRIX_TORCH_VERSION']]; print(max(min(int(os.environ['MATRIX_CUDA_VERSION']), maxv), minv))")
125+
if [[ ${{ matrix.torch-version }} == *"dev"* ]]; then
126+
pip install --no-cache-dir --pre torch==${{ matrix.torch-version }} --index-url https://download.pytorch.org/whl/nightly/cu${TORCH_CUDA_VERSION}
127+
else
128+
pip install --no-cache-dir torch==${{ matrix.torch-version }} --index-url https://download.pytorch.org/whl/cu${TORCH_CUDA_VERSION}
129+
fi
130+
nvcc --version
86131
python --version
87132
python -c "import torch; print('PyTorch:', torch.__version__)"
88133
python -c "import torch; print('CUDA:', torch.version.cuda)"
89134
python -c "from torch.utils import cpp_extension; print (cpp_extension.CUDA_HOME)"
90135
shell:
91136
bash
92-
137+
138+
- name: Build wheel
139+
run: |
140+
# 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
141+
# https://github.com/pytorch/pytorch/blob/664058fa83f1d8eede5d66418abff6e20bd76ca8/torch/utils/cpp_extension.py#L810
142+
# However this still fails so I'm using a newer version of setuptools
143+
pip install setuptools==68.0.0
144+
pip install ninja packaging wheel
145+
export PATH=/usr/local/nvidia/bin:/usr/local/nvidia/lib64:$PATH
146+
export LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
147+
# Currently for this setting the runner goes OOM if we pass --threads 4 to nvcc
148+
if [[ ${MATRIX_CUDA_VERSION} == "121" && ${MATRIX_TORCH_VERSION} == "2.1" ]]; then
149+
export FLASH_ATTENTION_FORCE_SINGLE_THREAD="TRUE"
150+
fi
151+
# Limit MAX_JOBS otherwise the github runner goes OOM
152+
MAX_JOBS=1 FLASH_ATTENTION_FORCE_BUILD="TRUE" FLASH_ATTENTION_FORCE_CXX11_ABI=${{ matrix.cxx11_abi}} python setup.py bdist_wheel --dist-dir=dist
153+
tmpname=cu${MATRIX_CUDA_VERSION}torch${MATRIX_TORCH_VERSION}cxx11abi${{ matrix.cxx11_abi }}
154+
wheel_name=$(ls dist/*whl | xargs -n 1 basename | sed "s/-/+$tmpname-/2")
155+
ls dist/*whl |xargs -I {} mv {} dist/${wheel_name}
156+
echo "wheel_name=${wheel_name}" >> $GITHUB_ENV
157+
158+
- name: Log Built Wheels
159+
run: |
160+
ls dist
161+
93162
- name: Get the tag version
94163
id: extract_branch
95164
run: echo ::set-output name=branch::${GITHUB_REF#refs/tags/}
@@ -102,26 +171,45 @@ jobs:
102171
env:
103172
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104173

105-
- name: Build wheel
106-
run: |
107-
export FORCE_CUDA="1"
108-
export PATH=/usr/local/nvidia/bin:/usr/local/nvidia/lib64:$PATH
109-
export LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
110-
export CUDA_INSTALL_DIR=/usr/local/cuda-11.3$CUDA_INSTALL_DIR
111-
pip install wheel
112-
python setup.py bdist_wheel --dist-dir=dist
113-
tmpname=cu${{ matrix.cuda-version }}torch${{ matrix.torch-version }}
114-
wheel_name=$(ls dist/*whl | xargs -n 1 basename | sed "s/-/+$tmpname-/2")
115-
ls dist/*whl |xargs -I {} mv {} ${wheel_name}
116-
echo "wheel_name=${wheel_name}" >> $GITHUB_ENV
117-
118174
- name: Upload Release Asset
119-
id: upload_release_asset
175+
id: upload_release_asset
120176
uses: actions/upload-release-asset@v1
121177
env:
122178
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123179
with:
124180
upload_url: ${{ steps.get_current_release.outputs.upload_url }}
125-
asset_path: ./${{env.wheel_name}}
181+
asset_path: ./dist/${{env.wheel_name}}
126182
asset_name: ${{env.wheel_name}}
127-
asset_content_type: application/*
183+
asset_content_type: application/*
184+
185+
publish_package:
186+
name: Publish package
187+
needs: [build_wheels]
188+
189+
runs-on: ubuntu-latest
190+
191+
steps:
192+
- uses: actions/checkout@v3
193+
194+
- uses: actions/setup-python@v4
195+
with:
196+
python-version: '3.10'
197+
198+
- name: Install dependencies
199+
run: |
200+
pip install ninja packaging setuptools wheel twine
201+
# We don't want to download anything CUDA-related here
202+
pip install torch --index-url https://download.pytorch.org/whl/cpu
203+
204+
- name: Build core package
205+
env:
206+
FLASH_ATTENTION_SKIP_CUDA_BUILD: "TRUE"
207+
run: |
208+
python setup.py sdist --dist-dir=dist
209+
210+
- name: Deploy
211+
env:
212+
TWINE_USERNAME: "__token__"
213+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
214+
run: |
215+
python -m twine upload dist/*

0 commit comments

Comments
 (0)