Skip to content

BaseSamplingPipeline

Namespace: LLama.Sampling

Base class for implementing custom sampling pipelines. This provides a helpful framework for implementing ISamplingPipeline.

1
public abstract class BaseSamplingPipeline : ISamplingPipeline, System.IDisposable

Inheritance ObjectBaseSamplingPipeline
Implements ISamplingPipeline, IDisposable

Properties

Grammar

Grammar to constrain valid tokens

1
public SafeLLamaGrammarHandle Grammar { get; set; }

Property Value

SafeLLamaGrammarHandle

Methods

Sample(SafeLLamaContextHandle, Span<Single>, ReadOnlySpan<LLamaToken>)

1
public LLamaToken Sample(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)

Parameters

ctx SafeLLamaContextHandle

logits Span<Single>

lastTokens ReadOnlySpan<LLamaToken>

Returns

LLamaToken

Accept(SafeLLamaContextHandle, LLamaToken)

1
public void Accept(SafeLLamaContextHandle ctx, LLamaToken token)

Parameters

ctx SafeLLamaContextHandle

token LLamaToken

ProcessLogits(SafeLLamaContextHandle, Span<Single>, ReadOnlySpan<LLamaToken>)

Process the raw logit values

1
protected abstract void ProcessLogits(SafeLLamaContextHandle ctx, Span<float> logits, ReadOnlySpan<LLamaToken> lastTokens)

Parameters

ctx SafeLLamaContextHandle
The context being sampled from

logits Span<Single>
The logits produced by the model

lastTokens ReadOnlySpan<LLamaToken>
A list of tokens recently returned by the model

ProcessTokenDataArray(SafeLLamaContextHandle, LLamaTokenDataArray, ReadOnlySpan<LLamaToken>)

Process the LLamaTokenDataArray and select a single token

1
protected abstract LLamaToken ProcessTokenDataArray(SafeLLamaContextHandle ctx, LLamaTokenDataArray candidates, ReadOnlySpan<LLamaToken> lastTokens)

Parameters

ctx SafeLLamaContextHandle
The context being sampled from

candidates LLamaTokenDataArray
The LLamaTokenDataArray data produced by the model

lastTokens ReadOnlySpan<LLamaToken>
A list of tokens recently returned by the model

Returns

LLamaToken

Reset()

1
public void Reset()

Clone()

1
public abstract ISamplingPipeline Clone()

Returns

ISamplingPipeline

Dispose()

1
public void Dispose()