You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

llama.native.nativelibraryconfig.md 6.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. # NativeLibraryConfig
  2. Namespace: LLama.Native
  3. Allows configuration of the native llama.cpp libraries to load and use.
  4. All configuration must be done before using **any** other LLamaSharp methods!
  5. ```csharp
  6. public sealed class NativeLibraryConfig
  7. ```
  8. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)
  9. ## Properties
  10. ### **Instance**
  11. Get the config instance
  12. ```csharp
  13. public static NativeLibraryConfig Instance { get; }
  14. ```
  15. #### Property Value
  16. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  17. ### **LibraryHasLoaded**
  18. Check if the native library has already been loaded. Configuration cannot be modified if this is true.
  19. ```csharp
  20. public static bool LibraryHasLoaded { get; internal set; }
  21. ```
  22. #### Property Value
  23. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  24. ## Methods
  25. ### **WithLibrary(String, String)**
  26. Load a specified native library as backend for LLamaSharp.
  27. When this method is called, all the other configurations will be ignored.
  28. ```csharp
  29. public NativeLibraryConfig WithLibrary(string llamaPath, string llavaPath)
  30. ```
  31. #### Parameters
  32. `llamaPath` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  33. The full path to the llama library to load.
  34. `llavaPath` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  35. The full path to the llava library to load.
  36. #### Returns
  37. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  38. #### Exceptions
  39. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  40. Thrown if `LibraryHasLoaded` is true.
  41. ### **WithCuda(Boolean)**
  42. Configure whether to use cuda backend if possible.
  43. ```csharp
  44. public NativeLibraryConfig WithCuda(bool enable)
  45. ```
  46. #### Parameters
  47. `enable` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  48. #### Returns
  49. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  50. #### Exceptions
  51. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  52. Thrown if `LibraryHasLoaded` is true.
  53. ### **WithAvx(AvxLevel)**
  54. Configure the prefferred avx support level of the backend.
  55. ```csharp
  56. public NativeLibraryConfig WithAvx(AvxLevel level)
  57. ```
  58. #### Parameters
  59. `level` [AvxLevel](./llama.native.nativelibraryconfig.avxlevel.md)<br>
  60. #### Returns
  61. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  62. #### Exceptions
  63. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  64. Thrown if `LibraryHasLoaded` is true.
  65. ### **WithAutoFallback(Boolean)**
  66. Configure whether to allow fallback when there's no match for preferred settings.
  67. ```csharp
  68. public NativeLibraryConfig WithAutoFallback(bool enable)
  69. ```
  70. #### Parameters
  71. `enable` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  72. #### Returns
  73. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  74. #### Exceptions
  75. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  76. Thrown if `LibraryHasLoaded` is true.
  77. ### **SkipCheck(Boolean)**
  78. Whether to skip the check when you don't allow fallback. This option
  79. may be useful under some complex conditions. For example, you're sure
  80. you have your cublas configured but LLamaSharp take it as invalid by mistake.
  81. ```csharp
  82. public NativeLibraryConfig SkipCheck(bool enable)
  83. ```
  84. #### Parameters
  85. `enable` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  86. #### Returns
  87. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  88. #### Exceptions
  89. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  90. Thrown if `LibraryHasLoaded` is true.
  91. ### **WithLogs(Boolean)**
  92. Whether to output the logs to console when loading the native library with your configuration.
  93. ```csharp
  94. public NativeLibraryConfig WithLogs(bool enable)
  95. ```
  96. #### Parameters
  97. `enable` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  98. #### Returns
  99. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  100. #### Exceptions
  101. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  102. Thrown if `LibraryHasLoaded` is true.
  103. ### **WithLogs(LLamaLogLevel)**
  104. Enable console logging with the specified log logLevel.
  105. ```csharp
  106. public NativeLibraryConfig WithLogs(LLamaLogLevel logLevel)
  107. ```
  108. #### Parameters
  109. `logLevel` [LLamaLogLevel](./llama.native.llamaloglevel.md)<br>
  110. #### Returns
  111. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  112. #### Exceptions
  113. [InvalidOperationException](https://docs.microsoft.com/en-us/dotnet/api/system.invalidoperationexception)<br>
  114. Thrown if `LibraryHasLoaded` is true.
  115. ### **WithSearchDirectories(IEnumerable&lt;String&gt;)**
  116. Add self-defined search directories. Note that the file stucture of the added
  117. directories must be the same as the default directory. Besides, the directory
  118. won't be used recursively.
  119. ```csharp
  120. public NativeLibraryConfig WithSearchDirectories(IEnumerable<string> directories)
  121. ```
  122. #### Parameters
  123. `directories` [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  124. #### Returns
  125. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  126. ### **WithSearchDirectory(String)**
  127. Add self-defined search directories. Note that the file stucture of the added
  128. directories must be the same as the default directory. Besides, the directory
  129. won't be used recursively.
  130. ```csharp
  131. public NativeLibraryConfig WithSearchDirectory(string directory)
  132. ```
  133. #### Parameters
  134. `directory` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  135. #### Returns
  136. [NativeLibraryConfig](./llama.native.nativelibraryconfig.md)<br>
  137. ### **CheckAndGatherDescription(LibraryName)**
  138. ```csharp
  139. internal static Description CheckAndGatherDescription(LibraryName library)
  140. ```
  141. #### Parameters
  142. `library` [LibraryName](./llama.native.libraryname.md)<br>
  143. #### Returns
  144. [Description](./llama.native.nativelibraryconfig.description.md)<br>
  145. ### **AvxLevelToString(AvxLevel)**
  146. ```csharp
  147. internal static string AvxLevelToString(AvxLevel level)
  148. ```
  149. #### Parameters
  150. `level` [AvxLevel](./llama.native.nativelibraryconfig.avxlevel.md)<br>
  151. #### Returns
  152. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>