# BaseSamplingPipeline Namespace: LLama.Sampling Base class for implementing custom sampling pipelines. This provides a helpful framework for implementing `ISamplingPipeline`. ```csharp public abstract class BaseSamplingPipeline : ISamplingPipeline, System.IDisposable ``` Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [BaseSamplingPipeline](./llama.sampling.basesamplingpipeline.md)
Implements [ISamplingPipeline](./llama.sampling.isamplingpipeline.md), [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable) ## Properties ### **Grammar** Grammar to constrain valid tokens ```csharp public SafeLLamaGrammarHandle Grammar { get; set; } ``` #### Property Value [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)
## Methods ### **Sample(SafeLLamaContextHandle, Span<Single>, ReadOnlySpan<LLamaToken>)** ```csharp public LLamaToken Sample(SafeLLamaContextHandle ctx, Span logits, ReadOnlySpan lastTokens) ``` #### Parameters `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)
`logits` [Span<Single>](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)
`lastTokens` [ReadOnlySpan<LLamaToken>](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)
#### Returns [LLamaToken](./llama.native.llamatoken.md)
### **Accept(SafeLLamaContextHandle, LLamaToken)** ```csharp public void Accept(SafeLLamaContextHandle ctx, LLamaToken token) ``` #### Parameters `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)
`token` [LLamaToken](./llama.native.llamatoken.md)
### **ProcessLogits(SafeLLamaContextHandle, Span<Single>, ReadOnlySpan<LLamaToken>)** Process the raw logit values ```csharp protected abstract void ProcessLogits(SafeLLamaContextHandle ctx, Span logits, ReadOnlySpan lastTokens) ``` #### Parameters `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)
The context being sampled from `logits` [Span<Single>](https://docs.microsoft.com/en-us/dotnet/api/system.span-1)
The logits produced by the model `lastTokens` [ReadOnlySpan<LLamaToken>](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)
A list of tokens recently returned by the model ### **ProcessTokenDataArray(SafeLLamaContextHandle, LLamaTokenDataArray, ReadOnlySpan<LLamaToken>)** Process the LLamaTokenDataArray and select a single token ```csharp protected abstract LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan lastTokens) ``` #### Parameters `ctx` [SafeLLamaContextHandle](./llama.native.safellamacontexthandle.md)
The context being sampled from `candidates` [LLamaTokenDataArray](./llama.native.llamatokendataarray.md)
The LLamaTokenDataArray data produced by the model `lastTokens` [ReadOnlySpan<LLamaToken>](https://docs.microsoft.com/en-us/dotnet/api/system.readonlyspan-1)
A list of tokens recently returned by the model #### Returns [LLamaToken](./llama.native.llamatoken.md)
### **Reset()** ```csharp public void Reset() ``` ### **Clone()** ```csharp public abstract ISamplingPipeline Clone() ``` #### Returns [ISamplingPipeline](./llama.sampling.isamplingpipeline.md)
### **Dispose()** ```csharp public void Dispose() ```