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.sampling.defaultsamplingpipeline.md 5.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # DefaultSamplingPipeline
  2. Namespace: LLama.Sampling
  3. An implementation of ISamplePipeline which mimics the default llama.cpp sampling
  4. ```csharp
  5. public sealed class DefaultSamplingPipeline : BaseSamplingPipeline, ISamplingPipeline, System.IDisposable
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [BaseSamplingPipeline](./llama.sampling.basesamplingpipeline.md) → [DefaultSamplingPipeline](./llama.sampling.defaultsamplingpipeline.md)<br>
  8. Implements [ISamplingPipeline](./llama.sampling.isamplingpipeline.md), [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  9. ## Properties
  10. ### **LogitBias**
  11. Bias values to add to certain logits
  12. ```csharp
  13. public Dictionary<int, float> LogitBias { get; }
  14. ```
  15. #### Property Value
  16. [Dictionary&lt;Int32, Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)<br>
  17. ### **RepeatPenalty**
  18. Repetition penalty, as described in https://arxiv.org/abs/1909.05858
  19. ```csharp
  20. public float RepeatPenalty { get; set; }
  21. ```
  22. #### Property Value
  23. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  24. ### **AlphaFrequency**
  25. Frequency penalty as described by OpenAI: https://platform.openai.com/docs/api-reference/chat/create<br>
  26. Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text
  27. so far, decreasing the model's likelihood to repeat the same line verbatim.
  28. ```csharp
  29. public float AlphaFrequency { get; set; }
  30. ```
  31. #### Property Value
  32. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  33. ### **AlphaPresence**
  34. Presence penalty as described by OpenAI: https://platform.openai.com/docs/api-reference/chat/create<br>
  35. Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the
  36. text so far, increasing the model's likelihood to talk about new topics.
  37. ```csharp
  38. public float AlphaPresence { get; set; }
  39. ```
  40. #### Property Value
  41. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  42. ### **Temperature**
  43. Temperature to apply (higher temperature is more "creative")
  44. ```csharp
  45. public float Temperature { get; set; }
  46. ```
  47. #### Property Value
  48. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  49. ### **TopK**
  50. Number of tokens to keep in TopK sampling
  51. ```csharp
  52. public int TopK { get; set; }
  53. ```
  54. #### Property Value
  55. [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
  56. ### **TailFreeZ**
  57. Z value for tail free sampling
  58. ```csharp
  59. public float TailFreeZ { get; set; }
  60. ```
  61. #### Property Value
  62. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  63. ### **TypicalP**
  64. P value for locally typical sampling
  65. ```csharp
  66. public float TypicalP { get; set; }
  67. ```
  68. #### Property Value
  69. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  70. ### **TopP**
  71. P value for TopP sampling
  72. ```csharp
  73. public float TopP { get; set; }
  74. ```
  75. #### Property Value
  76. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  77. ### **MinP**
  78. P value for MinP sampling
  79. ```csharp
  80. public float MinP { get; set; }
  81. ```
  82. #### Property Value
  83. [Single](https://docs.microsoft.com/en-us/dotnet/api/system.single)<br>
  84. ### **PenalizeNewline**
  85. Whether the newline value should be protected from being modified by logit bias and repeat penalty
  86. ```csharp
  87. public bool PenalizeNewline { get; set; }
  88. ```
  89. #### Property Value
  90. [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)<br>
  91. ### **Grammar**
  92. Grammar to constrain valid tokens
  93. ```csharp
  94. public SafeLLamaGrammarHandle Grammar { get; set; }
  95. ```
  96. #### Property Value
  97. [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)<br>
  98. ## Constructors
  99. ### **DefaultSamplingPipeline()**
  100. ```csharp
  101. public DefaultSamplingPipeline()
  102. ```
  103. ## Methods
  104. ### **ProcessLogits(SafeLLamaContextHandle, Span&lt;Single&gt;, ReadOnlySpan&lt;LLamaToken&gt;)**
  105. ```csharp
  106. protected void ProcessLogits(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)
  107. ```
  108. #### Parameters
  109. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  110. `logits` [Span&lt;Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  111. `lastTokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  112. ### **ProcessTokenDataArray(SafeLLamaContextHandle, LLamaTokenDataArray, ReadOnlySpan&lt;LLamaToken&gt;)**
  113. ```csharp
  114. protected LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan<LLamaToken> lastTokens)
  115. ```
  116. #### Parameters
  117. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  118. `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
  119. `lastTokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  120. #### Returns
  121. [LLamaToken](./llama.native.llamatoken.md)<br>
  122. ### **Accept(SafeLLamaContextHandle, LLamaToken)**
  123. ```csharp
  124. public void Accept(SafeLLamaContextHandle ctx, LLamaToken token)
  125. ```
  126. #### Parameters
  127. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  128. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  129. ### **Clone()**
  130. ```csharp
  131. public ISamplingPipeline Clone()
  132. ```
  133. #### Returns
  134. [ISamplingPipeline](./llama.sampling.isamplingpipeline.md)<br>