Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶ added in v0.21.1
type Options struct {
Temperature float32
TopP float32
MinP float32
TopK int
RepeatLastN int
RepeatPenalty float32
PresencePenalty float32
FrequencyPenalty float32
// Logprobs causes Sample to populate Result.Logprob with the selected
// token's log-probability. TopLogprobs (when > 0) adds top-K pairs.
Logprobs bool
TopLogprobs int
}
type Result ¶ added in v0.21.1
type Result struct {
Token *mlx.Array // sampled token ids, shape [B]
Logprob *mlx.Array // sampled-token logprobs, shape [B,1]; nil unless any registered slot has Logprobs
TopTokens *mlx.Array // top-K token ids, shape [B,maxK]; nil unless any registered slot has TopLogprobs>0
TopLogprobs *mlx.Array // top-K logprobs, shape [B,maxK]; same
}
Result bundles the outputs of one decode step. Logprob/TopTokens/ TopLogprobs are populated whenever any registered slot has Logprobs (respectively TopLogprobs>0). Consumers need to filter by their per-slot Options.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler is a batched, slot-based sampler. Sequences are registered with Add and released with Remove. Each Sample call takes a subset of registered slots (in any order) with their [B,V] logits, samples one token per row, and appends it to that slot's ring-buffer history. Slots not named in a given call are untouched.
func New ¶
New constructs an empty sampler with no registered slots. numCtx is the runner's context window and must be positive.
func (*Sampler) Add ¶ added in v0.22.0
Add registers a sequence under seqID. The last RepeatLastN entries of priorTokens seed the ring buffer.
func (*Sampler) Free ¶
func (s *Sampler) Free()
Free releases the pooled history tensor and resets the sampler to the New-equivalent state so it may be reused.