-
Notifications
You must be signed in to change notification settings - Fork 476
Open
Description
Description
Issue: following the steps in the 'quick start' to use LlamaSharp in a .NET Framework project doesn't work and raises a System.TypeLoadException exception "Could not load type 'LLama.Native.NativeApi' … because the method 'llama_backend_free' has no implementation (no RVA)."
Reproduction Steps
Follow the steps in https://scisharp.github.io/LLamaSharp/0.25.0/QuickStart/ with a .NET Framework 4.8 project.
Environment & Configuration
- Operating system: Windows
- .NET runtime version: .NET Framework 4.8
- LLamaSharp version: 0.25
- CUDA version (if you are using cuda backend):
- CPU & GPU device: AMD Ryzen 7 PORO 7840U with Radeon 780M
Known Workarounds
Root causes identified:
- The NativeLibraryConfig class is disabled for .NET Standard 2.0, so the llama.dll is not found in the output directory
- The NativeApi class and SafeLlamaModelHandle are missing DllImport statements
Fixes:
- Copied manually llama.dll and related libraries to the /bin/Debug output folder (therefore losing the automated dll selection logic)
- Added the statement
[DllImport(NativeApi.libraryName, CallingConvention = CallingConvention.Cdecl)]to the following methods: NativeApi.llama_backend_free(), SafeLlamaModelHandle.llama_model_cls_label(), SafeLlamaModelHandle.llama_model_n_cls_out() - Adapted the
program.csexample to avoid using async streams, not available in this version.
These look like potential changes that would allow it to work in .NET Framework 4.8, but wanted to know if anybody has faced this & if this is of interest for the project.
Metadata
Metadata
Assignees
Labels
No labels