|  | 
|  | 1 | +name: Build Wheels (CUDA) | 
|  | 2 | + | 
|  | 3 | +on: workflow_dispatch | 
|  | 4 | + | 
|  | 5 | +permissions: | 
|  | 6 | +  contents: write | 
|  | 7 | + | 
|  | 8 | +jobs: | 
|  | 9 | +  define_matrix: | 
|  | 10 | +    name: Define Build Matrix | 
|  | 11 | +    runs-on: ubuntu-latest | 
|  | 12 | +    outputs: | 
|  | 13 | +      matrix: ${{ steps.set-matrix.outputs.matrix }} | 
|  | 14 | +    defaults: | 
|  | 15 | +      run: | 
|  | 16 | +        shell: pwsh | 
|  | 17 | + | 
|  | 18 | +    steps: | 
|  | 19 | +      - name: Define Job Output | 
|  | 20 | +        id: set-matrix | 
|  | 21 | +        run: | | 
|  | 22 | +          $matrix = @{ | 
|  | 23 | +              'os' = @('ubuntu-20.04', 'windows-latest') | 
|  | 24 | +              'pyver' = @("3.10", "3.11", "3.12") | 
|  | 25 | +              'cuda' = @("12.1.1", "12.2.2", "12.3.2") | 
|  | 26 | +              'releasetag' = @("basic") | 
|  | 27 | +          } | 
|  | 28 | +
 | 
|  | 29 | +          $matrixOut = ConvertTo-Json $matrix -Compress | 
|  | 30 | +          Write-Output ('matrix=' + $matrixOut) >> $env:GITHUB_OUTPUT | 
|  | 31 | +
 | 
|  | 32 | +  build_wheels: | 
|  | 33 | +    name: Build Wheel ${{ matrix.os }} ${{ matrix.pyver }} ${{ matrix.cuda }} ${{ matrix.releasetag == 'wheels' && 'AVX2' || matrix.releasetag }} | 
|  | 34 | +    needs: define_matrix | 
|  | 35 | +    runs-on: ${{ matrix.os }} | 
|  | 36 | +    strategy: | 
|  | 37 | +      matrix: ${{ fromJSON(needs.define_matrix.outputs.matrix) }} | 
|  | 38 | +    defaults: | 
|  | 39 | +      run: | 
|  | 40 | +        shell: pwsh | 
|  | 41 | +    env: | 
|  | 42 | +      CUDAVER: ${{ matrix.cuda }} | 
|  | 43 | +      AVXVER: ${{ matrix.releasetag }} | 
|  | 44 | + | 
|  | 45 | +    steps: | 
|  | 46 | +      - uses: actions/checkout@v4 | 
|  | 47 | +        with: | 
|  | 48 | +          submodules: "recursive" | 
|  | 49 | + | 
|  | 50 | +      - uses: actions/setup-python@v4 | 
|  | 51 | +        with: | 
|  | 52 | +          python-version: ${{ matrix.pyver }} | 
|  | 53 | + | 
|  | 54 | +      - name: Setup Mamba | 
|  | 55 | +        uses: conda-incubator/[email protected] | 
|  | 56 | +        with: | 
|  | 57 | +          activate-environment: "build" | 
|  | 58 | +          python-version: ${{ matrix.pyver }} | 
|  | 59 | +          miniforge-variant: Mambaforge | 
|  | 60 | +          miniforge-version: latest | 
|  | 61 | +          use-mamba: true | 
|  | 62 | +          add-pip-as-python-dependency: true | 
|  | 63 | +          auto-activate-base: false | 
|  | 64 | + | 
|  | 65 | +      - name: VS Integration Cache | 
|  | 66 | +        id: vs-integration-cache | 
|  | 67 | +        if: runner.os == 'Windows' | 
|  | 68 | + | 
|  | 69 | +        with: | 
|  | 70 | +          path: ./MSBuildExtensions | 
|  | 71 | +          key: cuda-${{ matrix.cuda }}-vs-integration | 
|  | 72 | + | 
|  | 73 | +      - name: Get Visual Studio Integration | 
|  | 74 | +        if: runner.os == 'Windows' && steps.vs-integration-cache.outputs.cache-hit != 'true' | 
|  | 75 | +        run: | | 
|  | 76 | +          if ($env:CUDAVER -eq '12.1.1') {$x = '12.1.0'} else {$x = $env:CUDAVER} | 
|  | 77 | +          $links = (Invoke-RestMethod 'https://github.com/Jimver/cuda-toolkit/raw/dc0ca7bb29c5a92f7a963d3d5c93f8d59765136a/src/links/windows-links.ts').Trim().split().where({$_ -ne ''}) | 
|  | 78 | +          for ($i=$q=0;$i -lt $links.count -and $q -lt 2;$i++) {if ($links[$i] -eq "'$x',") {$q++}} | 
|  | 79 | +          Invoke-RestMethod $links[$i].Trim("'") -OutFile 'cudainstaller.zip' | 
|  | 80 | +          & 'C:\Program Files\7-Zip\7z.exe' e cudainstaller.zip -oMSBuildExtensions -r *\MSBuildExtensions\* > $null | 
|  | 81 | +          Remove-Item 'cudainstaller.zip' | 
|  | 82 | +
 | 
|  | 83 | +      - name: Install Visual Studio Integration | 
|  | 84 | +        if: runner.os == 'Windows' | 
|  | 85 | +        run: | | 
|  | 86 | +          $y = (gi '.\MSBuildExtensions').fullname + '\*' | 
|  | 87 | +          (gi 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\*\BuildCustomizations').fullname.foreach({cp $y $_}) | 
|  | 88 | +          $cupath = 'CUDA_PATH_V' + $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','_') | 
|  | 89 | +          echo "$cupath=$env:CONDA_PREFIX" >> $env:GITHUB_ENV | 
|  | 90 | +
 | 
|  | 91 | +      - name: Install Dependencies | 
|  | 92 | +        env: | 
|  | 93 | +          MAMBA_DOWNLOAD_FAILFAST: "0" | 
|  | 94 | +          MAMBA_NO_LOW_SPEED_LIMIT: "1" | 
|  | 95 | +        run: | | 
|  | 96 | +          $cudaVersion = $env:CUDAVER | 
|  | 97 | +          mamba install -y 'cuda' -c nvidia/label/cuda-$cudaVersion | 
|  | 98 | +          python -m pip install build wheel | 
|  | 99 | +
 | 
|  | 100 | +      - name: Build Wheel | 
|  | 101 | +        run: | | 
|  | 102 | +          $cudaVersion = $env:CUDAVER.Remove($env:CUDAVER.LastIndexOf('.')).Replace('.','') | 
|  | 103 | +          $env:CUDA_PATH = $env:CONDA_PREFIX | 
|  | 104 | +          $env:CUDA_HOME = $env:CONDA_PREFIX | 
|  | 105 | +          $env:CUDA_TOOLKIT_ROOT_DIR = $env:CONDA_PREFIX | 
|  | 106 | +          if ($IsLinux) { | 
|  | 107 | +            $env:LD_LIBRARY_PATH = $env:CONDA_PREFIX + '/lib:' + $env:LD_LIBRARY_PATH | 
|  | 108 | +          } | 
|  | 109 | +          $env:VERBOSE = '1' | 
|  | 110 | +          $env:CMAKE_ARGS = '-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=all' | 
|  | 111 | +          $env:CMAKE_ARGS = "-DLLAMA_CUDA_FORCE_MMQ=ON $env:CMAKE_ARGS" | 
|  | 112 | +          if ($env:AVXVER -eq 'AVX') { | 
|  | 113 | +            $env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off' | 
|  | 114 | +          } | 
|  | 115 | +          if ($env:AVXVER -eq 'AVX512') { | 
|  | 116 | +            $env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX512=on' | 
|  | 117 | +          } | 
|  | 118 | +          if ($env:AVXVER -eq 'basic') { | 
|  | 119 | +            $env:CMAKE_ARGS = $env:CMAKE_ARGS + ' -DLLAMA_AVX=off -DLLAMA_AVX2=off -DLLAMA_FMA=off -DLLAMA_F16C=off' | 
|  | 120 | +          } | 
|  | 121 | +          python -m build --wheel | 
|  | 122 | +          # write the build tag to the output | 
|  | 123 | +          Write-Output "CUDA_VERSION=$cudaVersion" >> $env:GITHUB_ENV | 
|  | 124 | +
 | 
|  | 125 | +      - uses: softprops/action-gh-release@v1 | 
|  | 126 | +        with: | 
|  | 127 | +          files: dist/* | 
|  | 128 | +          # Set tag_name to <tag>-cu<cuda_version> | 
|  | 129 | +          tag_name: ${{ github.ref_name }}-cu${{ env.CUDA_VERSION }} | 
|  | 130 | +        env: | 
|  | 131 | +          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
0 commit comments