fix(api): apply request logit biases in CUDA and HIP sampling

This commit is contained in:
David authored and Niko1221 committed 2026-10-09 15:21:29 +02:00
1 parent c81f99849e
commit dcc6f756cc
35 files changed
+3028 -10

No files matched your search

+17 -2
View File
@@ -1,3 +1,4 @@
#include "strata/core/logit_bias.hpp"
// src/program/generate.cpp - P2.S6: `strata generate`.
//
// THE DRIVER, and the first program in this project that answers a question. Everything below it is a
@@ -8481,7 +8482,7 @@ int main(int argc, char** argv) {
slots_all += remote_experts[(size_t) r].resident();
mib_all += (int64_t) (remote_experts[(size_t) r].gib() * 1024.0);
}
std::printf("INFO context=%lld kv=%s kv_resident=%lld expert_slots=%lld expert_cache_mib=%lld "
std::printf("INFO logit_bias=1 context=%lld kv=%s kv_resident=%lld expert_slots=%lld expert_cache_mib=%lld "
"expert_slots_primary=%lld expert_cache_primary_mib=%lld spec=%d "
"mtp_max=%d lookup=%d vram_free_mib=%lld cvec=%s arena_mib=%lld pool_workers=%d pcie_frac=%.2f "
"spec_min_p=%.2f conversation_cache_mib=%lld conversation_cache_slots=%d "
@@ -9382,6 +9383,8 @@ int main(int argc, char** argv) {
unsigned long long req_seed = 0;
float req_min_p = 0.0f, req_penalty_repeat = 1.0f, req_penalty_freq = 0.0f, req_penalty_present = 0.0f;
int req_penalty_last_n = 0;
std::string req_bias_text;
bool req_bias_present = false;
int req_cvec = 1; // cvec=0|1: a loaded control vector for this request (on when absent)
// ckpt=0: a one-shot call whose turn no later request extends. No checkpoint at its last turn boundary
// (so no split there) nor every --prompt-cache-every tokens, and its session is neither continued nor
@@ -9409,7 +9412,8 @@ int main(int argc, char** argv) {
if (eq == std::string::npos) { endp = const_cast<char*>(start); break; }
const std::string key = tok.substr(0, eq);
const float fv = std::strtof(tok.c_str() + eq + 1, nullptr);
if (key == "cvec") req_cvec = std::atoi(tok.c_str() + eq + 1);
if (key == "logit_bias") { req_bias_text = tok.substr(eq + 1); req_bias_present = true; }
else if (key == "cvec") req_cvec = std::atoi(tok.c_str() + eq + 1);
else if (key == "ckpt") req_ckpt = std::atoi(tok.c_str() + eq + 1) != 0;
else if (key == "pin") req_pin = std::max<long long>(0, std::atoll(tok.c_str() + eq + 1));
else if (key == "temperature") req_temperature = fv;
@@ -9427,6 +9431,13 @@ int main(int argc, char** argv) {
// unknown keys are skipped: the ids start at the first token without '='
}
}
std::vector<float> req_bias;
std::string bias_error;
if (req_bias_present && (o.batch > 0 ||
!strata::core::parse_logit_bias(req_bias_text, (int) n_vocab, req_bias, bias_error))) {
std::printf("ERR logit_bias: %s\n", o.batch > 0 ? "continuous batching is not supported" : bias_error.c_str());
continue;
}
std::string emb_path;
if (geni && endp != nullptr) {
while (*endp == ' ') ++endp;
@@ -10268,6 +10279,10 @@ int main(int argc, char** argv) {
req_sp.penalty_freq = req_penalty_freq;
req_sp.penalty_present = req_penalty_present;
req_sp.counter = 0;
if (!ver.set_logit_bias(req_bias, err) || (pipe && !ver_b.set_logit_bias(req_bias, err))) {
std::printf("ERR %s\n", err.c_str());
return 1;
}
ver.set_sampling(req_sp);
if (pipe) ver_b.set_sampling(req_sp); // (reaches the later stage's odd verifier)
if (use_mtp) mtp.set_draft_sampling(req_sp); // STRATA_SPEC_COUPLED=1: sampled drafts (a no-op otherwise)