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.basesamplingpipeline.md 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # BaseSamplingPipeline
  2. Namespace: LLama.Sampling
  3. Base class for implementing custom sampling pipelines. This provides a helpful framework for implementing `ISamplingPipeline`.
  4. ```csharp
  5. public abstract class BaseSamplingPipeline : ISamplingPipeline, System.IDisposable
  6. ```
  7. Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [BaseSamplingPipeline](./llama.sampling.basesamplingpipeline.md)<br>
  8. Implements [ISamplingPipeline](./llama.sampling.isamplingpipeline.md), [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable)
  9. ## Properties
  10. ### **Grammar**
  11. Grammar to constrain valid tokens
  12. ```csharp
  13. public SafeLLamaGrammarHandle Grammar { get; set; }
  14. ```
  15. #### Property Value
  16. [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)<br>
  17. ## Methods
  18. ### **Sample(SafeLLamaContextHandle, Span&lt;Single&gt;, ReadOnlySpan&lt;LLamaToken&gt;)**
  19. ```csharp
  20. public LLamaToken Sample(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)
  21. ```
  22. #### Parameters
  23. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  24. `logits` [Span&lt;Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  25. `lastTokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  26. #### Returns
  27. [LLamaToken](./llama.native.llamatoken.md)<br>
  28. ### **Accept(SafeLLamaContextHandle, LLamaToken)**
  29. ```csharp
  30. public void Accept(SafeLLamaContextHandle ctx, LLamaToken token)
  31. ```
  32. #### Parameters
  33. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  34. `token` [LLamaToken](./llama.native.llamatoken.md)<br>
  35. ### **ProcessLogits(SafeLLamaContextHandle, Span&lt;Single&gt;, ReadOnlySpan&lt;LLamaToken&gt;)**
  36. Process the raw logit values
  37. ```csharp
  38. protected abstract void ProcessLogits(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)
  39. ```
  40. #### Parameters
  41. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  42. The context being sampled from
  43. `logits` [Span&lt;Single&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)<br>
  44. The logits produced by the model
  45. `lastTokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  46. A list of tokens recently returned by the model
  47. ### **ProcessTokenDataArray(SafeLLamaContextHandle, LLamaTokenDataArray, ReadOnlySpan&lt;LLamaToken&gt;)**
  48. Process the LLamaTokenDataArray and select a single token
  49. ```csharp
  50. protected abstract LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan<LLamaToken> lastTokens)
  51. ```
  52. #### Parameters
  53. `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)<br>
  54. The context being sampled from
  55. `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)<br>
  56. The LLamaTokenDataArray data produced by the model
  57. `lastTokens` [ReadOnlySpan&lt;LLamaToken&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)<br>
  58. A list of tokens recently returned by the model
  59. #### Returns
  60. [LLamaToken](./llama.native.llamatoken.md)<br>
  61. ### **Reset()**
  62. ```csharp
  63. public void Reset()
  64. ```
  65. ### **Clone()**
  66. ```csharp
  67. public abstract ISamplingPipeline Clone()
  68. ```
  69. #### Returns
  70. [ISamplingPipeline](./llama.sampling.isamplingpipeline.md)<br>
  71. ### **Dispose()**
  72. ```csharp
  73. public void Dispose()
  74. ```