include/entropic/inference/sampler.h

← API

include/entropic/inference/sampler.h

entropic::Sampler

Pure-virtual per-generation sampler used by the decode loop.

Derived by entropic::LlamaCppSampler.

virtual entropic::Sampler::~Sampler()=default

virtual int32_t entropic::Sampler::sample()=0

Sample one token from the current decode position.

The backend has already positioned its KV cache to the token-to-be-sampled prior to calling sample(). The Sampler is responsible only for converting the latest logits into a token id.

Returns
Chosen token id, or a negative value on internal error (callers treat <0 as a hard failure).

virtual void entropic::Sampler::reset()

Reset internal sampler state.

Default no-op. Mock implementations may override to clear accumulated history (e.g. for tests that reuse a sampler across logical generations). Production llama.cpp samplers are created fresh per generation, so this is largely a test-facing hook.

entropic::SamplerFactory

Factory that materializes a Sampler from GenerationParams .

Derived by entropic::LlamaCppSamplerFactory.

virtual entropic::SamplerFactory::~SamplerFactory()=default

virtual std::unique_ptr< Sampler > entropic::SamplerFactory::create(const GenerationParams &params)=0

Build a configured Sampler for one generation.

Ownership transfers to the caller. Implementations must honor the entropic chain ordering / gating contract (see LlamaCppSamplerFactory::create for the canonical production rules — grammar → penalties → temperature → top-k → top-p → min-p → dist).

Parameters
  • params — Generation parameters (sampler knobs + seed).
Returns
Owned Sampler ready for use in the decode loop.