diff --git a/.github/workflows/unsloth-sd-prebuilt.yml b/.github/workflows/unsloth-sd-prebuilt.yml index 081e8d7fb1..cedc70cb8d 100644 --- a/.github/workflows/unsloth-sd-prebuilt.yml +++ b/.github/workflows/unsloth-sd-prebuilt.yml @@ -15,8 +15,8 @@ name: Unsloth SD prebuilt (CPU/Apple/CUDA/Vulkan) # after the upstream release the tree descends from (supply-chain # aged), decide if our release already exists. # build-unix -- macOS arm64 (Metal) + x64, Linux x64 + arm64, Linux Vulkan. -# build-windows-- Windows x64 CPU + Vulkan (MSVC + Ninja), Windows arm64 CPU (clang + Ninja, -# best effort like the CUDA legs). +# build-windows-- Windows x64 CPU + Vulkan (MSVC + Ninja), Windows arm64 CPU (clang + Ninja, two CPU +# variants, best effort like the CUDA legs). # build-linux-cuda / build-windows-cuda -- x64, CUDA 12.8 and 13.3, best effort # (continue-on-error); the CUDA runtime is not bundled, see build-linux-cuda. # assemble -- fingerprint gate, sha256 + manifest, coverage gate, atomic @@ -924,13 +924,15 @@ jobs: - label: win-vulkan-x64 runner: windows-2022 vulkan: "ON" - # Native arm64 (x64 under emulation is ~5x slower). No ggml CPU variant set exists for Windows on ARM, - # so one armv8.2-a + dotprod + fp16 build, which every Windows 11 ARM64 CPU has. + # Native arm64 (x64 under emulation is ~5x slower). Two ggml CPU variants picked per host at startup + # (ggml-patches/0067): armv8.2_2 (dotprod + fp16, the single build this bundle used to be, so the floor + # every Windows 11 ARM64 CPU ran) and armv8.6_0 (+ i8mm: Snapdragon X, Cobalt 100). - label: win-cpu-arm64 runner: windows-11-arm vulkan: "OFF" msvc_arch: arm64 - arm_arch: armv8.2-a+dotprod+fp16 + arm64: "true" + cpu_floor: armv8.2_2 best_effort: true env: VULKAN_VERSION: 1.4.328.1 @@ -963,10 +965,10 @@ jobs: with: python-version: "3.11" - name: Install Ninja - if: ${{ matrix.arm_arch == '' }} + if: ${{ matrix.arm64 != 'true' }} run: choco install ninja --no-progress - name: Install Ninja (arm64) - if: ${{ matrix.arm_arch != '' }} + if: ${{ matrix.arm64 == 'true' }} run: python -m pip install ninja - name: Setup MSVC uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 @@ -999,12 +1001,12 @@ jobs: if ('${{ matrix.cpu_floor }}' -ne '') { $cpuVariants = @('-DSD_BUILD_SHARED_GGML_LIB=ON', '-DBUILD_SHARED_LIBS=ON', '-DGGML_BACKEND_DL=ON', '-DGGML_CPU_ALL_VARIANTS=ON') } - # MSVC has no ARM -march (ggml would force GGML_NATIVE), so arm64 uses the runner's clang on the MSVC ABI; - # no /bigobj needed, and OpenMP off (no runtime on the image; ggml's threadpool instead). + # MSVC has no ARM -march (ggml would force GGML_NATIVE), so arm64 uses the runner's clang on the MSVC ABI + # (each CPU variant gets its own -march); no /bigobj needed, and OpenMP off (no runtime on the image; + # ggml's threadpool instead). $compiler = @("-DCMAKE_CXX_FLAGS=/bigobj") - if ('${{ matrix.arm_arch }}' -ne '') { - $compiler = @('-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', - '-DGGML_CPU_ARM_ARCH=${{ matrix.arm_arch }}', '-DGGML_OPENMP=OFF') + if ('${{ matrix.arm64 }}' -eq 'true') { + $compiler = @('-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', '-DGGML_OPENMP=OFF') } cmake -S . -B build -G Ninja ` -DCMAKE_BUILD_TYPE=Release ` @@ -1106,7 +1108,7 @@ jobs: # The arm64 runner also emulates x64, so prove each PE is ARM64 and sd-cli starts natively. - name: Native arm64 gate - if: ${{ matrix.arm_arch != '' }} + if: ${{ matrix.arm64 == 'true' }} shell: pwsh run: | $ErrorActionPreference = 'Stop' @@ -1136,6 +1138,36 @@ jobs: if ($p.ExitCode -ne 0) { Write-Host "::error::sd-cli --help exited $($p.ExitCode)"; exit 1 } $proc = Get-CimInstance Win32_Processor | Select-Object -First 1 Write-Host "host: $($proc.Name), $($proc.NumberOfCores) cores; $n PE files are ARM64" + # Variant pick: armv8.6_0 where Windows reports i8mm (feature 66), else the armv8.2_2 floor, and the floor + # again under GGML_CPU_ARM_NO_I8MM=1 (the pick of a CPU without i8mm). + Add-Type -Namespace U -Name K -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(uint f);' + $i8mm = [U.K]::IsProcessorFeaturePresent(66) + $empty = Join-Path $env:RUNNER_TEMP 'arm64-variant-cwd' + New-Item -ItemType Directory -Force $empty | Out-Null + $picks = @{} + foreach ($mode in @('auto', 'no_i8mm')) { + if ($mode -eq 'no_i8mm') { $env:GGML_CPU_ARM_NO_I8MM = '1' } else { Remove-Item Env:GGML_CPU_ARM_NO_I8MM -ErrorAction SilentlyContinue } + Push-Location $empty + $out = (& $cli.FullName -m (Join-Path $empty 'none.gguf') -p x -v 2>&1 | Out-String) + $code = $LASTEXITCODE + Pop-Location + # A clean start stops at the missing model (exit 1, new_sd_ctx_t failed). The load line is logged before + # the variant registers, so a crash in the picked DLL (0xC000001D illegal instruction) would still match. + if ($code -ne 1 -or $out -notmatch 'new_sd_ctx_t failed') { + Write-Host $out + Write-Host "::error::sd-cli ($mode) exited $code before reaching the missing-model error" + exit 1 + } + $m = [regex]::Match($out, 'loaded CPU backend from .*ggml-cpu-([A-Za-z0-9._]+)\.dll') + $picks[$mode] = if ($m.Success) { $m.Groups[1].Value } else { '' } + } + Remove-Item Env:GGML_CPU_ARM_NO_I8MM -ErrorAction SilentlyContinue + $want = if ($i8mm) { 'armv8.6_0' } else { 'armv8.2_2' } + Write-Host "i8mm reported: $i8mm; picked: $($picks['auto']) (want $want), with GGML_CPU_ARM_NO_I8MM=1: $($picks['no_i8mm'])" + if ($picks['auto'] -ne $want) { Write-Host "::error::picked CPU variant '$($picks['auto'])', want $want"; exit 1 } + if ($picks['no_i8mm'] -ne 'armv8.2_2') { Write-Host "::error::without i8mm the pick is '$($picks['no_i8mm'])', want armv8.2_2"; exit 1 } + # sd-cli exits 1 at the missing model (checked above), which would otherwise become the step's exit code. + exit 0 - name: Upload bundle uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 diff --git a/scripts/unsloth/ggml-patches/0067-ggml-cpu-windows-arm-variants.patch b/scripts/unsloth/ggml-patches/0067-ggml-cpu-windows-arm-variants.patch new file mode 100644 index 0000000000..81ba6d16b6 --- /dev/null +++ b/scripts/unsloth/ggml-patches/0067-ggml-cpu-windows-arm-variants.patch @@ -0,0 +1,58 @@ +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index fbe27635..2fb6b988 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -545,6 +545,13 @@ if (GGML_CPU_ALL_VARIANTS) + ggml_add_cpu_backend_variant(android_armv9.0_1 DOTPROD MATMUL_INT8 FP16_VECTOR_ARITHMETIC SVE2) + ggml_add_cpu_backend_variant(android_armv9.2_1 DOTPROD MATMUL_INT8 FP16_VECTOR_ARITHMETIC SVE SME) + ggml_add_cpu_backend_variant(android_armv9.2_2 DOTPROD MATMUL_INT8 FP16_VECTOR_ARITHMETIC SVE SVE2 SME) ++ elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") ++ # Unsloth: Windows on Arm (clang, MSVC ABI). The floor is the armv8.2-a + dotprod + fp16 set the single static ++ # build shipped (cpu-feats.cpp does not let it score 0 on Windows), plus NEON + i8mm for the i8mm repack ++ # kernels (Snapdragon X, Cobalt 100). No SVE variants: Windows reports no SVE vector length, and 128-bit SVE ++ # ran slower than NEON (ggml-patches/0020). ++ ggml_add_cpu_backend_variant(armv8.2_2 DOTPROD FP16_VECTOR_ARITHMETIC) ++ ggml_add_cpu_backend_variant(armv8.6_0 DOTPROD FP16_VECTOR_ARITHMETIC MATMUL_INT8) + elseif (APPLE) + ggml_add_cpu_backend_variant(apple_m1 DOTPROD) + ggml_add_cpu_backend_variant(apple_m2_m3 DOTPROD MATMUL_INT8) +diff --git a/src/ggml-cpu/arch/arm/cpu-feats.cpp b/src/ggml-cpu/arch/arm/cpu-feats.cpp +index fb876884..239ca042 100644 +--- a/src/ggml-cpu/arch/arm/cpu-feats.cpp ++++ b/src/ggml-cpu/arch/arm/cpu-feats.cpp +@@ -1,8 +1,9 @@ + #include "ggml-backend-impl.h" + #include "ggml-feats.h" + +-#if defined(__linux__) && defined(GGML_USE_SVE) + #include ++ ++#if defined(__linux__) && defined(GGML_USE_SVE) + #include + #endif + +@@ -10,8 +11,23 @@ + + static int ggml_backend_cpu_aarch64_score() { + int score = 1; +- const ggml_feats_arch64_runtime_t af = ggml_feats_get_arch64_runtime(); ++ ggml_feats_arch64_runtime_t af = ggml_feats_get_arch64_runtime(); + GGML_UNUSED(af); ++#if defined(_WIN32) ++ // Unsloth: the Windows arm64 bundle used to be one static armv8.2-a + dotprod + fp16 build, so its floor variant ++ // (armv8.2_2) must keep loading wherever that build ran. The FP16 and I8MM feature ids (67, 66) are recent and ++ // IsProcessorFeaturePresent returns FALSE for an id the running Windows does not know, so dotprod / fp16 are not ++ // allowed to veto a variant here; i8mm still has to be reported for armv8.6_0 (else the floor runs, as before). ++ af.has_dotprod = true; ++ af.has_fp16 = true; ++#endif ++ { ++ // Unsloth: GGML_CPU_ARM_NO_I8MM=1 scores the i8mm variants 0, i.e. picks the variant a CPU without i8mm gets ++ const char * no_i8mm = getenv("GGML_CPU_ARM_NO_I8MM"); ++ if (no_i8mm != NULL && no_i8mm[0] == '1') { ++ af.has_i8mm = false; ++ } ++ } + + #ifdef GGML_USE_DOTPROD + if (!af.has_dotprod) { return 0; }