28#include <unordered_map>
55 const std::string& grammar) {
56 if (grammar.empty()) {
return; }
58 vocab, grammar.c_str(),
"root");
64 logger->info(
"Grammar sampler attached ({} bytes)", grammar.size());
66 logger->error(
"Grammar sampler init FAILED for root rule — output "
67 "will be UNCONSTRAINED. Grammar ({} bytes): {}",
68 grammar.size(), grammar);
84 const std::unordered_map<int32_t, float>&
biases) {
85 if (
biases.empty()) {
return; }
86 std::vector<llama_logit_bias> entries;
87 entries.reserve(
biases.size());
89 entries.push_back({
tok,
val});
94 static_cast<int32_t>(entries.size()),
124 const GenerationParams&
params) {
126 ||
params.presence_penalty > 0.0f
127 ||
params.frequency_penalty > 0.0f;
132 64,
params.repeat_penalty,
134 params.presence_penalty));
163 : chain_(chain), ctx_(
ctx) {}
184 if (chain_ ==
nullptr || ctx_ ==
nullptr) {
return -1; }
194 if (chain_ !=
nullptr) {
234 if (
params.temperature > 0.0f) {
242 if (
params.top_p < 1.0f) {
247 if (
params.min_p > 0.0f) {
255 return std::make_unique<LlamaCppSampler>(chain, ctx_);
LlamaCppSamplerFactory(llama_context *ctx, const llama_vocab *vocab)
Construct with borrowed context + vocab pointers.
std::unique_ptr< Sampler > create(const GenerationParams ¶ms) override
Build the v2.3.10 sampler chain from GenerationParams.
~LlamaCppSampler() override
Free the underlying llama.cpp sampler chain.
LlamaCppSampler(llama_sampler *chain, llama_context *ctx)
Construct with an already-built llama_sampler chain.
int32_t sample() override
Sample one token from the current logits via the wrapped chain.
void reset() override
Reset llama_sampler internal state.
Concrete llama.cpp Sampler + SamplerFactory (v2.3.10 seam impl).
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
Generation parameters for a single inference call.