radiance 1.0.1

- Up to 32 sequences a step on every model. The DSpark drafter (MiniCPM5) no longer rejects every
  draft from the tenth sequence on, and the step batch's block tables and media staging are
  charged to the VRAM budget instead of the headroom kernels load into.
- A tool parameter whose schema accepts no value ({"not": {}}, as TypeBox and Arktype export
  `never`) is an argument no call writes, instead of failing the request. oh-my-pi's task tool
  works.
- --served-model-name NAME and --override-chat-template PATH.
- The startup session count counts only the part of the KV pool that holds context.
- Compose files and README run --max-num-seqs 32 where it keeps a 200K-token request.
This commit is contained in:
Deadcode committed 2026-10-04 15:07:32 +02:00
1 parent ae74a8aebf
commit 8ddb77e03c
28 files changed
+595 -60

No files matched your search

+9
View File
@@ -84,6 +84,7 @@ static const Flag g_flags[] = {
{ "--host", "ADDR", "listen address" },
{ "--port", "N", "listen port" },
{ "--api-key", "KEY", "require `Authorization: Bearer KEY` on every request but /health, /ping and the dashboard page" },
{ "--served-model-name", "NAME", "the model id /v1/models lists and responses carry; default the container's name" },
{ "--mm-max-patches", "N", "patches one encoder pass carries, and so the largest image (a patch is 16x16\n"
"pixels). Default `auto`: 16384 when the container carries a vision tower. 0\n"
"serves text only and keeps the tower off the card" },
@@ -91,6 +92,7 @@ static const Flag g_flags[] = {
" for requests that send none. Without it the container's own\n"
" `generation.*` metadata is used, then a <model>.generation.json\n"
" beside the container, then the built-in defaults" },
{ "--override-chat-template", "PATH", "a Jinja chat template file, used in place of the one the container carries" },
{ "--temp", "F", "default temperature for requests that do not set one" },
{ "--top-k", "N", "default top_k (0 = off) for requests that do not set one" },
{ "--top-p", "F", "default top_p for requests that do not set one" },
@@ -267,6 +269,11 @@ int config_parse(int argc, char** argv, Config* c) {
else if (S("--host")) { if (!(v = need(i))) return RAD_E_INVAL; c->host = v; }
else if (S("--port")) { if (!(v = need(i))) return RAD_E_INVAL; c->port = atoi(v); }
else if (S("--api-key")) { if (!(v = need(i))) return RAD_E_INVAL; c->api_key = v; }
else if (S("--served-model-name")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!*v) { RAD_ERR("--served-model-name takes a non-empty name"); return RAD_E_INVAL; }
c->served_model_name = v;
}
else if (S("--mm-max-patches")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "auto")) c->mm_max_patches = -1;
@@ -284,6 +291,8 @@ int config_parse(int argc, char** argv, Config* c) {
c->reasoning_effort = v; }
else if (S("--generation-config")) { if (!(v = need(i))) return RAD_E_INVAL;
c->generation_config = v; }
else if (S("--override-chat-template")) { if (!(v = need(i))) return RAD_E_INVAL;
c->override_chat_template = v; }
/* A NEGATIVE VALUE IS REFUSED HERE, not left to the range checks below: the fields use
* a negative number to mean "not set", so `--temp -0.5` would otherwise be read as no
* flag at all and the container's default served in its place. */
+5 -1
View File
@@ -1959,11 +1959,15 @@ int Engine::run_server() {
}
server::ServerOptions o{};
o.model_id = meta_.name && *meta_.name ? meta_.name : "radiance";
o.model_id = !cfg_.served_model_name.empty() ? cfg_.served_model_name
: meta_.name && *meta_.name ? meta_.name : "radiance";
o.host = cfg_.host;
o.port = cfg_.port;
o.api_key = cfg_.api_key;
o.max_seqs = cfg_.max_seqs;
/* `n` fans one request out over the batch, so a server that runs more sequences a step takes
* more choices a request; the floor keeps a small batch from refusing what it would queue. */
o.max_n = (int)std::max<int64_t>(o.max_n, cfg_.max_seqs);
o.max_ctx = cfg_.max_ctx ? cfg_.max_ctx : meta_.n_ctx_train;
o.default_reasoning_effort = cfg_.reasoning_effort;
o.default_sampling = resolve_sampling_defaults(meta_, file_ != nullptr, cfg_);
+58 -7
View File
@@ -26,6 +26,8 @@
#include <unistd.h>
#include <cstring>
#include <fstream>
#include <sstream>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
@@ -445,12 +447,20 @@ int Engine::declare() {
nullptr, sources());
});
}
if (cfg_.tp > 1 && !cfg_.tp_wire_exact)
RAD_WARN("tp wire: LOSSY (--tp-wire wht6) above %lld KiB a message. A cross-rank "
"all-reduce at or over that size carries a Walsh-Hadamard-rotated 6-bit payload "
"instead of bf16, so this process does not compute the same function the exact "
"wire does; smaller messages -- which is every decode step -- are still exact.",
(long long)cfg_.tp_wire_min_kb);
/* A message is a step's rows of the residual stream in bf16, so the floor is a ROW COUNT: a
* decode step's rows are its sequences times one plus the speculative depth, and concurrency
* alone decides whether a decode step is under it. */
if (cfg_.tp > 1 && !cfg_.tp_wire_exact) {
const int64_t row_bytes = meta_.n_embd > 0 ? meta_.n_embd * 2 : 1;
const int64_t exact_rows = (cfg_.tp_wire_min_kb * 1024 + row_bytes - 1) / row_bytes - 1;
RAD_WARN("tp wire: LOSSY (--tp-wire wht6) at %lld KiB a message and above. A cross-rank "
"all-reduce of that size carries a Walsh-Hadamard-rotated 6-bit payload instead "
"of bf16, so this process does not compute the same function the exact wire "
"does. Steps of at most %lld rows are exact: single-sequence decode, and a "
"decode step until sequences x (1 + speculative depth) passes that; prefill and "
"a busy decode step are lossy. --tp-wire-min-kb moves the floor.",
(long long)cfg_.tp_wire_min_kb, (long long)exact_rows);
}
for (auto& t : th) t.join();
@@ -677,8 +687,21 @@ int Engine::plan() {
* no memory and no pool; it is the half of configure() that is pure arithmetic on the
* declaration, split out for exactly this caller. */
KVManager probe;
if (probe.plan_groups(r->program.kv_groups, cfg_) == RAD_OK)
if (probe.plan_groups(r->program.kv_groups, cfg_) == RAD_OK) {
f.kv_ceiling = probe.ceiling(ctx);
f.kv_fixed = probe.fixed_bytes();
}
/* THE STEP BATCH'S DEVICE STAGING, which the scheduler reserves after this split: its
* block tables are carved for max_seqs sequences at max_ctx and its media staging for
* max_tok encoder rows. The state-index widths are the probe's, as the scheduler takes
* them from the configured manager. */
KVGeom kg = KVGeom::of(r->program.kv_groups);
for (size_t i = 0; i < kg.g.size(); ++i) {
const int64_t w = probe.state_index_width((int32_t)i);
if (w > 0) kg.g[i].sidx_width = w;
}
f.staging = BatchBuilder::device_bytes(r->program, cfg_, kg);
if (f.staging < 0) return RAD_E_INVAL;
facts.push_back(f);
}
VramBudget vb;
@@ -2818,6 +2841,34 @@ int Engine::load_vocab() {
}
}
/* THE OPERATOR'S TEMPLATE REPLACES THE CONTAINER'S before anything reads it, so the chat
* endpoint and the reply format derived from the template agree about which one is served. An
* unreadable or empty file is refused: serving the container's template in its place would be
* the silent fallback the flag exists to rule out. */
if (!cfg_.override_chat_template.empty()) {
std::ifstream f(cfg_.override_chat_template);
if (!f) {
RAD_ERR("--override-chat-template %s: cannot read the file",
cfg_.override_chat_template.c_str());
return RAD_E_IO;
}
std::ostringstream ss;
ss << f.rdbuf();
std::string t = ss.str();
/* Trailing newlines go, as they do for a checkpoint's own chat_template.jinja, so one file
* renders the same prompt whichever way it reaches the server. */
while (!t.empty() && (t.back() == '\n' || t.back() == '\r')) t.pop_back();
if (t.find_first_not_of(" \t\r\n") == std::string::npos) {
RAD_ERR("--override-chat-template %s: the file is empty",
cfg_.override_chat_template.c_str());
return RAD_E_INVAL;
}
RAD_INFO("chat: template from %s (%zu bytes), in place of the container's%s",
cfg_.override_chat_template.c_str(), t.size(),
vb.chat_template.empty() ? ", which carries none" : "");
vb.chat_template = std::move(t);
}
auto v = std::make_shared<Vocab>();
RAD_TRY(v->load(std::move(vb)));
vocab_ = v;
+3
View File
@@ -165,6 +165,9 @@ public:
* and nothing else (core/mem/vram_budget.cpp). carve() spends the pool it is given. */
int plan_groups(const std::vector<KVGroupInfo>& groups, const Config& cfg);
int64_t ceiling(int64_t ctx) const;
/* The part of every ceiling that is not context: recurrent and conv state for max_seqs
* sequences, the checkpoint slots and the padding. Set by plan_groups(). */
int64_t fixed_bytes() const { return fixed_; }
int carve(Pool& kv_pool);
const std::vector<KVGroupPlan>& plans() const { return plans_; }
+21 -7
View File
@@ -24,6 +24,15 @@ int64_t to_mib(int64_t bytes) { return bytes > 0 ? bytes / kMiB : 0; }
int64_t to_mib_up(int64_t bytes) { return bytes > 0 ? (bytes + kMiB - 1) / kMiB : 0; }
} /* namespace */
/* WHAT THE CACHE BACKS, counted on its PAGED part. The ceiling is the recurrent and conv state of
* max_seqs sequences plus their context, and the state is spent before a single token is cached --
* on a hybrid model at a few dozen sequences it is gigabytes a card. A ratio over the whole
* ceiling counts that state as context and reports full-length sessions the cache cannot hold. */
static double paged_share(const VramBudget& b) {
const double ctx = (double)(b.kv_ceiling - b.kv_fixed);
return ctx > 0 ? std::max(0.0, (double)(b.kv - b.kv_fixed)) / ctx : 0.0;
}
int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudget* out) {
VramBudget b;
if (per_rank.empty()) { if (out) *out = b; return RAD_OK; }
@@ -39,7 +48,9 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
b.capacity = std::min(b.capacity, f.capacity);
freeb = std::min(freeb, f.free);
b.arena = std::max(b.arena, f.arena);
b.staging = std::max(b.staging, f.staging);
b.kv_ceiling = std::max(b.kv_ceiling, f.kv_ceiling);
b.kv_fixed = std::max(b.kv_fixed, f.kv_fixed);
b.statics = std::max(b.statics, f.statics);
b.expert_ceiling = std::max(b.expert_ceiling, f.experts);
layer_max = std::max(layer_max, f.expert_layer_max);
@@ -72,7 +83,7 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
b.derived_kv = want_kv;
/* What is left after the terms nobody gets to spend. */
int64_t fixed = b.already_held + b.headroom + b.arena;
int64_t fixed = b.already_held + b.headroom + b.arena + b.staging;
if (!want_w) fixed += cfg.vram_weights_mib * kMiB; /* a stated pool is fixed too */
if (!want_kv) fixed += cfg.vram_kv_mib * kMiB;
b.claimable = b.capacity - fixed;
@@ -84,13 +95,14 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
" already held %10s (driver context, code objects, anything else on the card)\n"
" --gpu-headroom-mib %10s\n"
" activation arena %10s (buffer plan + kernel scratch)\n"
" step staging %10s (block tables + media staging)\n"
"%s%s"
" ------------------------------\n"
" SHORT BY %10s\n"
"Lower --gpu-headroom-mib, lower --max-num-batched-tokens (the arena scales with it), "
"or free the card.\n",
humanb(b.capacity).c_str(), humanb(b.already_held).c_str(),
humanb(b.headroom).c_str(), humanb(b.arena).c_str(),
humanb(b.headroom).c_str(), humanb(b.arena).c_str(), humanb(b.staging).c_str(),
want_w ? "" : fmt(" --vram-weights-mib %10s (stated)\n",
humanb(cfg.vram_weights_mib * kMiB).c_str()).c_str(),
want_kv ? "" : fmt(" --vram-kv-mib %10s (stated)\n",
@@ -223,9 +235,9 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
"live SESSIONS and not running requests -- when they do not all fit, the cache "
"evicts prefixes the next turn wanted and that turn re-prefills its whole "
"context. --expert-vs-cache-ratio moves it.",
100.0 * (double)b.kv / (double)b.kv_ceiling,
100.0 * paged_share(b),
(long long)cfg.max_seqs, (long long)cfg.max_ctx,
(double)cfg.max_seqs * (double)b.kv / (double)b.kv_ceiling);
(double)cfg.max_seqs * paged_share(b));
/* Rounding the floor up claims up to a MiB the split did not hand out. Take it back from the
* cache where the cache is ours to size -- a paged pool a MiB smaller addresses a handful
* fewer tokens and nothing else -- so the headroom stays whole. Where the KV budget was
@@ -240,13 +252,14 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
* line is not padding: to_mib truncates, and what it drops is real VRAM that ends up beside
* the headroom. */
const int64_t granted = cfg.vram_weights_mib * kMiB + cfg.vram_kv_mib * kMiB;
const int64_t unclaimed = b.capacity - b.already_held - b.arena - b.stage - granted;
const int64_t unclaimed = b.capacity - b.already_held - b.arena - b.staging - b.stage - granted;
const double ela = b.elastic > 0 ? (double)b.elastic : 1.0;
b.report = fmt(
"VRAM budget, per card:\n"
" card total %10s\n"
" already held %10s measured: driver context, code objects, anything else resident\n"
" activation arena %10s computed from the buffer plan\n"
" step staging %10s the step batch's block tables and media staging\n"
" %-18s %10s %s\n"
" ------------------------------\n"
" claimable %10s\n"
@@ -263,6 +276,7 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
" unclaimed %10s the headroom, the unusable above, and what MiB rounding\n"
" could not place\n",
humanb(b.capacity).c_str(), humanb(b.already_held).c_str(), humanb(b.arena).c_str(),
humanb(b.staging).c_str(),
shared ? "left to the host" : "--gpu-headroom-mib", humanb(b.headroom).c_str(),
shared ? "integrated graphics: this memory is the host's; --vram-kv-mib states a pool "
"outright"
@@ -302,9 +316,9 @@ int vram_budget_resolve(Config& cfg, const std::vector<VramFacts>& per_rank, Vra
"finished sequence's blocks stay held\n"
" for reuse, so the demand is LIVE "
"SESSIONS and not running requests",
100.0 * (double)b.kv / (double)b.kv_ceiling,
100.0 * paged_share(b),
(long long)cfg.max_seqs, (long long)cfg.max_ctx,
(double)cfg.max_seqs * (double)b.kv / (double)b.kv_ceiling).c_str()
(double)cfg.max_seqs * paged_share(b)).c_str()
: ""),
b.unusable > 0
? fmt(" unusable %10s neither side could take it: both are at their "
+5 -2
View File
@@ -60,7 +60,9 @@ struct VramFacts {
int64_t capacity = 0; /* RadDeviceProps::vram_bytes -- totalGlobalMem */
int64_t free = 0; /* RadDeviceProps::vram_free, measured now */
int64_t arena = 0; /* arena_plan_bytes() for this rank's program, total incl. scratch */
int64_t staging = 0; /* BatchBuilder::device_bytes(): the step slab and the media staging */
int64_t kv_ceiling = 0; /* KVManager::ceiling(max_ctx) for this rank's declared groups */
int64_t kv_fixed = 0; /* KVManager::fixed_bytes(): the part of the ceiling that is state */
/* weight_footprint() for this rank, which under tensor parallel is already this card's even
* share: declare runs per rank with every dimension already divided. */
int64_t statics = 0; /* non-expert weights -- the floor, not a share of anything */
@@ -75,11 +77,12 @@ struct VramFacts {
/* The resolved split, in bytes, beside every term it came from. Always filled, including when the
* operator stated the budgets -- the placement report and the pool report both want the totals. */
struct VramBudget {
int64_t capacity = 0, already_held = 0, headroom = 0, arena = 0;
int64_t claimable = 0; /* after the four fixed terms above */
int64_t capacity = 0, already_held = 0, headroom = 0, arena = 0, staging = 0;
int64_t claimable = 0; /* after the fixed terms above */
int64_t statics = 0; /* off the top, before the ratio sees anything */
int64_t elastic = 0; /* claimable - statics: what the ratio divides */
int64_t kv_ceiling = 0, expert_ceiling = 0;
int64_t kv_fixed = 0; /* the state part of kv_ceiling, which no context uses */
int64_t experts = 0, kv = 0; /* the two shares, each capped at its ceiling */
int64_t unusable = 0; /* elastic neither side could take -- both were full */
/* THE PREFILL STAGING REGION: two buffers, each one layer's share of the experts the budget
+9
View File
@@ -653,6 +653,10 @@ struct Config {
/* --api-key: the bearer key every request but the probes and the dashboard page must carry.
* Empty serves without one. */
std::string api_key;
/* --served-model-name: the id /v1/models lists, a response names when its request named none,
* and the metrics carry. Empty takes the container's own name. A request may still name any
* model: one model is loaded and every request is served by it. */
std::string served_model_name;
/* WHAT A REQUEST THAT SENDS NO SAMPLER SETTINGS IS SERVED WITH.
*
@@ -671,6 +675,11 @@ struct Config {
float sample_min_p = -1.0f;
/* An operator-supplied generation_config.json, overriding the search described above. */
std::string generation_config;
/* --override-chat-template: a Jinja file whose text replaces the chat template the container
* (or the checkpoint directory) carries. Everything that reads the template reads this one:
* the chat endpoint's rendering, and the reply format derived from it -- reasoning markers and
* tool calls. Empty serves the container's. */
std::string override_chat_template;
bool debug_graph = false;
bool debug_selection = false;
+54 -22
View File
@@ -177,7 +177,7 @@ void BatchBuilder::carve(Set& s, char* h) {
s.dev_bytes = od;
}
int BatchBuilder::alloc_set(Set& s, const std::vector<KVGroupInfo>& groups) {
void BatchBuilder::size_set(Set& s, const std::vector<KVGroupInfo>& groups) {
s.groups.resize(groups.size());
for (size_t gi = 0; gi < groups.size(); ++gi) {
const KVGeom::G& e = kvgeom_.g[gi];
@@ -192,8 +192,11 @@ int BatchBuilder::alloc_set(Set& s, const std::vector<KVGroupInfo>& groups) {
s.groups[gi].max_blocks = mb;
s.groups[gi].sidx_pitch = e.sidx_width > 0 ? e.sidx_width : 1;
}
carve(s, nullptr);
}
int BatchBuilder::alloc_set(Set& s, const std::vector<KVGroupInfo>& groups) {
size_set(s, groups);
/* ONE SLAB PER RANK, on that rank's card. rad_dev_alloc has no device argument and uses the
* current one, so the bind is part of the allocation. */
@@ -340,6 +343,43 @@ int BatchBuilder::init(Program& prog, const Config& cfg, const ChunkGeometry& ge
* buffer would have no arena to land in. */
for (const RankIO& r : ranks_)
if (!r.prog) return RAD_E_INVAL;
RAD_TRY(layout(prog, cfg));
RAD_TRY(alloc_set(set_, prog.kv_groups));
out_next_ = 0;
out_last_ = -1;
if (mm_on_) RAD_TRY(alloc_media());
/* THE RESERVATION AND WHAT ACTUALLY CROSSES ARE DIFFERENT NUMBERS, so the line says both.
* Nearly all of the slab is block-table rectangles carved for the worst step, and a step
* copies only the rows it filled -- an operator reading the reservation alone would price
* the per-step cost far above what it is. */
RAD_INFO("step batch: %s pinned staging ring + %s device slab a rank, %d KV group(s), "
"%d derived buffer(s); of the slab, %s is block tables carved for the worst step "
"and only the filled rows cross",
humanb(ring_.bytes).c_str(), humanb(set_.dev_bytes).c_str(),
(int)prog.kv_groups.size(), (int)derived_.size(),
humanb(set_.dev_bytes - set_.bt_base).c_str());
return RAD_OK;
}
/* WHAT init() WILL ALLOCATE ON EVERY RANK'S CARD, before any of it exists: the VRAM budget is
* resolved before the builder is, and a reservation it does not charge comes out of
* --gpu-headroom-mib -- the room a kernel's first launch allocates from, where running out is a
* fault inside the HIP runtime rather than an error. The slab's block tables grow with
* --max-num-seqs and the media staging with --max-num-batched-tokens, so neither is small enough
* to leave to the headroom. The same layout() and carve walk as init(), so the two cannot drift. */
int64_t BatchBuilder::device_bytes(Program& prog, const Config& cfg, const KVGeom& kvg) {
BatchBuilder b;
b.prog_ = &prog;
b.cfg_ = cfg;
b.kvgeom_ = kvg;
if (b.layout(prog, cfg) < 0) return -1;
b.size_set(b.set_, prog.kv_groups);
const MediaBytes m = b.mm_on_ ? b.media_bytes() : MediaBytes{};
return b.set_.dev_bytes + m.mm + m.pix + m.crd + m.cu;
}
int BatchBuilder::layout(Program& prog, const Config& cfg) {
max_tok_ = cfg.max_tok;
max_seqs_ = cfg.max_seqs;
@@ -456,36 +496,28 @@ int BatchBuilder::init(Program& prog, const Config& cfg, const ChunkGeometry& ge
});
mm_on_ = prog.encoder.modalities != 0;
RAD_TRY(alloc_set(set_, prog.kv_groups));
out_next_ = 0;
out_last_ = -1;
if (mm_on_) RAD_TRY(alloc_media());
/* THE RESERVATION AND WHAT ACTUALLY CROSSES ARE DIFFERENT NUMBERS, so the line says both.
* Nearly all of the slab is block-table rectangles carved for the worst step, and a step
* copies only the rows it filled -- an operator reading the reservation alone would price
* the per-step cost far above what it is. */
RAD_INFO("step batch: %s pinned staging ring + %s device slab a rank, %d KV group(s), "
"%d derived buffer(s); of the slab, %s is block tables carved for the worst step "
"and only the filled rows cross",
humanb(ring_.bytes).c_str(), humanb(set_.dev_bytes).c_str(),
(int)prog.kv_groups.size(), (int)derived_.size(),
humanb(set_.dev_bytes - set_.bt_base).c_str());
return RAD_OK;
}
/* ------------------------------------------------------------------ media staging */
int BatchBuilder::alloc_media() {
BatchBuilder::MediaBytes BatchBuilder::media_bytes() {
const RadEncoderDecl& e = prog_->encoder;
n_embd_ = e.n_embd;
enc_patches_ = e.max_patches;
enc_dim_ = e.patch_dim;
/* The most segments one pass can hold: a segment is at least one output row, `merge` patches. */
enc_segs_ = e.max_patches / (e.merge > 0 ? e.merge : 1) + 1;
const int64_t mm_bytes = max_tok_ * n_embd_ * (int64_t)sizeof(uint16_t);
const int64_t pix_bytes = enc_patches_ * enc_dim_ * (int64_t)sizeof(uint16_t);
const int64_t crd_bytes = 4 * enc_patches_ * (int64_t)sizeof(int32_t);
const int64_t cu_bytes = (enc_segs_ + 1) * (int64_t)sizeof(int32_t);
MediaBytes m;
m.mm = max_tok_ * n_embd_ * (int64_t)sizeof(uint16_t);
m.pix = enc_patches_ * enc_dim_ * (int64_t)sizeof(uint16_t);
m.crd = 4 * enc_patches_ * (int64_t)sizeof(int32_t);
m.cu = (enc_segs_ + 1) * (int64_t)sizeof(int32_t);
return m;
}
int BatchBuilder::alloc_media() {
const MediaBytes m = media_bytes();
const int64_t mm_bytes = m.mm, pix_bytes = m.pix, crd_bytes = m.crd, cu_bytes = m.cu;
mm_dev_.assign(ranks_.size(), nullptr);
enc_pix_dev_.assign(ranks_.size(), nullptr);
enc_coord_dev_.assign(ranks_.size(), nullptr);
+11
View File
@@ -132,6 +132,11 @@ public:
const KVGeom& kvg, const std::vector<RankIO>& ranks);
void fini();
/* The bytes init() allocates on each rank's card -- the step slab and, with an encoder, the
* media staging -- computed without allocating, for the VRAM budget. -1 when the program is
* one init() would refuse. */
static int64_t device_bytes(Program& prog, const Config& cfg, const KVGeom& kvg);
/* Build the batch for this step. The returned pointer is stable until the kOut-th next call
* and is the pointer the rank threads share -- because the ranks share an address space, the
* batch is shared by pointer rather than broadcast (spec §1). Null on a device failure, which
@@ -365,6 +370,8 @@ private:
int32_t* enc_coord_host_ = nullptr;
int32_t* enc_cu_host_ = nullptr;
int64_t last_n_tok_ = 0;
struct MediaBytes { int64_t mm = 0, pix = 0, crd = 0, cu = 0; };
MediaBytes media_bytes(); /* the four device regions alloc_media reserves, per rank */
int alloc_media();
void free_media();
/* The encoder rows of one entry: the media tokens among its positions, their rows copied into
@@ -372,6 +379,10 @@ private:
int64_t stage_mm_rows(const StepEntry& e, int64_t k, int64_t shift, int64_t n_rows,
int32_t* rows);
/* The members init() derives from the program and the config, allocating nothing. */
int layout(Program& prog, const Config& cfg);
/* The set's groups and its carve with no base: dev_bytes and host_bytes, nothing reserved. */
void size_set(Set& s, const std::vector<KVGroupInfo>& groups);
int alloc_set(Set& s, const std::vector<KVGroupInfo>& groups);
void free_set(Set& s);
/* Point every h_* at host staging based at `base`, and every d_* at rank 0's slab. */
+6
View File
@@ -640,6 +640,12 @@ int chat_format_grammar(const ChatFormat& f, const ChatGrammarRequest& req, Chat
std::vector<G> req_arms, opt_arms;
for (const auto& [pname, pschema] : properties.items()) {
/* An optional argument no value satisfies -- `false`, or `{"not": {}}`, an
* Arktype or TypeBox `never` -- is one no call writes, so it gets no arm; a
* model that writes it anyway reaches the undeclared arm below. The template
* path does the same (vendor/patches/0012); required, it goes through the
* schema and is refused there by name. */
if (!required.count(pname) && info.unsatisfiable(pschema)) continue;
G value;
if (f.other_value != ChatValue::Json || info.resolves_to_string(pschema)) {
value = wrap(rule_ref("until-suffix"));