diff --git a/.devops/rocm.Dockerfile b/.devops/rocm.Dockerfile index a8bc4e1fcd64..20f6ad636080 100644 --- a/.devops/rocm.Dockerfile +++ b/.devops/rocm.Dockerfile @@ -57,7 +57,6 @@ COPY --from=web /app/tools/ui/dist tools/ui/dist RUN HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \ cmake -S . -B build \ -DGGML_HIP=ON \ - -DGGML_HIP_ROCWMMA_FATTN=ON \ -DAMDGPU_TARGETS="$ROCM_DOCKER_ARCH" \ -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON \ -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=OFF \ diff --git a/.github/actions/windows-setup-rocm/action.yml b/.github/actions/windows-setup-rocm/action.yml index fd9f8e5a4168..dffbb7f396cf 100644 --- a/.github/actions/windows-setup-rocm/action.yml +++ b/.github/actions/windows-setup-rocm/action.yml @@ -1,15 +1,27 @@ name: "Windows - Setup ROCm" -description: "Setup ROCm for Windows" +description: "Install ROCm for Windows from the TheRock wheels (same layout as the upstream windows-rocm release job)" inputs: version: - description: "ROCm version" + description: "ROCm version, e.g. 10.0.0" required: true runs: using: "composite" steps: - - name: Setup ROCm - uses: ./.github/actions/install-exe - with: - url: https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-${{ inputs.version }}-Win11-For-HIP.exe - args: -install + - name: Install ROCm wheels + shell: pwsh + run: | + $ErrorActionPreference = "Stop" + # The venv lives at a fixed path so the devel tree it expands can be + # cached and does not need relocation. + New-Item -Path "C:\TheRock\build" -ItemType Directory -Force | Out-Null + python -m venv C:\TheRock\build\.venv + & C:\TheRock\build\.venv\Scripts\Activate.ps1 + + python -m pip install --upgrade pip + # Multi-arch wheels: one install covers every gfx target we build for. + python -m pip install --index-url https://stable.repo.amd.com/rocm/whl-next/ "rocm[libraries,devel]==${{ inputs.version }}" + + rocm-sdk init + if ($LASTEXITCODE -ne 0) { throw "rocm-sdk init failed with exit code $LASTEXITCODE" } + Write-Host "ROCm ${{ inputs.version }} installed under C:\TheRock\build" diff --git a/.github/workflows/dev-build.yml b/.github/workflows/dev-build.yml index 004203d39960..28cb4247ecb6 100644 --- a/.github/workflows/dev-build.yml +++ b/.github/workflows/dev-build.yml @@ -526,9 +526,8 @@ jobs: -DGGML_CPU_ALL_VARIANTS=ON \ -DGGML_HIP=ON \ -DHIP_PLATFORM=amd \ - -DGPU_TARGETS="gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201;gfx90a;gfx942" \ + -DGPU_TARGETS="gfx1030;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201;gfx90a;gfx942;gfx950" \ -DCMAKE_HIP_FLAGS="--offload-compress" \ - -DGGML_HIP_ROCWMMA_FATTN=ON \ -DLLAMA_CURL=OFF \ -DLLAMA_OPENSSL=OFF \ -DLLAMA_BUILD_SERVER=ON \ @@ -727,6 +726,191 @@ jobs: path: llama-turboquant-windows-x64-${{ matrix.variant }}.zip retention-days: 14 + # HIP backend only, built with the clang that ships inside the ROCm wheels. + # The archive itself is assembled in publish-dev-latest: the windows-x64-cpu + # archive plus ggml-hip.dll and the ROCm runtime. llama-server.exe from the + # CPU archive dlopens ggml-hip.dll thanks to GGML_BACKEND_DL, the same way + # the upstream windows-rocm release works. Separate job rather than a matrix + # row: different toolchain, and the matrix row names are required checks. + windows-x64-rocm: + runs-on: windows-2022 + env: + # ROCm wheels (TheRock). Keep in sync with the upstream `windows-rocm` job. + ROCM_VERSION: "10.0.0" + # Consumer parts only: RDNA2, RDNA3, RDNA3.5 (Ryzen AI 300 / Strix Halo), + # RDNA4. CDNA has no Windows driver, RDNA1 has no usable HIP support. + GPU_TARGETS: "gfx1030;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" + + steps: + - name: Clone + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: ccache + uses: ggml-org/ccache-action@v1.2.21 + with: + key: turboquant-windows-x64-rocm + # 9 gfx targets x every fattn/mmq template instance: a CUDA-sized build. + max-size: 2G + evict-old-files: 7d + + - name: Install Ninja + run: choco install ninja -y + + - name: Setup ROCm + uses: ./.github/actions/windows-setup-rocm + with: + version: ${{ env.ROCM_VERSION }} + + - name: Setup ROCm environment + shell: pwsh + run: | + $ErrorActionPreference = "Stop" + & C:\TheRock\build\.venv\Scripts\Activate.ps1 + rocm-sdk init + if ($LASTEXITCODE -ne 0) { throw "rocm-sdk init failed with exit code $LASTEXITCODE" } + $rocmPath = (rocm-sdk path --root) + if (-not $rocmPath) { throw "rocm-sdk path --root returned empty - devel package may not be installed" } + $rocmPath = $rocmPath.Trim() + $cmakePath = (rocm-sdk path --cmake).Trim() + $binPath = (rocm-sdk path --bin).Trim() + Write-Host "ROCm root: $rocmPath" + Write-Host "CMake path: $cmakePath" + Write-Host "Bin path: $binPath" + echo "HIP_PATH=$rocmPath" >> $env:GITHUB_ENV + echo "CMAKE_PREFIX_PATH=$cmakePath" >> $env:GITHUB_ENV + echo "HIP_DEVICE_LIB_PATH=$rocmPath\lib\llvm\amdgcn\bitcode" >> $env:GITHUB_ENV + echo "HIP_PLATFORM=amd" >> $env:GITHUB_ENV + echo "LLVM_PATH=$rocmPath\lib\llvm" >> $env:GITHUB_ENV + echo "ROCM_BIN_PATH=$binPath" >> $env:GITHUB_ENV + echo "$binPath" >> $env:GITHUB_PATH + echo "C:\TheRock\build\.venv\Scripts" >> $env:GITHUB_PATH + + # Best-effort, same reason as the CUDA variants: Defender scans every + # object clang writes. + - name: Exclude build tree from Defender + shell: pwsh + run: | + try { + Add-MpPreference -ExclusionPath "${{ github.workspace }}", "$env:RUNNER_TEMP", "C:\TheRock" + Add-MpPreference -ExclusionProcess "clang.exe", "clang++.exe", "lld.exe", "lld-link.exe", "ninja.exe" + } catch { + Write-Host "Defender exclusions unavailable: $_" + } + + - name: Build + shell: pwsh + # On Windows ggml-hip compiles the .cu files as CXX with hip::device + # (CXX_IS_HIPCC in ggml/src/ggml-hip/CMakeLists.txt), so CMAKE_HIP_FLAGS + # is never used and --offload-compress must go through CMAKE_CXX_FLAGS. + # Without it ggml-hip.dll is 545 MB for these 9 targets (upstream ships + # ~900 MB for 20). -Wno-ignored-attributes drops 850k GGML_API dllimport + # warnings per build that otherwise make the job log unfetchable. + run: | + cmake -S . -B build -G "Ninja Multi-Config" ` + -DCMAKE_PREFIX_PATH="${env:HIP_PATH}" ` + -DCMAKE_C_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` + -DCMAKE_CXX_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang++.exe" ` + -DCMAKE_HIP_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` + -DCMAKE_C_FLAGS="-Wno-error=incompatible-pointer-types -Wno-ignored-attributes" ` + -DCMAKE_CXX_FLAGS="--offload-compress -Wno-ignored-attributes" ` + -DHIP_PATH="${env:HIP_PATH}" ` + -DHIP_PLATFORM=amd ` + -DGGML_HIP=ON ` + -DGPU_TARGETS="${env:GPU_TARGETS}" ` + -DGGML_BACKEND_DL=ON ` + -DGGML_NATIVE=OFF ` + -DGGML_CPU=OFF ` + -DGGML_RPC=OFF ` + -DLLAMA_CURL=OFF ` + -DLLAMA_OPENSSL=OFF ` + -DLLAMA_BUILD_SERVER=OFF ` + -DLLAMA_BUILD_TOOLS=OFF ` + -DLLAMA_BUILD_TESTS=OFF ` + -DLLAMA_BUILD_EXAMPLES=OFF + if ($LASTEXITCODE -ne 0) { throw "cmake configure failed" } + cmake --build build --config Release --parallel ${env:NUMBER_OF_PROCESSORS} --target ggml-hip + if ($LASTEXITCODE -ne 0) { throw "cmake build failed" } + + - name: Verify HIP backend was built + shell: pwsh + run: | + $dll = Get-ChildItem -Path build\bin\Release -Filter "ggml-hip*.dll" -ErrorAction SilentlyContinue + if (-not $dll) { + Write-Host "##[error]ggml-hip*.dll was NOT produced. The HIP backend silently failed to build." + Get-ChildItem build\bin\Release | Format-Table -AutoSize + exit 1 + } + $dll | Format-Table FullName, Length -AutoSize + + # Only our own DLL gets our signature; the AMD DLLs stay as AMD ships them. + - name: Stage ggml-hip.dll for signing + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path hip-out | Out-Null + Copy-Item build\bin\Release\ggml-hip.dll hip-out\ + + - name: Sign ggml-hip.dll + uses: ./.github/actions/windows-code-sign + with: + path: hip-out + sm-api-key: ${{ secrets.SM_API_KEY }} + sm-client-cert-b64: ${{ secrets.SM_CLIENT_CERT_FILE_B64 }} + sm-client-cert-password: ${{ secrets.SM_CLIENT_CERT_PASSWORD }} + + - name: Bundle ROCm runtime + shell: pwsh + # The bundle is the import closure of ggml-hip.dll over the ROCm wheel + # bin dirs: amdhip64_7 (+ rocm_kpack, amd_comgr), hipblas, rocblas + # (+ libhipblaslt), rocsolver, ... System DLLs are left alone. + # The ROCm 10 wheels ship no rocBLAS kernel library: kernels come from + # amd_comgr.dll at run time, so there is no gfx-specific data to copy. + # amdhip64_7.dll must sit next to the binaries: the Adrenalin driver + # ships its own copy in System32 and the loader searches the exe + # directory first (ggml-org/llama.cpp#26929). rocblas/hipblas are not + # installed by the driver; upstream stopped bundling them and its + # Windows ROCm zip no longer loads without a ROCm SDK (#26996). + run: | + $ErrorActionPreference = "Stop" + $sp = "C:\TheRock\build\.venv\Lib\site-packages" + $bins = @("$sp\_rocm_sdk_devel\bin", "$sp\_rocm_sdk_core\bin", "$sp\_rocm_sdk_libraries\bin") + $dumpbin = Get-ChildItem "C:\Program Files\Microsoft Visual Studio" -Recurse -Filter dumpbin.exe -ErrorAction SilentlyContinue | + Where-Object { $_.FullName -like "*Hostx64\x64*" } | Select-Object -First 1 + if (-not $dumpbin) { throw "dumpbin.exe not found" } + function Get-Imports($path) { + & $dumpbin.FullName /NOLOGO /DEPENDENTS $path 2>$null | + Where-Object { $_ -match "^\s+(\S+\.dll)\s*$" } | ForEach-Object { $Matches[1] } + } + $queue = [System.Collections.Generic.Queue[string]]::new() + $queue.Enqueue("hip-out\ggml-hip.dll") + $seen = @{ "ggml-hip.dll" = $true } + while ($queue.Count -gt 0) { + $p = $queue.Dequeue() + foreach ($d in Get-Imports $p) { + if ($seen.ContainsKey($d.ToLower())) { continue } + $seen[$d.ToLower()] = $true + $src = $null + foreach ($b in $bins) { if (Test-Path "$b\$d") { $src = "$b\$d"; break } } + if (-not $src) { continue } + Copy-Item $src -Destination hip-out -Force + Write-Host (" {0,-22} {1,8:N1} MiB needed by {2}" -f $d, ((Get-Item $src).Length / 1MB), (Split-Path $p -Leaf)) + $queue.Enqueue("hip-out\$d") + } + } + foreach ($must in @("amdhip64_7.dll", "rocblas.dll", "hipblas.dll")) { + if (-not (Test-Path "hip-out\$must")) { throw "$must missing from the bundle" } + } + $total = (Get-ChildItem -Path hip-out -File | Measure-Object -Property Length -Sum).Sum + Write-Host (" HIP backend payload total: {0:N1} MiB" -f ($total / 1MB)) + + - name: Upload HIP backend + uses: actions/upload-artifact@v4 + with: + name: hip-windows-x64-rocm + path: hip-out + retention-days: 14 + macos-arm64: runs-on: macos-latest @@ -843,7 +1027,7 @@ jobs: # broken backend never blocks the others from shipping to testers — the # release notes call out what is missing. publish-dev-latest: - needs: [linux-x64-cpu, linux-x64-vulkan, linux-x64-cuda-12-4, linux-x64-cuda-13-3, linux-arm64-cuda-13-3, linux-x64-rocm, windows-x64, macos-arm64] + needs: [linux-x64-cpu, linux-x64-vulkan, linux-x64-cuda-12-4, linux-x64-cuda-13-3, linux-arm64-cuda-13-3, linux-x64-rocm, windows-x64, windows-x64-rocm, macos-arm64] if: ${{ always() && github.event_name == 'push' && github.ref == 'refs/heads/dev' }} runs-on: ubuntu-22.04 permissions: @@ -862,6 +1046,45 @@ jobs: path: archives merge-multiple: true + # The Windows ROCm archive is the CPU archive plus the HIP payload from + # windows-x64-rocm. Either input may be missing when a build job failed; + # then the archive is simply absent and the notes call it out. + - name: Download Windows HIP backend + uses: actions/download-artifact@v4 + continue-on-error: true + with: + name: hip-windows-x64-rocm + path: hip-windows + + - name: Assemble Windows ROCm archive + run: | + CPU_ZIP=archives/llama-turboquant-windows-x64-cpu.zip + if [ ! -f "$CPU_ZIP" ] || [ ! -f hip-windows/ggml-hip.dll ]; then + echo "windows-x64-rocm: inputs missing, skipping" + exit 0 + fi + rm -rf rocm-win && mkdir rocm-win + unzip -q "$CPU_ZIP" -d rocm-win + cp -r hip-windows/. rocm-win/build/bin/ + cat > rocm-win/build/bin/README-ROCm.txt << 'EOF' + AMD ROCm (HIP) build for Windows x64. + + Self-contained: ggml-hip.dll plus the matching HIP runtime + (amdhip64_7.dll, rocm_kpack.dll, amd_comgr.dll) and the BLAS stack it + links (hipblas, rocblas, libhipblaslt, rocsolver, origami). No ROCm + SDK install is needed, only a current AMD Adrenalin driver. + + Targets: gfx1030 (RX 6000), gfx1100/1101/1102/1103 (RX 7000, Radeon + 780M/760M), gfx1150/gfx1151 (Ryzen AI 300 / Ryzen AI Max, Strix Halo), + gfx1200/gfx1201 (RX 9000). Other GPUs: use the Vulkan build. + + llama-server picks the HIP device automatically; check with + `llama-server --list-devices`. To force the CPU backend instead, + delete ggml-hip.dll. + EOF + (cd rocm-win && zip -qr ../archives/llama-turboquant-windows-x64-rocm.zip build) + ls -lh archives/llama-turboquant-windows-x64-rocm.zip + - name: Recreate dev-latest release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -870,7 +1093,7 @@ jobs: DATE=$(date -u +%Y-%m-%d) ls -lh archives/ - EXPECTED="linux-x64-cpu linux-x64-vulkan linux-x64-cuda-12.4 linux-x64-cuda-13.3 linux-arm64-cuda-13.3 linux-x64-rocm windows-x64-cpu windows-x64-vulkan windows-x64-cuda-12.4 windows-x64-cuda-13.3 macos-arm64" + EXPECTED="linux-x64-cpu linux-x64-vulkan linux-x64-cuda-12.4 linux-x64-cuda-13.3 linux-arm64-cuda-13.3 linux-x64-rocm windows-x64-cpu windows-x64-vulkan windows-x64-cuda-12.4 windows-x64-cuda-13.3 windows-x64-rocm macos-arm64" MISSING="" for b in $EXPECTED; do ls archives/ | grep -q "llama-turboquant-${b}\." || MISSING="$MISSING $b" diff --git a/.github/workflows/release-turboquant.yml b/.github/workflows/release-turboquant.yml index 0f32476ada93..941a2a06977a 100644 --- a/.github/workflows/release-turboquant.yml +++ b/.github/workflows/release-turboquant.yml @@ -520,9 +520,10 @@ jobs: sudo apt-get install -y build-essential cmake libssl-dev rocm-hip-sdk - name: Build - # RDNA only, by scope decision: gfx1030 (RDNA2), gfx1100/1101/1102 - # (RDNA3), gfx1151 (RDNA 3.5 / Strix Halo), gfx1200/1201 (RDNA4). - # GCN/CDNA are intentionally excluded -- those users use Vulkan. + # RDNA2-RDNA4: gfx1030, gfx1100/1101/1102/1103, gfx1150/1151 (Ryzen AI + # 300 / Strix Halo), gfx1200/1201. CDNA: gfx90a, gfx942, gfx950 + # (MI200/MI300/MI350). Both families ship in one archive thanks to + # --offload-compress (see dev-build.yml for the measured sizes). # Runner has no AMD GPU: build only. libggml-hip.so is dlopen'd # thanks to GGML_BACKEND_DL. run: | @@ -538,9 +539,8 @@ jobs: -DGGML_CPU_ALL_VARIANTS=ON \ -DGGML_HIP=ON \ -DHIP_PLATFORM=amd \ - -DGPU_TARGETS="gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201;gfx90a;gfx942" \ + -DGPU_TARGETS="gfx1030;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201;gfx90a;gfx942;gfx950" \ -DCMAKE_HIP_FLAGS="--offload-compress" \ - -DGGML_HIP_ROCWMMA_FATTN=ON \ -DLLAMA_CURL=OFF \ -DLLAMA_OPENSSL=OFF \ -DLLAMA_BUILD_SERVER=ON \ @@ -735,6 +735,192 @@ jobs: path: llama-turboquant-windows-x64-${{ matrix.variant }}.zip retention-days: 30 + # HIP backend only, built with the clang that ships inside the ROCm wheels. + # The archive itself is assembled in publish-release: the windows-x64-cpu + # archive plus ggml-hip.dll and the ROCm runtime. llama-server.exe from the + # CPU archive dlopens ggml-hip.dll thanks to GGML_BACKEND_DL, the same way + # the upstream windows-rocm release works. Separate job rather than a matrix + # row: different toolchain, and the matrix row names are required checks. + windows-x64-rocm: + needs: verify-version + runs-on: windows-2022 + env: + # ROCm wheels (TheRock). Keep in sync with the upstream `windows-rocm` job. + ROCM_VERSION: "10.0.0" + # Consumer parts only: RDNA2, RDNA3, RDNA3.5 (Ryzen AI 300 / Strix Halo), + # RDNA4. CDNA has no Windows driver, RDNA1 has no usable HIP support. + GPU_TARGETS: "gfx1030;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1200;gfx1201" + + steps: + - name: Clone + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: ccache + uses: ggml-org/ccache-action@v1.2.21 + with: + key: turboquant-windows-x64-rocm + # 9 gfx targets x every fattn/mmq template instance: a CUDA-sized build. + max-size: 2G + evict-old-files: 7d + + - name: Install Ninja + run: choco install ninja -y + + - name: Setup ROCm + uses: ./.github/actions/windows-setup-rocm + with: + version: ${{ env.ROCM_VERSION }} + + - name: Setup ROCm environment + shell: pwsh + run: | + $ErrorActionPreference = "Stop" + & C:\TheRock\build\.venv\Scripts\Activate.ps1 + rocm-sdk init + if ($LASTEXITCODE -ne 0) { throw "rocm-sdk init failed with exit code $LASTEXITCODE" } + $rocmPath = (rocm-sdk path --root) + if (-not $rocmPath) { throw "rocm-sdk path --root returned empty - devel package may not be installed" } + $rocmPath = $rocmPath.Trim() + $cmakePath = (rocm-sdk path --cmake).Trim() + $binPath = (rocm-sdk path --bin).Trim() + Write-Host "ROCm root: $rocmPath" + Write-Host "CMake path: $cmakePath" + Write-Host "Bin path: $binPath" + echo "HIP_PATH=$rocmPath" >> $env:GITHUB_ENV + echo "CMAKE_PREFIX_PATH=$cmakePath" >> $env:GITHUB_ENV + echo "HIP_DEVICE_LIB_PATH=$rocmPath\lib\llvm\amdgcn\bitcode" >> $env:GITHUB_ENV + echo "HIP_PLATFORM=amd" >> $env:GITHUB_ENV + echo "LLVM_PATH=$rocmPath\lib\llvm" >> $env:GITHUB_ENV + echo "ROCM_BIN_PATH=$binPath" >> $env:GITHUB_ENV + echo "$binPath" >> $env:GITHUB_PATH + echo "C:\TheRock\build\.venv\Scripts" >> $env:GITHUB_PATH + + # Best-effort, same reason as the CUDA variants: Defender scans every + # object clang writes. + - name: Exclude build tree from Defender + shell: pwsh + run: | + try { + Add-MpPreference -ExclusionPath "${{ github.workspace }}", "$env:RUNNER_TEMP", "C:\TheRock" + Add-MpPreference -ExclusionProcess "clang.exe", "clang++.exe", "lld.exe", "lld-link.exe", "ninja.exe" + } catch { + Write-Host "Defender exclusions unavailable: $_" + } + + - name: Build + shell: pwsh + # On Windows ggml-hip compiles the .cu files as CXX with hip::device + # (CXX_IS_HIPCC in ggml/src/ggml-hip/CMakeLists.txt), so CMAKE_HIP_FLAGS + # is never used and --offload-compress must go through CMAKE_CXX_FLAGS. + # Without it ggml-hip.dll is 545 MB for these 9 targets (upstream ships + # ~900 MB for 20). -Wno-ignored-attributes drops 850k GGML_API dllimport + # warnings per build that otherwise make the job log unfetchable. + run: | + cmake -S . -B build -G "Ninja Multi-Config" ` + -DCMAKE_PREFIX_PATH="${env:HIP_PATH}" ` + -DCMAKE_C_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` + -DCMAKE_CXX_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang++.exe" ` + -DCMAKE_HIP_COMPILER="${env:HIP_PATH}\lib\llvm\bin\clang.exe" ` + -DCMAKE_C_FLAGS="-Wno-error=incompatible-pointer-types -Wno-ignored-attributes" ` + -DCMAKE_CXX_FLAGS="--offload-compress -Wno-ignored-attributes" ` + -DHIP_PATH="${env:HIP_PATH}" ` + -DHIP_PLATFORM=amd ` + -DGGML_HIP=ON ` + -DGPU_TARGETS="${env:GPU_TARGETS}" ` + -DGGML_BACKEND_DL=ON ` + -DGGML_NATIVE=OFF ` + -DGGML_CPU=OFF ` + -DGGML_RPC=OFF ` + -DLLAMA_CURL=OFF ` + -DLLAMA_OPENSSL=OFF ` + -DLLAMA_BUILD_SERVER=OFF ` + -DLLAMA_BUILD_TOOLS=OFF ` + -DLLAMA_BUILD_TESTS=OFF ` + -DLLAMA_BUILD_EXAMPLES=OFF + if ($LASTEXITCODE -ne 0) { throw "cmake configure failed" } + cmake --build build --config Release --parallel ${env:NUMBER_OF_PROCESSORS} --target ggml-hip + if ($LASTEXITCODE -ne 0) { throw "cmake build failed" } + + - name: Verify HIP backend was built + shell: pwsh + run: | + $dll = Get-ChildItem -Path build\bin\Release -Filter "ggml-hip*.dll" -ErrorAction SilentlyContinue + if (-not $dll) { + Write-Host "##[error]ggml-hip*.dll was NOT produced. The HIP backend silently failed to build." + Get-ChildItem build\bin\Release | Format-Table -AutoSize + exit 1 + } + $dll | Format-Table FullName, Length -AutoSize + + # Only our own DLL gets our signature; the AMD DLLs stay as AMD ships them. + - name: Stage ggml-hip.dll for signing + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path hip-out | Out-Null + Copy-Item build\bin\Release\ggml-hip.dll hip-out\ + + - name: Sign ggml-hip.dll + uses: ./.github/actions/windows-code-sign + with: + path: hip-out + sm-api-key: ${{ secrets.SM_API_KEY }} + sm-client-cert-b64: ${{ secrets.SM_CLIENT_CERT_FILE_B64 }} + sm-client-cert-password: ${{ secrets.SM_CLIENT_CERT_PASSWORD }} + + - name: Bundle ROCm runtime + shell: pwsh + # The bundle is the import closure of ggml-hip.dll over the ROCm wheel + # bin dirs: amdhip64_7 (+ rocm_kpack, amd_comgr), hipblas, rocblas + # (+ libhipblaslt), rocsolver, ... System DLLs are left alone. + # The ROCm 10 wheels ship no rocBLAS kernel library: kernels come from + # amd_comgr.dll at run time, so there is no gfx-specific data to copy. + # amdhip64_7.dll must sit next to the binaries: the Adrenalin driver + # ships its own copy in System32 and the loader searches the exe + # directory first (ggml-org/llama.cpp#26929). rocblas/hipblas are not + # installed by the driver; upstream stopped bundling them and its + # Windows ROCm zip no longer loads without a ROCm SDK (#26996). + run: | + $ErrorActionPreference = "Stop" + $sp = "C:\TheRock\build\.venv\Lib\site-packages" + $bins = @("$sp\_rocm_sdk_devel\bin", "$sp\_rocm_sdk_core\bin", "$sp\_rocm_sdk_libraries\bin") + $dumpbin = Get-ChildItem "C:\Program Files\Microsoft Visual Studio" -Recurse -Filter dumpbin.exe -ErrorAction SilentlyContinue | + Where-Object { $_.FullName -like "*Hostx64\x64*" } | Select-Object -First 1 + if (-not $dumpbin) { throw "dumpbin.exe not found" } + function Get-Imports($path) { + & $dumpbin.FullName /NOLOGO /DEPENDENTS $path 2>$null | + Where-Object { $_ -match "^\s+(\S+\.dll)\s*$" } | ForEach-Object { $Matches[1] } + } + $queue = [System.Collections.Generic.Queue[string]]::new() + $queue.Enqueue("hip-out\ggml-hip.dll") + $seen = @{ "ggml-hip.dll" = $true } + while ($queue.Count -gt 0) { + $p = $queue.Dequeue() + foreach ($d in Get-Imports $p) { + if ($seen.ContainsKey($d.ToLower())) { continue } + $seen[$d.ToLower()] = $true + $src = $null + foreach ($b in $bins) { if (Test-Path "$b\$d") { $src = "$b\$d"; break } } + if (-not $src) { continue } + Copy-Item $src -Destination hip-out -Force + Write-Host (" {0,-22} {1,8:N1} MiB needed by {2}" -f $d, ((Get-Item $src).Length / 1MB), (Split-Path $p -Leaf)) + $queue.Enqueue("hip-out\$d") + } + } + foreach ($must in @("amdhip64_7.dll", "rocblas.dll", "hipblas.dll")) { + if (-not (Test-Path "hip-out\$must")) { throw "$must missing from the bundle" } + } + $total = (Get-ChildItem -Path hip-out -File | Measure-Object -Property Length -Sum).Sum + Write-Host (" HIP backend payload total: {0:N1} MiB" -f ($total / 1MB)) + + - name: Upload HIP backend + uses: actions/upload-artifact@v4 + with: + name: hip-windows-x64-rocm + path: hip-out + retention-days: 30 + macos-arm64: needs: verify-version runs-on: macos-latest @@ -865,7 +1051,7 @@ jobs: # A stable release must be COMPLETE: this job has hard `needs` on every # build job — if anything failed, no release is published at all. publish-release: - needs: [verify-version, linux-x64-cpu, linux-x64-vulkan, linux-x64-cuda-12-4, linux-x64-cuda-13-3, linux-arm64-cuda-13-3, linux-x64-rocm, windows-x64, macos-arm64] + needs: [verify-version, linux-x64-cpu, linux-x64-vulkan, linux-x64-cuda-12-4, linux-x64-cuda-13-3, linux-arm64-cuda-13-3, linux-x64-rocm, windows-x64, windows-x64-rocm, macos-arm64] # Publish even if some backend build failed, so one broken backend never # blocks shipping the others (the notes call out what is missing). Still # requires the version check to pass. @@ -887,6 +1073,45 @@ jobs: path: archives merge-multiple: true + # The Windows ROCm archive is the CPU archive plus the HIP payload from + # windows-x64-rocm. Either input may be missing when a build job failed; + # then the archive is simply absent and the notes call it out. + - name: Download Windows HIP backend + uses: actions/download-artifact@v4 + continue-on-error: true + with: + name: hip-windows-x64-rocm + path: hip-windows + + - name: Assemble Windows ROCm archive + run: | + CPU_ZIP=archives/llama-turboquant-windows-x64-cpu.zip + if [ ! -f "$CPU_ZIP" ] || [ ! -f hip-windows/ggml-hip.dll ]; then + echo "windows-x64-rocm: inputs missing, skipping" + exit 0 + fi + rm -rf rocm-win && mkdir rocm-win + unzip -q "$CPU_ZIP" -d rocm-win + cp -r hip-windows/. rocm-win/build/bin/ + cat > rocm-win/build/bin/README-ROCm.txt << 'EOF' + AMD ROCm (HIP) build for Windows x64. + + Self-contained: ggml-hip.dll plus the matching HIP runtime + (amdhip64_7.dll, rocm_kpack.dll, amd_comgr.dll) and the BLAS stack it + links (hipblas, rocblas, libhipblaslt, rocsolver, origami). No ROCm + SDK install is needed, only a current AMD Adrenalin driver. + + Targets: gfx1030 (RX 6000), gfx1100/1101/1102/1103 (RX 7000, Radeon + 780M/760M), gfx1150/gfx1151 (Ryzen AI 300 / Ryzen AI Max, Strix Halo), + gfx1200/gfx1201 (RX 9000). Other GPUs: use the Vulkan build. + + llama-server picks the HIP device automatically; check with + `llama-server --list-devices`. To force the CPU backend instead, + delete ggml-hip.dll. + EOF + (cd rocm-win && zip -qr ../archives/llama-turboquant-windows-x64-rocm.zip build) + ls -lh archives/llama-turboquant-windows-x64-rocm.zip + - name: Create release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -902,7 +1127,7 @@ jobs: # A build job may have failed (if: always() above). Publish whatever # archives exist and call out anything missing in the notes. - EXPECTED="linux-x64-cpu linux-x64-vulkan linux-x64-cuda-12.4 linux-x64-cuda-13.3 linux-arm64-cuda-13.3 linux-x64-rocm windows-x64-cpu windows-x64-vulkan windows-x64-cuda-12.4 windows-x64-cuda-13.3 macos-arm64" + EXPECTED="linux-x64-cpu linux-x64-vulkan linux-x64-cuda-12.4 linux-x64-cuda-13.3 linux-arm64-cuda-13.3 linux-x64-rocm windows-x64-cpu windows-x64-vulkan windows-x64-cuda-12.4 windows-x64-cuda-13.3 windows-x64-rocm macos-arm64" MISSING="" for b in $EXPECTED; do ls archives/ | grep -q "llama-turboquant-${b}\." || MISSING="$MISSING $b" @@ -941,9 +1166,10 @@ jobs: | Windows x64 Vulkan | \`llama-turboquant-windows-x64-vulkan.zip\` | | Windows x64 CUDA 12.4 | \`llama-turboquant-windows-x64-cuda-12.4.zip\` | | Windows x64 CUDA 13.3 | \`llama-turboquant-windows-x64-cuda-13.3.zip\` | + | Windows x64 AMD ROCm, RDNA2-RDNA4 + Ryzen AI (HIP runtime and rocBLAS bundled) | \`llama-turboquant-windows-x64-rocm.zip\` | | macOS ARM64 (Metal, signed + notarized) | \`llama-turboquant-macos-arm64.zip\` | - The AMD ROCm archive targets RDNA2 through RDNA4 (gfx1030/1100/1101/1102/1151/1200/1201) and CDNA (gfx90a, gfx942 -- Instinct MI200/MI300) in a single archive, and needs the ROCm runtime installed on the system. Older GCN cards: use the Vulkan build. + The Linux AMD ROCm archive targets RDNA2 through RDNA4 (gfx1030/1100/1101/1102/1103/1150/1151/1200/1201) and CDNA (gfx90a, gfx942, gfx950 -- Instinct MI200/MI300/MI350) in a single archive, and needs the ROCm runtime installed on the system. The Windows AMD ROCm archive covers the same RDNA targets, bundles the HIP runtime and rocBLAS, and only needs a current Adrenalin driver. Older GCN cards: use the Vulkan build. The Linux arm64 CUDA archive is built for NVIDIA DGX Spark (GB10, sm_121); other arm64 NVIDIA machines (GH200, GB200, Thor) run it too but JIT the kernels from PTX on first launch. diff --git a/CHANGELOG.md b/CHANGELOG.md index 91490068e25e..1a875af63681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,31 @@ commit list underneath. Releases before `b10269-1.5.0` predate this file; see the git history. +## b10269-1.5.1 + +### Fixed + +- **Ling-3.0-flash (BailingMoeV3) no longer emits garbage token bursts.** The + model is trained with clamped SwiGLU activations in its late layers, and the + per-layer limits live in `config.json` under `expert_swiglu_limit_list` and + `share_expert_swiglu_limit_list`. The public HF modeling code ignores those + keys and so did this port, which caused deterministic transient logit + collapse - output like `count += 1eville` dropped into otherwise fine + generations. Measured at roughly -20 pass@1 on HumanEval (72.6% -> 93%+ with + the fix); the garbage-token repro is eliminated. + +### Notes + +- **Re-convert your Ling-3.0-flash GGUF to get the fix.** The clamp limits are + written by the converter into two new KVs (`{arch}.swiglu_clamp_exp` and + `{arch}.swiglu_clamp_shexp`); a GGUF produced before this release does not + carry them, and the runtime then defaults to no clamping. Re-download the + quant or re-run `conversion/bailingmoe.py`. +- Both KVs are optional and default to zero, so existing GGUFs and every other + architecture are unaffected. The graph needed no change - the SwiGLU clamp + branches in `build_ffn` / `build_moe_ffn` already trigger on a nonzero + per-layer limit, matching the vLLM `SwigluStepAndMul` semantics. + ## b10269-1.5.0 ### Added diff --git a/README.md b/README.md index d46840a281e9..444d0fec8f3e 100644 --- a/README.md +++ b/README.md @@ -348,7 +348,7 @@ because of the lighter memory traffic. | Metal (Apple Silicon) | yes; `TurboFlash` flash-attn decode kernel for `turbo3` (off-by-default on Apple10 — see PR #91) | yes (V2.1 fused kernels) | | CUDA (NVIDIA) | `turbo3` / `turbo4` (full); `turbo2` via reference path | `TQ4_1S` MUL_MAT_VEC | | Vulkan | `turbo3` KV (FA + coopmat), `SET_ROWS` for `turbo2/4` | `TQ4_1S` (specialised MUL_MAT_VEC, SET_ROWS, CPY) | -| HIP / ROCm | `turbo3` KV; F16-K + TURBO-V mixed dispatch | reference | +| HIP / ROCm | `turbo2` / `turbo3` / `turbo4` KV (same fattn-vec instances as CUDA, incl. mixed K/V types); validated on RDNA3/RDNA4 and MI300X/MI355X, see [docs/amd](docs/amd/README.md) | `TQ3_1S` / `TQ4_1S` via the scalar MUL_MAT_VEC path | | CPU | reference (correctness, not throughput) | reference | ### Pre-built binaries @@ -361,8 +361,10 @@ Each push to `feature/turboquant-kv-cache` publishes self-contained |---|---|---| | macOS arm64 | `llama-turboquant-macos-arm64.{zip,tar.gz}` | Metal (`TurboFlash`) + CPU | | Linux x64 | `llama-turboquant-linux-x64-vulkan.{zip,tar.gz}` | Vulkan + portable CPU | +| Linux x64 | `llama-turboquant-linux-x64-rocm.{zip,tar.gz}` | AMD ROCm/HIP (RDNA2-RDNA4, Strix Halo, CDNA MI200/MI300/MI350; needs the ROCm runtime installed) + portable CPU | | Windows x64 | `llama-turboquant-windows-x64-cpu.zip` | portable CPU | | Windows x64 | `llama-turboquant-windows-x64-vulkan.zip` | Vulkan + portable CPU | +| Windows x64 | `llama-turboquant-windows-x64-rocm.zip` | AMD ROCm/HIP (RDNA2-RDNA4, Ryzen AI 300 / Strix Halo; HIP runtime + rocBLAS bundled) + portable CPU | | Windows x64 | `llama-turboquant-windows-x64-cuda-12.4.zip` | CUDA 12.4 (`cudart` bundled) + portable CPU | | Windows x64 | `llama-turboquant-windows-x64-cuda-13.3.zip` | CUDA 13.3 (`cudart` bundled) + portable CPU | diff --git a/TURBOQUANT.md b/TURBOQUANT.md index b1074c1d969f..af98f9a4e0ef 100644 --- a/TURBOQUANT.md +++ b/TURBOQUANT.md @@ -31,7 +31,7 @@ the notes list what is missing. |---|---| | Linux x64 | `cpu`, `vulkan`, `cuda-12.4`, `cuda-13.3`, `rocm` | | Linux arm64 | `cuda-13.3` — NVIDIA DGX Spark / GB10, sm_121 | -| Windows x64 | `cpu`, `vulkan`, `cuda-12.4`, `cuda-13.3` | +| Windows x64 | `cpu`, `vulkan`, `cuda-12.4`, `cuda-13.3`, `rocm` | | macOS arm64 | `macos-arm64` (Metal) | The CUDA archives bundle their own `libcudart`/`libcublas` and are linked with diff --git a/docs/amd/README.md b/docs/amd/README.md new file mode 100644 index 000000000000..c733559b292c --- /dev/null +++ b/docs/amd/README.md @@ -0,0 +1,173 @@ +# AMD ROCm / HIP: status, benchmark plan, roadmap + +What this fork ships for AMD GPUs today, what we measure to compare ROCm (HIP) +against Vulkan with the TurboQuant KV cache, and what is still open. Written +for the team and for the AMD partner conversation; numbers go into +`docs/amd/results/` and a dated `benchmarks-.md` next to this file. + +## 1. What ships + +| Archive | Targets | Runtime | +|---|---|---| +| `llama-turboquant-linux-x64-rocm.tar.gz` | RDNA2-RDNA4: gfx1030, gfx1100/1101/1102/1103, gfx1150/1151 (Ryzen AI 300 / Strix Halo), gfx1200/1201; CDNA: gfx90a, gfx942, gfx950 (MI200/MI300/MI350) | needs the ROCm runtime installed (rocBLAS/hipBLASLt for every gfx do not fit a release asset) | +| `llama-turboquant-windows-x64-rocm.zip` | the RDNA targets above | self-contained: HIP runtime + the BLAS DLLs ggml-hip links bundled, only an Adrenalin driver is needed | +| `llama-turboquant-*-vulkan.*` | any Vulkan 1.2+ GPU | driver only | + +Both ROCm archives are built with `--offload-compress` and `GGML_BACKEND_DL=ON` +(`libggml-hip.so` / `ggml-hip.dll` is dlopen'd). The Windows one follows the +upstream `windows-rocm` release job (ROCm 10.0 wheels, clang from the wheels, +`amdhip64_7.dll` next to the binaries because the loader prefers the exe +directory over the driver copy in System32, ggml-org/llama.cpp#26929) with two +differences learned the hard way: + +- On Windows the `.cu` files are compiled as CXX through `hip::device` + (`CXX_IS_HIPCC`), so `CMAKE_HIP_FLAGS` is ignored and `--offload-compress` + has to go through `CMAKE_CXX_FLAGS`. That takes `ggml-hip.dll` from 545 MB to + 47 MiB for 9 targets (upstream ships about 900 MB for 20). +- The bundle is the import closure of `ggml-hip.dll` over the ROCm wheels: + amdhip64_7, rocm_kpack, amd_comgr, hipblas, rocblas, libhipblaslt, rocsolver, + origami; 230 MiB unpacked, 92 MiB zipped. The ROCm 10 wheels ship no rocBLAS + Tensile kernel library at all; kernels come from `amd_comgr.dll` at run time. + Upstream stopped bundling rocBLAS and its Windows zip no longer loads without + a ROCm SDK (ggml-org/llama.cpp#26996). + +TurboQuant on HIP: the CUDA kernels compile unchanged (no `GGML_USE_HIP` +guards in any turbo kernel), all 21 turbo fattn-vec instances are listed in +`ggml/src/ggml-hip/CMakeLists.txt`. HIP-specific dispatch: + +- `ggml/src/ggml-cuda/fattn.cu`, `#ifdef GGML_USE_HIP` block: decode with a + quantized KV (batch <= 8) is forced onto the VEC kernel (inline dequant, no + f16 scratch, HIP-graph safe); prefill falls through to TILE/MMA. +- `ggml/src/ggml-cuda/fattn.cu`, RDNA4 fast path: VEC preferred for quantized + K/V at <= 2 query columns. +- `ggml/src/ggml-cuda/mmvq-tq.cu`: TQ4_1S/TQ3_1S weights use the scalar path on + AMD (dp4a was measured slower on RDNA4). +- `ggml/src/ggml-cuda/vendors/hip.h`: variadic `__shfl_*_sync` shims and a + 32-bit `__ballot_sync`. + +MTP (Gemma 4) and NextN (Qwen 3.6) speculative decoding live in `src/` and +have no backend code, so they run on HIP and Vulkan as-is. + +Validated so far: MI300X and MI355X throughput (`docs/rocm-mi300x-test-results.md`, +April 2026: turbo4 decode at 89% / 84% of f16, prefill +4% / 98%), RDNA4 by the +community on Windows (RX 9070, 256k context in 16 GB with a 4-bit KV cache). + +## 2. Benchmark plan: ROCm vs Vulkan with TurboQuant + +### Hardware + +- Phase 1, now: Hot Aisle MI300X VM (gfx942, ROCm preinstalled, + https://hotaisle.xyz/quick-start). Gives the CDNA correctness check and the + Instinct row. Vulkan on MI300X goes through Mesa RADV headless; RADV knows + gfx942 but nobody tunes it for Instinct, so that comparison shows how much + HIP is ahead on Instinct, not the consumer picture. Say so in the report. +- Phase 2, when a box is available: RDNA3/RDNA4, where Vulkan vs ROCm is a real + contest (Hostkey rents RX 7900 XTX and Radeon AI PRO R9700, Vast.ai rents RX + 7900 XTX). Strix Halo is not rentable; ask AMD for a sample. + +### Correctness first (CDNA only, once) + +Build from source with tests on the MI300X and run + +```bash +./build/bin/test-backend-ops -o SET_ROWS +./build/bin/test-backend-ops -o FLASH_ATTN_EXT +``` + +Reason: the turbo `set_rows` kernels in `ggml/src/ggml-cuda/set-rows.cu` +compute the lane as `j % WARP_SIZE` (32) while the HIP `__shfl_sync` shim +shuffles with `warpSize` (64 on gfx9) and `__ballot_sync` truncates the mask +to 32 bits. On wave64 hardware the upper half-wave may read the lower half's +bits. The MI300X numbers so far only checked speed and the WHT roundtrip, not +the KV cache contents. RDNA (wave32) is not affected. If the tests fail, fix +before publishing numbers. + +### Matrix + +Models (from the AtomicChat Hugging Face collections, NextN/MTP heads included): + +| Model | Size | Speculative | +|---|---|---| +| Qwen3.6-35B-A3B UDT Q4_K_XL `_MTP` | 20.7 GiB, MoE | NextN | +| Qwen3.6-27B UDT Q4_K_XL `_MTP` | 17.7 GiB, dense | NextN | +| Gemma 4 26B-A4B + assistant Q4_K_M | MoE | MTP | +| Qwen3.5-9B Q4_K_M | small | none; the "long context in small memory" row | + +| Axis | Values | +|---|---| +| backend | fork HIP (`linux-x64-rocm`), fork Vulkan (`linux-x64-vulkan`), upstream HIP of the same day (control: what the fork adds) | +| KV cache | f16, q8_0, turbo3, turbo4 | +| speculative | off, nextn / mtp | +| depth (`-d`) | 0, 8192, 32768, 131072 | +| tests | pp512, pp4096, tg128 | + +Metrics: tokens/s per cell, KV memory at a given context, largest context that +fits, and wikitext-2 perplexity for turbo3/turbo4 vs f16 so "compression +without loss" is measured, not claimed. Flags: `-fa 1 -ngl 99 -ub 2048 -r 3`; +on gfx1151 also `ROCBLAS_USE_HIPBLASLT=1` (about +10% prompt processing, +lemonade-sdk/llamacpp-rocm#7). + +### How to run + +```bash +# once per backend build on the same machine +BIN_DIR=./rocm/build/bin LABEL=hip MODELS="$M1 $M2" PPL_FILE=wiki.test.raw bash scripts/bench-amd.sh +BIN_DIR=./vulkan/build/bin LABEL=vulkan MODELS="$M1 $M2" PPL_FILE=wiki.test.raw bash scripts/bench-amd.sh +BIN_DIR=./upstream/bin LABEL=upstream-hip KV_TYPES="f16 q8_0" MODELS="$M1 $M2" bash scripts/bench-amd.sh + +# one table +python3 scripts/bench-amd-report.py docs/amd/results/*.json --baseline hip/f16 +``` + +`bench-amd.sh` writes, per run, `__