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.llamabatch.md 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # LLamaBatch
  2. Namespace: LLama.Native
  3. A batch allows submitting multiple tokens to multiple sequences simultaneously
  4. ```csharp
  5. public class LLamaBatch
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [LLamaBatch](./llama.native.llamabatch.md)
  8. ## Properties
  9. ### **TokenCount**
  10. The number of tokens in this batch
  11. ```csharp
  12. public int TokenCount { get; private set; }
  13. ```
  14. #### Property Value
  15. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  16. ### **SequenceCapacity**
  17. Maximum number of sequences a token can be assigned to (automatically grows if exceeded)
  18. ```csharp
  19. public int SequenceCapacity { get; private set; }
  20. ```
  21. #### Property Value
  22. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  23. ## Constructors
  24. ### **LLamaBatch()**
  25. Create a new batch for submitting inputs to llama.cpp
  26. ```csharp
  27. public LLamaBatch()
  28. ```
  29. ## Methods
  30. ### **ToNativeBatch(LLamaNativeBatch&)**
  31. ```csharp
  32. internal GroupDisposable ToNativeBatch(LLamaNativeBatch& batch)
  33. ```
  34. #### Parameters
  35. `batch` [LLamaNativeBatch&](./llama.native.llamanativebatch&.md)<br>
  36. #### Returns
  37. [GroupDisposable](./llama.native.groupdisposable.md)<br>
  38. ### **Add(LLamaToken, LLamaPos, ReadOnlySpan&lt;LLamaSeqId&gt;, Boolean)**
  39. Add a single token to the batch at the same position in several sequences
  40. ```csharp
  41. public int Add(LLamaToken token, LLamaPos pos, ReadOnlySpan<LLamaSeqId> sequences, bool logits)
  42. ```
  43. #### Parameters
  44. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  45. The token to add
  46. `pos` [LLamaPos](./llama.native.llamapos.md)<br>
  47. The position to add it att
  48. `sequences` [ReadOnlySpan&lt;LLamaSeqId&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  49. The set of sequences to add this token to
  50. `logits` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  51. #### Returns
  52. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  53. The index that the token was added at. Use this for GetLogitsIth
  54. **Remarks:**
  55. https://github.com/ggerganov/llama.cpp/blob/ad939626577cd25b462e8026cc543efb71528472/common/common.cpp#L829C2-L829C2
  56. ### **Add(LLamaToken, LLamaPos, List&lt;LLamaSeqId&gt;, Boolean)**
  57. Add a single token to the batch at the same position in several sequences
  58. ```csharp
  59. public int Add(LLamaToken token, LLamaPos pos, List<LLamaSeqId> sequences, bool logits)
  60. ```
  61. #### Parameters
  62. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  63. The token to add
  64. `pos` [LLamaPos](./llama.native.llamapos.md)<br>
  65. The position to add it att
  66. `sequences` [List&lt;LLamaSeqId&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
  67. The set of sequences to add this token to
  68. `logits` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  69. #### Returns
  70. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  71. The index that the token was added at. Use this for GetLogitsIth
  72. **Remarks:**
  73. https://github.com/ggerganov/llama.cpp/blob/ad939626577cd25b462e8026cc543efb71528472/common/common.cpp#L829C2-L829C2
  74. ### **Add(LLamaToken, LLamaPos, LLamaSeqId, Boolean)**
  75. Add a single token to the batch at a certain position for a single sequences
  76. ```csharp
  77. public int Add(LLamaToken token, LLamaPos pos, LLamaSeqId sequence, bool logits)
  78. ```
  79. #### Parameters
  80. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  81. The token to add
  82. `pos` [LLamaPos](./llama.native.llamapos.md)<br>
  83. The position to add it att
  84. `sequence` [LLamaSeqId](./llama.native.llamaseqid.md)<br>
  85. The sequence to add this token to
  86. `logits` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  87. #### Returns
  88. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  89. The index that the token was added at. Use this for GetLogitsIth
  90. **Remarks:**
  91. https://github.com/ggerganov/llama.cpp/blob/ad939626577cd25b462e8026cc543efb71528472/common/common.cpp#L829C2-L829C2
  92. ### **AddRange(ReadOnlySpan&lt;LLamaToken&gt;, LLamaPos, LLamaSeqId, Boolean)**
  93. Add a range of tokens to a single sequence, start at the given position.
  94. ```csharp
  95. public int AddRange(ReadOnlySpan<LLamaToken> tokens, LLamaPos start, LLamaSeqId sequence, bool logitsLast)
  96. ```
  97. #### Parameters
  98. `tokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  99. The tokens to add
  100. `start` [LLamaPos](./llama.native.llamapos.md)<br>
  101. The starting position to add tokens at
  102. `sequence` [LLamaSeqId](./llama.native.llamaseqid.md)<br>
  103. The sequence to add this token to
  104. `logitsLast` [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  105. Whether the final token should generate logits
  106. #### Returns
  107. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  108. The index that the final token was added at. Use this for GetLogitsIth
  109. ### **Clear()**
  110. Set TokenCount to zero for this batch
  111. ```csharp
  112. public void Clear()
  113. ```
  114. ### **GetLogitPositions(Span&lt;ValueTuple&lt;LLamaSeqId, Int32&gt;&gt;)**
  115. Get the positions where logits can be sampled from
  116. ```csharp
  117. internal Span<ValueTuple<LLamaSeqId, int>> GetLogitPositions(Span<ValueTuple<LLamaSeqId, int>> dest)
  118. ```
  119. #### Parameters
  120. `dest` [Span&lt;ValueTuple&lt;LLamaSeqId, Int32&gt;&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  121. #### Returns
  122. [Span&lt;ValueTuple&lt;LLamaSeqId, Int32&gt;&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>