| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
As indicated in Architecture, LLamaSharp uses the native library to run the LLM models. Sometimes you may want to compile the native library yourself, or just dynamically load the library due to the environment of your user of your application. Luckily, since version 0.7.0, dynamic loading of native library has been supported! That allows you to customize the native library loading process.
Before introducing the way to customize native library loading, please follow the tips below to see if you need to compile the native library yourself, rather than use the published backend packages, which contain native library files for multiple targets.
We provide LLama.Native.NativeLibraryConfig class with singleton mode to allow users to customize the loading process of the native library. Any method of it should be called before the model loading, because a native library file must be decided before any model is loaded.
All you need to do is adding the following code to the very beginning of your code.
NativeLibraryConfig.All.WithLibrary("<Your native library path>");If you want to configure the loading for LLama library or llava library respectively, please call the following APIs.
NativeLibraryConfig.LLama.WithLibrary("<Your llama native library path>");
NativeLibraryConfig.LLava.WithLibrary("<Your llava native library path>");Let's consider this case: you don't know your user's device when distributing your application, so you put all the possible native libraries in a folder and want to select the best one depending on the user's device. LLamaSharp allows you to define the strategy to do it.
NativeLibraryConfig.All.SkipCheck allows you to skip the checks of the device/environment compatibility. This API will be very useful if your users have an unusual environment. For example, if the user installed the cuda toolkit in a customized path and didn't set the environment variables correctly, it might be regarded as invalid even though the loading could actually succeed.
In some conditions, you or your users are not sure if the native library could be successfully loaded with the configuration. To address this issue, NativeLibraryConfig.All.DryRun is provided to try to run the native library loading with the current configuration. It will return whether the loading is successfully, and the loaded library. However, the loaded library is not assigned to the handle of NativeApi. So you could try different configurations until one of them could be loaded successfully.
NOTE: Similar to other APIs, NativeLibraryConfig.All.DryRun is only available before calling an arbitrary API in NativeApi, too.
NativeLibraryConfig.All.WithLogs();There are four log levels, which are error, warning, info and debug. If you are not sure if the correct library is selected, please set log level to info to see the full logs.
| Back | FazBrowse Home | New Git URL |