LLamaSharp icon indicating copy to clipboard operation
LLamaSharp copied to clipboard

Getting a Illegal instruction (core dumped) when trying to run

Open blackdow1 opened this issue 3 months ago • 6 comments

Getting the Illegal instruction (core dumped) when I try to run llamasharp. Here is my process of trying to run this repo: -dotnet new console -n LlamaSharpProject -cd LLamaSharpProject -dotnet add package LLamaSharp (I did not see the notice at the bottom of the readme at first, so i also went back and did the process over with --version 0.24.0 appended) -dotnet add package LLamaSharp.Backend.Cpu (appended --version 0.24.0 on other attempt) -dotnet build -dotnet run (it fails silently, get no feedback from console.) I then try dotnet bin/Debug/net10.0/LlamaSharpProject.dll and that is when i see the core dump message.

I am running this on an old laptop. These are its flags from lscpu command: Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pg e mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx lm constant_tsc arch_perf mon pebs bts rep_good nopl cpuid aperfmperf pni dte s64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lah f_lm pti dtherm ida

I am able to run models fine using ggml's llama.cpp. I am running the Qwen3-0_6B-Q4_0 Any help would be greatly appreciated.

blackdow1 avatar Aug 21 '26 21:08 blackdow1

Hi @blackdow1, your lscpu flags point directly to the root of the problem.

The Illegal instruction (core dumped) error is happening because your laptop's CPU is a bit older and doesn't support AVX or AVX2 instructions (looking at your flags, your CPU caps out at ssse3).

The native libraries bundled inside the LLamaSharp.Backend.Cpu NuGet package are pre-compiled with AVX support enabled to ensure fast performance for most modern hardware. When your CPU encounters one of those instructions, it crashes.

The reason standard llama.cpp works for you is likely because you built it from source on that machine, meaning your C++ compiler automatically turned off AVX instructions to match your hardware.

How to fix this: To run LLamaSharp on this specific machine, you'll need to use a backend compiled without AVX.

zsogitbe avatar Aug 22 '26 05:08 zsogitbe

I'll work on this. Could you assign it to me?

I'll look at the current code, add a focused test, and send a small PR.

modelpath-dev avatar Sep 04 '26 08:09 modelpath-dev

Thanks very much for volunteering to look into this. I suspect you'll need to look into modifying the noavx build in this file to remove the unknown instructions.

martindevans avatar Sep 04 '26 11:09 martindevans

Thanks for the guidance, @martindevans. I'll check out the noavx build in the compile.yml file and see what modifications are needed to remove the unsupported instructions. I'll update here once I make some progress.

modelpath-dev avatar Sep 05 '26 07:09 modelpath-dev

PR is up: https://github.com/SciSharp/LLamaSharp/pull/1438

The noavx job was already turning AVX off, but ggml still defaulted GGML_SSE42=ON and compiled with -msse4.2. That is an illegal instruction on a CPU that only has SSSE3.

The PR turns SSE4.2 off on every noavx / Rosetta build and pins gcc/clang to -march=x86-64. I configured current llama.cpp both ways: old flags print -msse4.2 GGML_SSE42, new flags do not, and objdump of the new libggml-cpu.so has no SSE4.1/4.2 ops.

This does not change the NuGet you have installed today. It takes effect after the next Update Binaries run and a new LLamaSharp.Backend.Cpu publish. Until then you can compile llama.cpp with those same flags and load it through NativeLibraryConfig.All.WithLibrary. I put that path in the FAQ on the PR.

modelpath-dev avatar Sep 06 '26 10:09 modelpath-dev

This issue has been automatically marked as stale due to inactivity. If no further activity occurs, it will be closed in 7 days.

github-actions[bot] avatar Nov 06 '26 00:11 github-actions[bot]