diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 3e7c9ecce..51691dfc4 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -27,8 +27,10 @@ jobs: fail-fast: true matrix: include: + # SSE4.2 stays on unless we disable it; that SIGILLs pre-Nehalem CPUs (#1422). + # -march=x86-64 stops gcc from emitting SSE4 via auto-vectorization. - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' os: ubuntu-22.04 arch: x64 - build: 'avx2' @@ -95,7 +97,7 @@ jobs: matrix: include: - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' - build: 'avx2' defines: '' - build: 'avx' @@ -160,7 +162,7 @@ jobs: matrix: include: - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF' - build: 'avx2' defines: '' - build: 'avx' @@ -222,8 +224,9 @@ jobs: matrix: include: - build: 'arm64' - defines: '-T ClangCL -DCMAKE_GENERATOR_PLATFORM=ARM64 -DGGML_NATIVE=OFF' - runs-on: windows-latest + # ClangCL + CMake PCH disagrees on C17 for ggml-cpu, so llama.dll is never built. + defines: '-T ClangCL -DCMAKE_GENERATOR_PLATFORM=ARM64 -DGGML_NATIVE=OFF -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON' + runs-on: windows-2022 steps: - uses: actions/checkout@v6 with: @@ -238,6 +241,7 @@ jobs: cd build cmake .. ${{ env.COMMON_DEFINE }} ${{ matrix.defines }} cmake --build . --config Release -j ${env:NUMBER_OF_PROCESSORS} --target ggml ggml-base ggml-cpu llama mtmd + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } tree /f - name: Upload artifacts (llama) @@ -535,7 +539,7 @@ jobs: defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=ON -DGGML_AVX2=ON' targets: '--target ggml ggml-base ggml-cpu ggml-blas llama mtmd' - build: 'x64-rosetta2' - defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' targets: '--target ggml ggml-base ggml-cpu ggml-blas llama mtmd' env: MACOS_RPATH_DEFINE: "-DCMAKE_INSTALL_RPATH='@loader_path' -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" diff --git a/LLama/Native/Load/NativeLibraryMetadata.cs b/LLama/Native/Load/NativeLibraryMetadata.cs index e07d40986..05c88a9df 100644 --- a/LLama/Native/Load/NativeLibraryMetadata.cs +++ b/LLama/Native/Load/NativeLibraryMetadata.cs @@ -23,7 +23,7 @@ public override string ToString() public enum AvxLevel { /// - /// No AVX + /// No AVX or SSE4.2. For x86_64 CPUs that only provide SSSE3 / SSE2. /// None, diff --git a/docs/FAQ.md b/docs/FAQ.md index 03ceab536..95dc327b6 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -24,6 +24,22 @@ Generally, there are two possible cases for this problem: 1. The native library (backend) you are using is not compatible with the LLamaSharp version. If you compiled the native library yourself, please make sure you have checkouted llama.cpp to the corresponding commit of LLamaSharp, which could be found at the bottom of README. 2. The model file you are using is not compatible with the backend. If you are using a GGUF file downloaded from huggingface, please check its publishing time. +### Illegal instruction (core dumped) on an older CPU + +`LLamaSharp.Backend.Cpu` ships several x86_64 binaries. The loader picks `noavx` when the CPU has no AVX. Those binaries must also be free of SSE4.2. A CPU that only has SSSE3 (no `sse4_1` / `sse4_2` in `lscpu`) will SIGILL if the `noavx` build still contains SSE4.2 kernels. + +Until a backend package built with `-DGGML_SSE42=OFF` is published, compile llama.cpp yourself and load it before any other LLamaSharp call: + +```bash +cmake -B build -DGGML_NATIVE=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64 -DBUILD_SHARED_LIBS=ON +``` + +```cs +NativeLibraryConfig.All.WithLibrary("", null); +``` + +You can also add `NativeLibraryConfig.All.WithLogCallback(...)` at startup to confirm which runtime folder was loaded (`noavx`, `avx`, `avx2`, ...). + ## Why my model is generating output infinitely