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.llamamodel.md 7.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. # LLamaModel
  2. Namespace: LLama
  3. The abstraction of a LLama model, which holds the context in the native library.
  4. ```csharp
  5. public class LLamaModel : System.IDisposable
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [LLamaModel](./llama.llamamodel.md)<br>
  8. Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  9. ## Properties
  10. ### **ContextSize**
  11. The context size.
  12. ```csharp
  13. public int ContextSize { get; }
  14. ```
  15. #### Property Value
  16. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  17. ### **Params**
  18. The model params set for this model.
  19. ```csharp
  20. public ModelParams Params { get; set; }
  21. ```
  22. #### Property Value
  23. [ModelParams](./llama.common.modelparams.md)<br>
  24. ### **NativeHandle**
  25. The native handle, which is used to be passed to the native APIs. Please avoid using it
  26. unless you know what is the usage of the Native API.
  27. ```csharp
  28. public SafeLLamaContextHandle NativeHandle { get; }
  29. ```
  30. #### Property Value
  31. [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  32. ### **Encoding**
  33. The encoding set for this model to deal with text input.
  34. ```csharp
  35. public Encoding Encoding { get; }
  36. ```
  37. #### Property Value
  38. [Encoding](https://docs.microsoft.com/en-us/dotnet/api/system.text.encoding)<br>
  39. ## Constructors
  40. ### **LLamaModel(ModelParams, String, ILLamaLogger)**
  41. ```csharp
  42. public LLamaModel(ModelParams Params, string encoding, ILLamaLogger logger)
  43. ```
  44. #### Parameters
  45. `Params` [ModelParams](./llama.common.modelparams.md)<br>
  46. Model params.
  47. `encoding` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  48. Encoding to deal with text input.
  49. `logger` [ILLamaLogger](./llama.common.illamalogger.md)<br>
  50. The logger.
  51. ## Methods
  52. ### **Tokenize(String, Boolean)**
  53. Tokenize a string.
  54. ```csharp
  55. public IEnumerable<int> Tokenize(string text, bool addBos)
  56. ```
  57. #### Parameters
  58. `text` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  59. `addBos` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  60. Whether to add a bos to the text.
  61. #### Returns
  62. [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  63. ### **DeTokenize(IEnumerable&lt;Int32&gt;)**
  64. Detokenize the tokens to text.
  65. ```csharp
  66. public string DeTokenize(IEnumerable<int> tokens)
  67. ```
  68. #### Parameters
  69. `tokens` [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  70. #### Returns
  71. [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  72. ### **SaveState(String)**
  73. Save the state to specified path.
  74. ```csharp
  75. public void SaveState(string filename)
  76. ```
  77. #### Parameters
  78. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  79. ### **GetStateData()**
  80. Get the state data as a byte array.
  81. ```csharp
  82. public Byte[] GetStateData()
  83. ```
  84. #### Returns
  85. [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
  86. ### **LoadState(String)**
  87. Load the state from specified path.
  88. ```csharp
  89. public void LoadState(string filename)
  90. ```
  91. #### Parameters
  92. `filename` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
  93. #### Exceptions
  94. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  95. ### **LoadState(Byte[])**
  96. Load the state from memory.
  97. ```csharp
  98. public void LoadState(Byte[] stateData)
  99. ```
  100. #### Parameters
  101. `stateData` [Byte[]](https://docs.microsoft.com/en-us/dotnet/api/system.byte)<br>
  102. #### Exceptions
  103. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  104. ### **Sample(LLamaTokenDataArray, Single, MiroStateType, Single, Single, Int32, Single, Single, Single)**
  105. Perform the sampling. Please don't use it unless you fully know what it does.
  106. ```csharp
  107. public int Sample(LLamaTokenDataArray candidates, float temperature, MiroStateType mirostat, float mirostatTau, float mirostatEta, int topK, float topP, float tfsZ, float typicalP)
  108. ```
  109. #### Parameters
  110. `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
  111. `temperature` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  112. `mirostat` [MiroStateType](./llama.common.mirostatetype.md)<br>
  113. `mirostatTau` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  114. `mirostatEta` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  115. `topK` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  116. `topP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  117. `tfsZ` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  118. `typicalP` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  119. #### Returns
  120. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  121. ### **ApplyPenalty(IEnumerable&lt;Int32&gt;, Dictionary&lt;Int32, Single&gt;, Int32, Single, Single, Single, Boolean)**
  122. Apply the penalty for the tokens. Please don't use it unless you fully know what it does.
  123. ```csharp
  124. public LLamaTokenDataArray ApplyPenalty(IEnumerable<int> lastTokens, Dictionary<int, float> logitBias, int repeatLastTokensCount, float repeatPenalty, float alphaFrequency, float alphaPresence, bool penalizeNL)
  125. ```
  126. #### Parameters
  127. `lastTokens` [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  128. `logitBias` [Dictionary&lt;Int32, Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<br>
  129. `repeatLastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  130. `repeatPenalty` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  131. `alphaFrequency` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  132. `alphaPresence` [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  133. `penalizeNL` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  134. #### Returns
  135. [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
  136. ### **Eval(Int32[], Int32)**
  137. ```csharp
  138. public int Eval(Int32[] tokens, int pastTokensCount)
  139. ```
  140. #### Parameters
  141. `tokens` [Int32[]](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  142. `pastTokensCount` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  143. #### Returns
  144. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  145. The updated `pastTokensCount`.
  146. #### Exceptions
  147. [RuntimeError](./llama.exceptions.runtimeerror.md)<br>
  148. ### **GenerateResult(IEnumerable&lt;Int32&gt;)**
  149. ```csharp
  150. internal IEnumerable<string> GenerateResult(IEnumerable<int> ids)
  151. ```
  152. #### Parameters
  153. `ids` [IEnumerable&lt;Int32&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  154. #### Returns
  155. [IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
  156. ### **Dispose()**
  157. ```csharp
  158. public void Dispose()
  159. ```

C#/.NET上易用的LLM高性能推理框架,支持LLaMA和LLaVA系列模型。