Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows actions #1036

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
112 changes: 112 additions & 0 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Build flash-attention Wheels for Windows

on:
workflow_dispatch:
inputs:
version:
description: 'Version tag of flash-attention to build: (format: v2.3.4/v2.3.4.post1)'
default: 'v2.3.4'
required: true
type: string
workflow_call:
inputs:
version:
description: 'Version tag of flash-attention to build (format: v2.3.4/v2.3.4.post1)'
default: 'v2.3.4'
required: true
type: string

permissions:
contents: write

jobs:
build_wheels:
name: Build wheels for Python ${{ matrix.pyver }}, CUDA ${{ matrix.cuda }}, and Torch ${{ matrix.torchver }}
runs-on: windows-2022
strategy:
matrix:
pyver: ["3.8", "3.9", "3.10", "3.11", "3.12"]
cuda: ["12.2.2"]
torchver: ["2.2.2", "2.3.1"]
defaults:
run:
shell: pwsh
env:
CUDAVER: ${{ matrix.cuda }}
PCKGVER: ${{ inputs.version }}

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver }}

- name: Install VS2022 BuildTools 17.9.7
run: choco install -y visualstudio2022buildtools --version=117.9.7.0 --params "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --installChannelUri https://aka.ms/vs/17/release/180911598_-255012421/channel"
if: runner.os == 'Windows'

- name: Setup Mamba
uses: conda-incubator/[email protected]
with:
activate-environment: "build"
python-version: ${{ matrix.pyver }}
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
add-pip-as-python-dependency: true
auto-activate-base: false

- name: Install Dependencies
run: |
$cudaVersion = '${{ matrix.cuda }}'
$cudaVersionPytorch = '${{ matrix.cuda }}'.Remove('${{ matrix.cuda }}'.LastIndexOf('.')).Replace('.','')

mamba install -y -c nvidia/label/cuda-$cudaVersion cuda-toolkit cuda-runtime
if (!(mamba list cuda)[-1].contains('cuda')) {sleep -s 10; mamba install -y 'cuda' $cudaVersion}
if (!(mamba list cuda)[-1].contains('cuda')) {throw 'CUDA Toolkit failed to install!'}

python -m pip install --upgrade build setuptools wheel packaging ninja torch==${{ matrix.torchver }} psutil --extra-index-url "https://download.pytorch.org/whl/cu121"

- name: Build Wheel
id: build-wheel
run: |
# --- Spawn the VS shell
if ($IsWindows) {
Import-Module 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
Enter-VsDevShell -VsInstallPath 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools' -DevCmdArguments '-arch=x64 -host_arch=x64'
$env:DISTUTILS_USE_SDK=1
}

$cudaVersion = $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','')
$packageVersion = $env:PCKGVER.TrimStart('v')

$env:CUDA_PATH = $env:CONDA_PREFIX
$env:CUDA_HOME = $env:CONDA_PREFIX

$env:MAX_JOBS = '1'
$env:FLASH_ATTENTION_FORCE_BUILD = 'TRUE'
$env:FLASH_ATTENTION_FORCE_SINGLE_THREAD = 'TRUE'

python -m build -n --wheel

$wheel = (gi '.\dist\*.whl')[0]
$wheelname = $wheel.name.replace("flash_attn-$packageVersion-","flash_attn-$packageVersion+cu$cudaVersion"+"torch${{ matrix.torchver }}cxx11abiFALSE-")
Move-Item $wheel.fullname ".\dist\$wheelname"

- uses: actions/upload-artifact@v3
with:
name: 'windows-wheels'
path: ./dist/*.whl

- name: Upload files to a GitHub release
uses: svenstaro/[email protected]
continue-on-error: true
with:
file: ./dist/*.whl
tag: ${{ inputs.version }}
file_glob: true
overwrite: true
release_name: ${{ inputs.version }}