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.safellamamodelhandle.md 5.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. # SafeLlamaModelHandle
  2. Namespace: LLama.Native
  3. A reference to a set of llama model weights
  4. ```csharp
  5. public sealed class SafeLlamaModelHandle : SafeLLamaHandleBase, System.IDisposable
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [CriticalFinalizerObject](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.constrainedexecution.criticalfinalizerobject) → [SafeHandle](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle) → [SafeLLamaHandleBase](./llama.native.safellamahandlebase.md) → [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)<br>
  8. Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  9. ## Properties
  10. ### **VocabCount**
  11. Total number of tokens in vocabulary of this model
  12. ```csharp
  13. public int VocabCount { get; }
  14. ```
  15. #### Property Value
  16. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  17. ### **ContextSize**
  18. Total number of tokens in the context
  19. ```csharp
  20. public int ContextSize { get; }
  21. ```
  22. #### Property Value
  23. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  24. ### **EmbeddingSize**
  25. Dimension of embedding vectors
  26. ```csharp
  27. public int EmbeddingSize { get; }
  28. ```
  29. #### Property Value
  30. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  31. ### **IsInvalid**
  32. ```csharp
  33. public bool IsInvalid { get; }
  34. ```
  35. #### Property Value
  36. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  37. ### **IsClosed**
  38. ```csharp
  39. public bool IsClosed { get; }
  40. ```
  41. #### Property Value
  42. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  43. ## Methods
  44. ### **ReleaseHandle()**
  45. ```csharp
  46. protected bool ReleaseHandle()
  47. ```
  48. #### Returns
  49. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  50. ### **LoadFromFile(String, LLamaContextParams)**
  51. Load a model from the given file path into memory
  52. ```csharp
  53. public static SafeLlamaModelHandle LoadFromFile(string modelPath, LLamaContextParams lparams)
  54. ```
  55. #### Parameters
  56. `modelPath` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  57. `lparams` [LLamaContextParams](./llama.native.llamacontextparams.md)<br>
  58. #### Returns
  59. [SafeLlamaModelHandle](./llama.native.safellamamodelhandle.md)<br>
  60. #### Exceptions
  61. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  62. ### **ApplyLoraFromFile(String, String, Int32)**
  63. Apply a LoRA adapter to a loaded model
  64. ```csharp
  65. public void ApplyLoraFromFile(string lora, string modelBase, int threads)
  66. ```
  67. #### Parameters
  68. `lora` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  69. `modelBase` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  70. A path to a higher quality model to use as a base for the layers modified by the
  71. adapter. Can be NULL to use the current loaded model.
  72. `threads` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  73. #### Exceptions
  74. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  75. ### **TokenToSpan(Int32, Span&lt;Byte&gt;)**
  76. Convert a single llama token into bytes
  77. ```csharp
  78. public int TokenToSpan(int llama_token, Span<byte> dest)
  79. ```
  80. #### Parameters
  81. `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  82. Token to decode
  83. `dest` [Span&lt;Byte&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  84. A span to attempt to write into. If this is too small nothing will be written
  85. #### Returns
  86. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  87. The size of this token. **nothing will be written** if this is larger than `dest`
  88. ### **TokenToString(Int32, Encoding)**
  89. Convert a single llama token into a string
  90. ```csharp
  91. public string TokenToString(int llama_token, Encoding encoding)
  92. ```
  93. #### Parameters
  94. `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  95. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  96. Encoding to use to decode the bytes into a string
  97. #### Returns
  98. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  99. ### **TokenToString(Int32, Encoding, StringBuilder)**
  100. Append a single llama token to a string builder
  101. ```csharp
  102. public void TokenToString(int llama_token, Encoding encoding, StringBuilder dest)
  103. ```
  104. #### Parameters
  105. `llama_token` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  106. Token to decode
  107. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  108. `dest` [StringBuilder](https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder)<br>
  109. string builder to append the result to
  110. ### **Tokenize(String, Boolean, Encoding)**
  111. Convert a string of text into tokens
  112. ```csharp
  113. public Int32[] Tokenize(string text, bool add_bos, Encoding encoding)
  114. ```
  115. #### Parameters
  116. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  117. `add_bos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  118. `encoding` [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  119. #### Returns
  120. [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  121. ### **CreateContext(LLamaContextParams)**
  122. Create a new context for this model
  123. ```csharp
  124. public SafeLLamaContextHandle CreateContext(LLamaContextParams params)
  125. ```
  126. #### Parameters
  127. `params` [LLamaContextParams](./llama.native.llamacontextparams.md)<br>
  128. #### Returns
  129. [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>