Merge f-027-gh-eng-s (#3291 #3955 #3317 #4036 #2893 #3218 #3200: serve, tools and setup ports)

This commit is contained in:
Niko1221 committed 2026-10-26 20:00:53 +01:00
commit 8486336f9b
20 files changed
+1545 -85

No files matched your search

+64
View File
@@ -155,6 +155,51 @@ namespace strata::metal_engine { void set_model_shard(const char* shard1); } /
#include <set>
#include <vector>
// logprobs=K / allowed=...: one `LP` line for the token just emitted, from `ver`'s head
// logits for the window row it came from (before sampling, penalties and temperature).
// Format matches the SYCL port's LP line so one server-side reader serves both.
// Called only when the request asked (`req_logprobs >= 0`): a request without logprobs never reaches it, so the
// default path does no work for this and prints exactly what it printed before.
static void emit_lp_line(const strata::core::Verifier& ver, int t, int32_t token, int k,
const std::vector<int32_t>& allowed) {
if (k < 0) return;
static std::vector<float> row;
row.resize((size_t) ver.vocab());
if (!ver.copy_logits(t, row.data()) || token < 0 || (size_t) token >= row.size()) {
std::printf("LP nan\n");
return;
}
float mx = -INFINITY;
for (const float v : row) mx = std::max(mx, v);
double se = 0.0;
for (const float v : row) se += std::exp((double) v - (double) mx);
const double lse = (double) mx + std::log(se);
std::printf("LP %.6f", (double) row[(size_t) token] - lse);
if (!allowed.empty()) {
// Only the ids the caller named; the server renormalises over them, which is what allowed_token_ids means.
// The server refuses an id past the vocabulary with a 400 only when it can read the vocabulary size from the
// tokenizer. The engine's own vocab() is the authority: an id past it is left off the line, so the logits
// are never read out of bounds.
for (const int32_t id : allowed) {
if (id == token || id < 0 || (int64_t) id >= ver.vocab()) continue;
std::printf(" %d:%.6f", (int) id, (double) row[(size_t) id] - lse);
}
std::printf("\n");
return;
}
if (k > 0) {
static std::vector<int32_t> ord;
ord.resize(row.size());
for (size_t v = 0; v < row.size(); ++v) ord[v] = (int32_t) v;
const int kk = std::min<int>(k, (int) row.size());
std::partial_sort(ord.begin(), ord.begin() + kk, ord.end(),
[&](int32_t a, int32_t b) { return row[(size_t) a] > row[(size_t) b]; });
for (int j = 0; j < kk; ++j)
std::printf(" %d:%.6f", ord[(size_t) j], (double) row[(size_t) ord[(size_t) j]] - lse);
}
std::printf("\n");
}
namespace {
// Windows' WDDM driver model: native Windows, or WSL2 (its GPU goes through /dev/dxg to the Windows driver). There,
// pinning a large arena into two CUDA contexts leaves WDDM refusing every later allocation (the 5080 + 3090 rig);
@@ -12606,6 +12651,11 @@ int main(int argc, char** argv) {
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)
// logprobs=K (0..20): after each "T id" an "LP logprob id:logprob ..." line.
// -1 (absent) = no LP lines, so a server that never asks sees today's output.
int req_logprobs = -1;
// allowed=a,b,c: with logprobs, print only these token ids (renormalized server-side).
std::vector<int32_t> req_allowed;
// 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
// parked after it. It still resumes from a checkpoint it matches, and still saves the system-prompt root
@@ -12645,6 +12695,18 @@ int main(int argc, char** argv) {
else if (key == "temperature") req_temperature = fv;
else if (key == "top_p") req_top_p = fv;
else if (key == "top_k") req_top_k = std::atoi(tok.c_str() + eq + 1);
else if (key == "logprobs") req_logprobs = std::atoi(tok.c_str() + eq + 1);
else if (key == "allowed") {
const std::string csv = tok.substr(eq + 1);
size_t p = 0;
while (p < csv.size()) {
const size_t c = csv.find(",", p);
const std::string one = csv.substr(p, c == std::string::npos ? std::string::npos : c - p);
if (!one.empty()) req_allowed.push_back((int32_t) std::atoi(one.c_str()));
if (c == std::string::npos) break;
p = c + 1;
}
}
else if (key == "min_p") req_min_p = fv;
else if (key == "penalty_last_n") req_penalty_last_n = std::atoi(tok.c_str() + eq + 1);
else if (key == "penalty_repeat") req_penalty_repeat = fv;
@@ -15088,6 +15150,7 @@ int main(int argc, char** argv) {
bool eos = false;
for (int i = 0; !nf && i <= a && produced_n < max_new && !eos; ++i) {
std::printf("T %d\n", (int) outp[(size_t) i]);
if (req_logprobs >= 0) emit_lp_line(V1(A), i, outp[(size_t) i], req_logprobs, req_allowed);
strata::core::progress_beat();
++produced_n;
if (o.suffix_draft > 0) sfx.append(outp[(size_t) i]);
@@ -15523,6 +15586,7 @@ int main(int argc, char** argv) {
bool eos = false;
for (int i = merged ? a : 0; i <= a && produced_n < max_new && !eos; ++i) { // (merged: row T-1 only)
std::printf("T %d\n", (int) outv[(size_t) i]);
if (req_logprobs >= 0) emit_lp_line(ver, i, outv[(size_t) i], req_logprobs, req_allowed);
strata::core::progress_beat();
++produced_n;
if (sfx_on) sfx.append(outv[(size_t) i]);