Merge branch 'f-132-pr' into rel-0.1.32
# Conflicts: # CMakeLists.txt # serve/server.py # src/program/generate.cpp
This commit is contained in:
commit
b0abdeb446
68 files changed
+4262
-403
No files matched your search
+152
-17
@@ -18,6 +18,7 @@
|
||||
#include "strata/core/expert_cache.hpp"
|
||||
#include "strata/core/conversation_snapshot.hpp"
|
||||
#include "strata/core/conversation_memory.hpp"
|
||||
#include "strata/core/coupled_draft.hpp"
|
||||
#include "strata/core/expert_source.hpp"
|
||||
#include "strata/core/pinned.hpp"
|
||||
#include "strata/core/remote_experts.hpp"
|
||||
@@ -55,6 +56,8 @@
|
||||
#include "strata/spec/suffix_drafter.hpp"
|
||||
#include "strata/kernels/cvec.hpp"
|
||||
#include "strata/core/progress.hpp"
|
||||
#include "strata/core/device.hpp"
|
||||
#include "strata/core/emulate.hpp"
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // gguf_reader.hpp includes windows.h
|
||||
#endif
|
||||
@@ -213,6 +216,8 @@ struct Options {
|
||||
/// combination recorded in bench/results/2026-09-23-attention-ple plus the native indexer, and never the
|
||||
/// <=256-token attention adapter. It becomes the default once P0 shows it is not slower.
|
||||
std::string native_preset;
|
||||
/// The token embedding from this GGUF instead of --native's (tools/embd_bf16_pack.py: BF16 as shipped)
|
||||
std::string embd_gguf;
|
||||
/// Plan v0.3 P2: how the n-gram table is read. Direct (default) = unbuffered SSD reads, table never in RAM.
|
||||
std::string ple_io = "direct";
|
||||
int64_t ple_row_cache = 1 << 20; ///< bounded row cache (rows of 90 B); 0 disables
|
||||
@@ -251,10 +256,13 @@ struct Options {
|
||||
bool graph_only = false;
|
||||
bool gpu_only_full = false; ///< R0.3: pre + post + head, the true per-token GPU floor
|
||||
int pool_workers = 0; ///< R2.2: 0 = "all physical cores minus the host's"; >0 overrides
|
||||
/// #272: the pool's core layout; `all` (the default) is the layout it always had, auto / p-cores are opt-in
|
||||
strata::kernels::cpu::PoolAffinity pool_affinity = strata::kernels::cpu::PoolAffinity::All;
|
||||
/// R2.2's first half, as an A/B arm. **ON by default**, because the measurement that justifies it is the
|
||||
/// pool's own drain: 33.7 GB/s against 5/6 x 44.14 = 36.8 for five workers, on a machine whose sixth core
|
||||
/// is reserved for a host thread that has nothing to do while the drain runs.
|
||||
bool no_host_worker = false;
|
||||
bool coupled_draft = strata::core::coupled_draft_env(); ///< Coupled draft sampling for MTP drafter under sampling
|
||||
bool mmap_experts = false; ///< R2.1: opt OUT of the resident arena, back to MapViewOfFile
|
||||
std::string shared_expert_arena; ///< Linux: optional file backing for the resident arena shared by processes
|
||||
bool resident_cpu_experts = false; ///< mmap-backed static-cache misses copied into ordinary RAM
|
||||
@@ -318,6 +326,9 @@ struct Options {
|
||||
/// `--prefill auto`: the largest chunk (up to 8192) whose buffers the expert cache can lend. Every expert a chunk
|
||||
/// routes to is streamed once per chunk, so a bigger chunk streams fewer bytes per token (the "ubatch" effect).
|
||||
bool prefill_auto = false;
|
||||
/// #282, opt-in: the largest chunk `--prefill auto` may take - 8192 by default; `--prefill auto:16384` or
|
||||
/// `auto:32768` (or STRATA_PREFILL_AUTO_MAX) lets it go further, never past the context
|
||||
int64_t prefill_auto_max = 8192;
|
||||
bool no_split_rows = false; ///< plan v0.3 P4 A/B: one whole expert per pool thread
|
||||
/// Plan v0.3 P5: the prompt path borrows the top expert-cache slots for its buffers and refills them after
|
||||
/// the prompt (default); `--no-prefill-borrow` reserves the buffers' VRAM for the whole session instead.
|
||||
@@ -449,6 +460,8 @@ void usage() {
|
||||
" indexer, RoPE, PLE postops, and the CPU q8_0 contract unless the\n"
|
||||
" expert cache is on. Individual --native-* flags stay for A/B.\n"
|
||||
" --native-head-gguf PATH native Q5_K head from model shard 1; requires --stream-token\n"
|
||||
" --embd-gguf PATH the token embedding from this GGUF instead of --native's (tools/embd_bf16_pack.py:\n"
|
||||
" BF16 as the checkpoint ships it; mapped host memory, no VRAM)\n"
|
||||
" --native-dense-gguf PATH native GDN/QSA/shared projections; repeat for each source model shard\n"
|
||||
" --expert-cache-cpu-order experimental GPU expert reduction matching CPU order\n"
|
||||
" --max-new N tokens to generate (default 16)\n"
|
||||
@@ -497,7 +510,8 @@ void usage() {
|
||||
" --no-token-graph A/B: two graphs per layer (the host launches each) instead of one per token\n"
|
||||
" --no-fused-gr A/B: the six-kernel hyper-connection read and a separate write (native)\n"
|
||||
" --prefill CHUNK batched prompt processing in chunks of CHUNK tokens (needs --native); auto =\n"
|
||||
" the largest chunk up to 8192 whose buffers the expert cache can lend\n"
|
||||
" the largest chunk up to 8192 whose buffers the expert cache can lend;\n"
|
||||
" auto:16384 / auto:32768 (or STRATA_PREFILL_AUTO_MAX) allow bigger ones\n"
|
||||
" --no-pool skip the CPU expert pool (the GPU-only floor)\n"
|
||||
" --sync-every-layer debug: synchronise after every layer\n"
|
||||
" --ple-gguf PATH the n-gram/PLE shard. WITHOUT IT LAYER 1's PLE IS SILENTLY SKIPPED,\n"
|
||||
@@ -538,8 +552,14 @@ void usage() {
|
||||
" pool is six threads on six cores instead of five plus an idle core;\n"
|
||||
" this flag restores the five-worker form for comparison on `pool phases`.\n"
|
||||
" --pool-workers N R2.2: CPU expert pool worker count. Default 0 = every physical core\n"
|
||||
" except the one the host loop spins on. A sweep is how the pool's\n"
|
||||
" except the one the host loop spins on (with --pool-affinity auto or\n"
|
||||
" p-cores on a hybrid CPU: P-cores minus 1). A sweep is how the pool's\n"
|
||||
" deviation from `cpu_s2` is attributed.\n"
|
||||
" --pool-affinity MODE Worker CPU affinity: all (default: one worker per physical core, as\n"
|
||||
" always), auto (hybrid CPUs: P-cores first, then their SMT siblings,\n"
|
||||
" then E-cores) or p-cores (P-cores and their siblings only).\n"
|
||||
" --coupled-draft enable coupled draft sampling for MTP drafter under sampling (STRATA_SPEC_COUPLED)\n"
|
||||
" --no-coupled-draft disable coupled draft sampling (propose argmax drafts)\n"
|
||||
" --mmap-experts R2.1: opt OUT of the resident expert arena, back to MapViewOfFile.\n"
|
||||
" The A/B arm: the mmap's rate depends on the OS page cache holding\n"
|
||||
" 34 GB, and measured 71.97 vs 34.78 ms/token cold vs warm.\n"
|
||||
@@ -1058,6 +1078,7 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--cpu-oracle-q8-0") o.cpu_oracle_q8_0 = true;
|
||||
else if (a == "--native") o.native_preset = next("--native");
|
||||
else if (a == "--native-head-gguf") o.native_head_gguf = next("--native-head-gguf");
|
||||
else if (a == "--embd-gguf") o.embd_gguf = next("--embd-gguf");
|
||||
else if (a == "--native-dense-gguf") o.native_dense_gguf.push_back(next("--native-dense-gguf"));
|
||||
else if (a == "--no-capture") o.no_capture = true;
|
||||
else if (a == "--no-pool") o.no_pool = true;
|
||||
@@ -1066,8 +1087,20 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--graph-only") o.graph_only = true;
|
||||
else if (a == "--gpu-only-full") o.gpu_only_full = true;
|
||||
else if (a == "--pool-workers") o.pool_workers = std::atoi(next("--pool-workers"));
|
||||
else if (a == "--pool-affinity") {
|
||||
const std::string v = next("--pool-affinity");
|
||||
if (v == "auto") o.pool_affinity = strata::kernels::cpu::PoolAffinity::Auto;
|
||||
else if (v == "p-cores" || v == "pcores") o.pool_affinity = strata::kernels::cpu::PoolAffinity::PCores;
|
||||
else if (v == "all") o.pool_affinity = strata::kernels::cpu::PoolAffinity::All;
|
||||
else {
|
||||
std::fprintf(stderr, "strata generate: unknown --pool-affinity value '%s' (expected auto, p-cores, or all)\n", v.c_str());
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (a == "--no-host-worker") o.no_host_worker = true;
|
||||
else if (a == "--no-ple-prefetch") o.no_ple_prefetch = true;
|
||||
else if (a == "--coupled-draft") o.coupled_draft = true;
|
||||
else if (a == "--no-coupled-draft") o.coupled_draft = false;
|
||||
else parsed = false;
|
||||
// The chain continues here in a second statement: one chain of 120+ `else if` passed MSVC's limit of 128
|
||||
// nested blocks (C1061). The order of the tests and what each does are unchanged.
|
||||
@@ -1084,8 +1117,13 @@ int main(int argc, char** argv) {
|
||||
else if (a == "--vram-reserve-mib") o.vram_reserve_mib = std::atoi(next("--vram-reserve-mib"));
|
||||
else if (a == "--prefill") {
|
||||
const std::string v = next("--prefill");
|
||||
o.prefill_auto = v == "auto";
|
||||
o.prefill_chunk = o.prefill_auto ? 8192 : std::atoll(v.c_str());
|
||||
o.prefill_auto = v == "auto" || v.rfind("auto:", 0) == 0;
|
||||
// #282: auto:N (N = 16384 or 32768) or STRATA_PREFILL_AUTO_MAX lets auto take chunks above 8192
|
||||
const char* env_max = std::getenv("STRATA_PREFILL_AUTO_MAX");
|
||||
const long long want_max = v.rfind("auto:", 0) == 0 ? std::atoll(v.c_str() + 5)
|
||||
: (o.prefill_auto && env_max != nullptr ? std::atoll(env_max) : 8192);
|
||||
o.prefill_auto_max = want_max >= 32768 ? 32768 : want_max >= 16384 ? 16384 : 8192;
|
||||
o.prefill_chunk = o.prefill_auto ? o.prefill_auto_max : std::atoll(v.c_str());
|
||||
}
|
||||
else if (a == "--no-split-rows") o.no_split_rows = true;
|
||||
else if (a == "--no-prefill-borrow") o.no_prefill_borrow = true;
|
||||
@@ -1214,6 +1252,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
strata::core::set_coupled_draft(o.coupled_draft);
|
||||
if (o.serve && o.conversation_cache_mib > 0 && (o.prompt_cache == 0 || o.conversation_cache_slots == 0))
|
||||
std::fprintf(stderr, "strata serve: warning: conversation caching is disabled by %s\n",
|
||||
o.prompt_cache == 0 ? "--prompt-cache 0" : "--conversation-cache-slots 0");
|
||||
@@ -1420,6 +1459,12 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::core::qsa_set_kv_int8(o.kv == "int8");
|
||||
strata::core::qsa_set_kv_q4(o.kv == "q4_0"); // PR #21: 4-bit codes after a Hadamard rotation (kv_q4.hpp)
|
||||
// STRATA_KV_ROT=1: INT8 K/V through the Hadamard rotation --kv q4_0 already uses. Opt-in: first-token KL to
|
||||
// fp16 K/V improved on an NVFP4 pack (0.0066 -> 0.0051) but not on IQ2_XS (0.0022 -> 0.0054)
|
||||
const char* kv_rot = std::getenv("STRATA_KV_ROT");
|
||||
strata::core::qsa_set_kv_int8_rotate(kv_rot != nullptr && kv_rot[0] == '1');
|
||||
if (kv_rot != nullptr && kv_rot[0] == '1' && o.kv == "int8")
|
||||
std::fprintf(stderr, "strata generate: STRATA_KV_ROT=1: INT8 K/V through the Hadamard rotation (opt-in)\n");
|
||||
strata::core::qsa_set_kv_hybrid(o.kv == "k8v4"); // K8V4: INT8 K + rotated Q4_0 V, 816 B/cell
|
||||
if (o.kv_resident < 0) {
|
||||
std::fprintf(stderr, "strata generate: --kv-resident must be >= 0\n");
|
||||
@@ -1469,7 +1514,14 @@ int main(int argc, char** argv) {
|
||||
// every shard of the model (<name>-0000N-of-0000M.gguf beside --native), then the PLE shard: a split
|
||||
// may put any layer in any shard (Swift's GGUFs: layers 13-47 in shard 2, the PLE table in shard 1)
|
||||
o.native_dense_gguf = o.native_shards;
|
||||
if (std::find(o.native_dense_gguf.begin(), o.native_dense_gguf.end(), o.ple_gguf) == o.native_dense_gguf.end())
|
||||
// a PLE-only table (tools/ple_fp8_pack.py: architecture strata-ple) holds no projections
|
||||
bool ple_only = false;
|
||||
try {
|
||||
strata::GgufFile pg(o.ple_gguf);
|
||||
if (const strata::MetaValue* v = pg.get("general.architecture")) ple_only = v->s == "strata-ple";
|
||||
} catch (const std::exception&) {}
|
||||
if (!ple_only &&
|
||||
std::find(o.native_dense_gguf.begin(), o.native_dense_gguf.end(), o.ple_gguf) == o.native_dense_gguf.end())
|
||||
o.native_dense_gguf.push_back(o.ple_gguf);
|
||||
}
|
||||
// Plan v0.3 (24 Sep): the CPU experts stay on the VNNI kernel. The llama.cpp-CPU-exact q8_0 contract
|
||||
@@ -1788,15 +1840,16 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
const strata::core::ModelGeometry g0;
|
||||
if (!native_embed.load(o.native_shards, g0.n_embd, 248320, err)) {
|
||||
if (!native_embed.load(o.embd_gguf.empty() ? o.native_shards : std::vector<std::string>{o.embd_gguf}, g0.n_embd,
|
||||
248320, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
strata::core::set_native_embed(&native_embed);
|
||||
std::fprintf(stderr, "strata generate: native pack: %s experts (largest blob %.2f MB), token embedding "
|
||||
"type %d in mapped host memory (%.0f MiB)\n",
|
||||
"%s in mapped host memory (%.0f MiB)\n",
|
||||
o.pack.c_str(), (double) strata::kernels::cpu::expert_layout().max_blob / 1e6,
|
||||
native_embed.type(), (double) native_embed.bytes() / 1048576.0);
|
||||
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0);
|
||||
}
|
||||
// Plan v0.3 P1: tensors served in native form are not also loaded in canonical form (~2.7 GB of VRAM back
|
||||
// to the expert cache with --native). `--keep-canonical` loads both, as before.
|
||||
@@ -1965,6 +2018,17 @@ int main(int argc, char** argv) {
|
||||
pio.max_inflight = (uint32_t) o.ple_inflight;
|
||||
pio.cache_rows = (uint64_t) o.ple_row_cache;
|
||||
pio.io_thread = !o.ple_sync_submit;
|
||||
// Keep the SSD awake while rows are being asked for (PleReader::set_keepalive): some SSDs stall the first
|
||||
// reads 50-150 ms after ~250 ms without a command. STRATA_SSD_KEEPALIVE = ms without a read before one
|
||||
// page is read anyway (default 100, 0 = off), STRATA_SSD_KEEPALIVE_WINDOW = seconds after the last row
|
||||
// request that this goes on (default 60; then the SSD may sleep until the next request).
|
||||
{
|
||||
const char* ka = std::getenv("STRATA_SSD_KEEPALIVE");
|
||||
const char* kw = std::getenv("STRATA_SSD_KEEPALIVE_WINDOW");
|
||||
pio.keepalive_ms = ka != nullptr && *ka ? std::clamp(std::atof(ka), 0.0, 10000.0) : 100.0;
|
||||
pio.keepalive_window_s = kw != nullptr && *kw ? std::clamp(std::atof(kw), 1.0, 86400.0) : 60.0;
|
||||
if (pio.mode != strata::kernels::PleIo::Direct || !pio.io_thread) pio.keepalive_ms = 0;
|
||||
}
|
||||
if (!ple_table.open(o.ple_gguf, err, pio)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
@@ -1973,6 +2037,12 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: PLE table %s (--ple-io ram) in %.1f s\n",
|
||||
ple_table.locked() ? "locked in RAM" : "loaded (not locked)",
|
||||
std::chrono::duration<double>(Clock::now() - tpl).count());
|
||||
if (pio.keepalive_ms > 0)
|
||||
std::fprintf(stderr, "strata generate: the SSD is kept awake while rows are read: one page of the table after "
|
||||
"%.0f ms without a read, until %.0f s after the last request "
|
||||
"(STRATA_SSD_KEEPALIVE=0 turns it off)\n", pio.keepalive_ms, pio.keepalive_window_s);
|
||||
else if (pio.mode == strata::kernels::PleIo::Direct)
|
||||
std::fprintf(stderr, "strata generate: SSD keep-alive off: the SSD may fall asleep between reads\n");
|
||||
const strata::core::WeightRef* wk = wt.find("blk.1.ple_key.weight");
|
||||
const strata::core::WeightRef* wv = wt.find("blk.1.ple_value.weight");
|
||||
const strata::core::WeightRef* wnk = wt.find("blk.1.ple_norm_key.weight");
|
||||
@@ -2096,6 +2166,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
strata::core::Verifier::set_commit_async(!multi_gpu); // see Verifier::set_commit_async
|
||||
// ---- layer split across GPUs: each later stage's own copy of the dense weights, its session and (the last) the
|
||||
// head, made on its device before the host arena is mapped (as the drafter below, for the same WDDM reason)
|
||||
std::vector<std::unique_ptr<GpuStage>> stages;
|
||||
@@ -2461,6 +2532,27 @@ int main(int argc, char** argv) {
|
||||
// CUDA error left set by the failed `cudaHostRegister` and read later by `gr_read`'s launch check. See the
|
||||
// note in `pinned.cu`.
|
||||
strata::core::FileExpertSource src;
|
||||
{ // the card, and whether this build has code for it (a binary built for other GPUs fails at its first kernel
|
||||
// otherwise, after the whole expert arena has loaded) - before the arena starts loading
|
||||
int dev = 0;
|
||||
cudaDeviceProp p{};
|
||||
const bool named = cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&p, dev) == cudaSuccess;
|
||||
if (!named) cudaGetLastError();
|
||||
const char* name = named && p.name[0] ? p.name : "(an unnamed GPU)";
|
||||
#if defined(STRATA_USE_HIP)
|
||||
std::fprintf(stderr, "strata generate: GPU %d: %s (%s)\n", dev, name, named ? p.gcnArchName : "?");
|
||||
#else
|
||||
std::fprintf(stderr, "strata generate: GPU %d: %s, compute capability %d.%d%s\n", dev, name,
|
||||
strata::cc_major_of(p.major), strata::cc_minor_of(p.minor),
|
||||
strata::emulated_cc() ? " (STRATA_EMULATE_CC: a test mode, the card is emulated)" : "");
|
||||
#endif
|
||||
const std::string e = strata::core::device_code_error();
|
||||
if (!e.empty()) {
|
||||
std::fprintf(stderr, "strata generate: this engine has no code for %s (sm_%d%d): %s - rebuild it for this "
|
||||
"card (setup does: START-HERE.bat --setup)\n", name, p.major, p.minor, e.c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
strata::core::ArenaExpertSource arena_src;
|
||||
strata::core::ExpertSource* srcp = nullptr;
|
||||
if (o.mmap_experts) {
|
||||
@@ -2522,7 +2614,13 @@ int main(int argc, char** argv) {
|
||||
#endif
|
||||
srcp = &arena_src;
|
||||
}
|
||||
strata::kernels::cpu::ExpertPool pool(o.pool_workers, /*pin=*/true, /*host_works=*/!o.no_host_worker);
|
||||
strata::kernels::cpu::ExpertPool pool(o.pool_workers, /*pin=*/true, /*host_works=*/!o.no_host_worker, o.pool_affinity);
|
||||
if (pool.is_hybrid() && pool.affinity() != strata::kernels::cpu::PoolAffinity::All) {
|
||||
const char* aff_str = pool.affinity() == strata::kernels::cpu::PoolAffinity::PCores ? "p-cores" :
|
||||
pool.affinity() == strata::kernels::cpu::PoolAffinity::All ? "all" : "auto";
|
||||
std::fprintf(stderr, "strata generate: hybrid CPU detected (%d P-cores / %d threads, %d E-cores), pool workers: %d, affinity: %s\n",
|
||||
pool.p_cores(), pool.p_threads(), pool.e_cores(), pool.workers(), aff_str);
|
||||
}
|
||||
if (o.no_ple_prefetch) strata::kernels::ple_prefetch_enable(false);
|
||||
// ---- R4's slot storage. Allocated AFTER the weights and the session, so `cudaMemGetInfo` inside `open`
|
||||
// sees the memory this process actually has left rather than the card's idle figure - and refuses with both
|
||||
@@ -3625,10 +3723,15 @@ int main(int argc, char** argv) {
|
||||
: (int64_t) (strata::prefill::Prefill::pinned_share() >= 0.9 ? 90 : 85);
|
||||
}();
|
||||
auto plan_lend = [&](int64_t& chunk) -> int64_t {
|
||||
static constexpr int64_t kAutoChunks[] = {8192, 6144, 4096, 3072, 2048, 1024, 512, 256};
|
||||
// 32768 and 16384 (#282, opt-in: --prefill auto:32768): a 32K prompt with IQ2_XS (RTX 5090, 64K context)
|
||||
// read at 5,624 tok/s in 8192-token chunks and 6,465 in one 32768 chunk (40K -> 18K experts streamed; an
|
||||
// NVFP4 pack at 262K: 3,535 -> 5,201)
|
||||
static constexpr int64_t kAutoChunks[] = {32768, 16384, 8192, 6144, 4096, 3072, 2048, 1024, 512, 256};
|
||||
auto slots_for = lend_slots;
|
||||
if (o.prefill_auto) {
|
||||
for (const int64_t c : kAutoChunks) {
|
||||
// above 8192: only when asked for, and only when a prompt of the context can use it
|
||||
if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue;
|
||||
const int64_t k = slots_for(c);
|
||||
if (k + 128 <= xcache.slots() && k * 100 <= kAutoLendPct * xcache.slots()) { chunk = c; return k; }
|
||||
}
|
||||
@@ -3763,11 +3866,13 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
return true;
|
||||
};
|
||||
static constexpr int64_t kAutoChunks[] = {8192, 6144, 4096, 3072, 2048, 1024, 512, 256};
|
||||
static constexpr int64_t kAutoChunks[] = {32768, 16384, 8192, 6144, 4096, 3072, 2048, 1024, 512, 256};
|
||||
int64_t chunk = 0;
|
||||
if (o.prefill_auto) {
|
||||
for (const int64_t c : kAutoChunks)
|
||||
for (const int64_t c : kAutoChunks) {
|
||||
if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue; // #282, as plan_lend
|
||||
if (fits(c, true)) { chunk = c; break; }
|
||||
}
|
||||
} else {
|
||||
for (int64_t c = o.prefill_chunk; c >= 256; c /= 2)
|
||||
if (fits(c, false)) { chunk = c; break; }
|
||||
@@ -4127,11 +4232,12 @@ int main(int argc, char** argv) {
|
||||
estimate = fresh_estimate;
|
||||
err.clear();
|
||||
}
|
||||
if (!reuse.kv.empty() && !conversations.can_fit(estimate, held)) {
|
||||
// Optional growth capacity must not evict useful conversations.
|
||||
reuse = {};
|
||||
estimate = fresh_estimate;
|
||||
}
|
||||
// A park carrying its own retained K/V replaces memory the cache
|
||||
// already held, so capacity is make_room's call - it runs next either
|
||||
// way, and put()'s accounting still bounds the budget. The with-reuse
|
||||
// estimate must stay uncapped: it counts the retained buffers'
|
||||
// capacity and directories, and put() charges that same true size -
|
||||
// a capped figure would under-evict and overfill the budget.
|
||||
// #342: before make_room evicts oldest-first, the copies of this conversation a turn back go (they hold
|
||||
// nothing the outgoing chain does not, apart from the tail this conversation rewrote)
|
||||
if (const size_t dropped = conversations.drop_superseded(live, live_imgs, checks, cvec_cached))
|
||||
@@ -4732,6 +4838,13 @@ int main(int argc, char** argv) {
|
||||
return imgs_below(req_imgs, L) == pre_imgs;
|
||||
};
|
||||
const bool want_cvec = strata::kernels::cvec().loaded() ? req_cvec != 0 : true;
|
||||
// the last request's final commit may still be running on the verifier's stream (set_commit_async):
|
||||
// everything below reads, restores or zeroes the session from other streams and the host (the end of the
|
||||
// last request waited already; this covers a request that ended on an error path)
|
||||
if (!ver.wait_commit(err)) {
|
||||
std::printf("ERR %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
int64_t resume = 0;
|
||||
bool from_live = false;
|
||||
if (o.prompt_cache > 0 && want_cvec == cvec_cached) {
|
||||
@@ -4923,6 +5036,8 @@ int main(int argc, char** argv) {
|
||||
if (!ver.commit(T, e) || !mtp.prefill(ver.final_R_all(), nxt.data(), T, q, e)) return false;
|
||||
q += T;
|
||||
}
|
||||
// the batched prompt path (other streams), checkpoints and snapshots may follow: the last commit first
|
||||
if (!ver.wait_commit(e)) return false;
|
||||
const double ms = std::chrono::duration<double, std::milli>(Clock::now() - pp_t0).count();
|
||||
std::printf("PP %lld %lld %.0f %.1f\n", (long long) b, (long long) pp_total, ms,
|
||||
ms > 0.0 ? 1000.0 * (double) (b - pp_from) / ms : 0.0);
|
||||
@@ -5281,6 +5396,11 @@ int main(int argc, char** argv) {
|
||||
p += a + 1;
|
||||
}
|
||||
const double decode_ms = std::chrono::duration<double, std::milli>(Clock::now() - d0).count();
|
||||
// the last commit (set_commit_async): the session is complete before anything reads or copies it
|
||||
if (!ver.wait_commit(err)) {
|
||||
std::printf("ERR %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
if (dec_timing && dec_windows > 0) {
|
||||
const DecSnap d1 = dec_snap();
|
||||
const double w = (double) dec_windows, L = (double) g.n_layers;
|
||||
@@ -6028,6 +6148,16 @@ int main(int argc, char** argv) {
|
||||
if (first_window) {
|
||||
first_window = false;
|
||||
ttft_ms = std::chrono::duration<double, std::milli>(Clock::now() - t_start).count();
|
||||
// Diagnostics: the first window runs the prompt's last token over the state the prompt path left
|
||||
// (keys, values, recurrent state), so its logits carry whatever that path did. A native pack never
|
||||
// runs the per-token loop --dump-logits reads; this is where prompt paths can be compared by output.
|
||||
if (const char* fl = std::getenv("STRATA_DUMP_FIRST_LOGITS")) {
|
||||
std::vector<float> row((size_t) ver.vocab());
|
||||
std::FILE* f = ver.copy_logits(0, row.data()) ? std::fopen(fl, "wb") : nullptr;
|
||||
if (f == nullptr || std::fwrite(row.data(), sizeof(float), row.size(), f) != row.size())
|
||||
std::fprintf(stderr, "strata generate: STRATA_DUMP_FIRST_LOGITS: cannot write %s\n", fl);
|
||||
if (f) std::fclose(f);
|
||||
}
|
||||
}
|
||||
// plan v0.3 P6: the adaptive tier's host work (ranking, copy submission) runs on its own thread while the
|
||||
// GPU commits and drafts; it touches only the residency tables, which nothing reads until the next window
|
||||
@@ -6073,6 +6203,11 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: position %lld, %lld tokens, %lld rounds\n", (long long) p,
|
||||
(long long) produced.size(), (long long) rounds);
|
||||
}
|
||||
// the last commit (set_commit_async) before anything reads the session again
|
||||
if (!ver.wait_commit(err)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("%-24s %lld rounds of %d, drafts accepted %lld of %lld (%.3f), %.2f tokens per round\n",
|
||||
"speculation", (long long) rounds, o.spec, (long long) drafts_ok, (long long) drafts_total,
|
||||
drafts_total > 0 ? (double) drafts_ok / (double) drafts_total : 0.0,
|
||||
|
||||
Reference in new issue
Block a user