Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Merge f-189 (PR #189, the conversation snapshot core and RAM cache) into rel-0.1.30
Niko1221abbf12caf563
diff --cc src/program/generate.cppindex bfc19202f,2afd05912..3880ba323--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@@ -805,35 -727,21 +804,23 @@@ uint64_t fnv1a(const void* data, size_return h;}- struct ConvStateSizes {- size_t gdn = 0, ple = 0, tail = 0;- };+ using ConvStateSizes = strata::core::ConversationStateSizes;-ConvStateSizes conv_state_sizes(const strata::core::ModelGeometry& g) {+ConvStateSizes conv_state_sizes(const strata::core::ModelGeometry& g, const strata::core::SessionState& ss) {ConvStateSizes z;+ std::string error;+ strata::core::conversation_state_sizes(g, z, error); // geometry has already passed engine validation+ // a split stage's session owns only its layer range's state (see SessionState's carve note)- z.gdn = (size_t) ss.gdn_alloc *- ((size_t) g.ssm_state_size * (size_t) g.ssm_v_heads * (size_t) g.ssm_state_size +- (size_t) g.ssm_conv_channels * (size_t) (g.ssm_d_conv - 1)) * sizeof(float);- z.ple = (size_t) strata::kernels::NG_HIST * (size_t) strata::kernels::NG_HC_DIM * sizeof(float);- z.tail = (size_t) (strata::kernels::qsa_real_shapes().idx_block - 1) * (size_t) g.idx_key_dim * sizeof(float);++ if (g.n_gdn_layers() > 0) z.gdn = z.gdn / (size_t) g.n_gdn_layers() * (size_t) ss.gdn_alloc;return z;}--/// Copies the running state out. The caller has synchronized the device.++/// Copies the running state out (this session's carve only). The caller has synchronized the device.bool checkpoint_save(ConvCheckpoint& c, const strata::core::SessionState& ss, const strata::core::ModelGeometry& g) {- const ConvStateSizes z = conv_state_sizes(g, ss);- c.gdn.resize(z.gdn);- c.ple.resize(ss.ple_hist != nullptr ? z.ple : 0);- c.tails.resize(z.tail * (size_t) ss.qsa_alloc);- if (cudaMemcpy(c.gdn.data(), ss.gdn_state, z.gdn, cudaMemcpyDeviceToHost) != cudaSuccess) return false;- if (!c.ple.empty() && cudaMemcpy(c.ple.data(), ss.ple_hist, z.ple, cudaMemcpyDeviceToHost) != cudaSuccess)- return false;- for (int64_t j = 0; j < ss.qsa_alloc; ++j)- if (cudaMemcpy(c.tails.data() + (size_t) j * z.tail, ss.qsa_states[ss.qsa_ord0 + j].idx_tail, z.tail,- cudaMemcpyDeviceToHost) != cudaSuccess)- return false;- return true;+ std::string error;+ if (strata::core::conversation_checkpoint_save(c, ss, g, error)) return true;+ std::fprintf(stderr, "strata serve: checkpoint save: %s\n", error.c_str()); // the caller's ERR has no reason+ return false;}/// Puts a checkpoint's running state back; the positional cells below it are the caller's to guarantee.@@@ -1112,6 -996,20 +1089,20 @@@ int main(int argc, char** argv)else if (a == "--serve") o.serve = true;else if (a == "--vision") o.vision = true;else if (a == "--prompt-cache") o.prompt_cache = std::max(0, std::atoi(next("--prompt-cache")));+ else if (a == "--conversation-cache-mib" || a == "--conversation-cache-slots" ||+ a == "--conversation-cache-min-free-mib") {+ const std::string value = next(a.c_str());- int64_t parsed = 0;- const auto result = std::from_chars(value.data(), value.data() + value.size(), parsed);++ int64_t number = 0;++ const auto result = std::from_chars(value.data(), value.data() + value.size(), number);+ const int64_t limit = a == "--conversation-cache-slots" ? INT32_MAX : INT64_MAX / (1024 * 1024);- if (result.ec != std::errc{} || result.ptr != value.data() + value.size() || parsed < 0 || parsed > limit) {++ if (result.ec != std::errc{} || result.ptr != value.data() + value.size() || number < 0 || number > limit) {+ std::fprintf(stderr, "%s needs a nonnegative integer within range\n", a.c_str());+ return 2;+ }- if (a == "--conversation-cache-mib") o.conversation_cache_mib = parsed;- else if (a == "--conversation-cache-min-free-mib") o.conversation_cache_min_free_mib = parsed;- else o.conversation_cache_slots = (int) parsed;++ if (a == "--conversation-cache-mib") o.conversation_cache_mib = number;++ else if (a == "--conversation-cache-min-free-mib") o.conversation_cache_min_free_mib = number;++ else o.conversation_cache_slots = (int) number;+ }else if (a == "--prompt-cache-every") o.prompt_cache_every = std::max(0LL, std::atoll(next("--prompt-cache-every")));else if (a == "--prompt-cache-root") o.prompt_cache_root = std::max(0LL, std::atoll(next("--prompt-cache-root")));else if (a == "--turn-token") o.turn_token = std::atoll(next("--turn-token"));@@@ -1191,8 -1078,14 +1182,15 @@@usage();return 2;}+ }}+ 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");+ if (o.conversation_cache_mib > 0 && o.conversation_cache_slots > 0 && o.prompt_cache > 0 && !o.layer_split.empty()) {+ std::fprintf(stderr, "strata serve: conversation parking does not yet support --layer-split; disable parking with --conversation-cache-mib 0\n");+ return 2;+ }// Layer split (multi-GPU): the later stages run layers [K_i, K_i+1) on their own GPUs (--split-device, default// the next visible ones); "auto" places the K from each GPU's free VRAM once the weights are in (below). Across// GPUs, not yet: KV streaming, images, control vectors, the helper caches (--expert-cache-remote), and lending@@@ -3966,36 -3607,18 +4034,38 @@@{size_t free_b = 0, total_b = 0;cudaMemGetInfo(&free_b, &total_b);- std::printf("INFO context=%lld kv=%s kv_resident=%lld expert_slots=%lld expert_cache_mib=%lld spec=%d "+ // "Experts in VRAM" is every tier, not one card's. This used to report `xcache` alone, so a layer split+ // showed CUDA0's cache as if it were the whole GPU's: a 4-GPU 256K run read 3327 experts when the four+ // cards held 13320, and the Monitor tab was wrong by 4x for every multi-GPU config. The tiers are+ // disjoint by construction (remote_experts.cpp skips any pair a stage already claimed), so they add.+ const int64_t slots_primary = (int64_t) xcache.slots();+ const int64_t mib_primary = (int64_t) (xcache.bytes() >> 20);+ int64_t slots_all = slots_primary, mib_all = mib_primary;+ for (const auto& st : stages) {+ slots_all += (int64_t) st->cache.slots();+ mib_all += (int64_t) (st->cache.bytes() >> 20);+ }+ for (int r = 0; r < 3; ++r)+ if (o.expert_cache_remote[(size_t) r] > 0) {+ 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 "+ "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 engine=" STRATA_VERSION "\n",+ "spec_min_p=%.2f conversation_cache_mib=%lld conversation_cache_slots=%d "+ "conversation_cache_min_free_mib=%lld engine=" STRATA_VERSION "\n",(long long) o.max_context, o.kv.c_str(),- (long long) (g.n_qsa_layers() > 0 && ss.qsa_states[0].kv_mode == 1- ? ss.qsa_states[0].n_slots * 4 : 0),- (long long) xcache.slots(), (long long) (xcache.bytes() >> 20), o.spec, o.mtp_max_t,+ (long long) (g.n_qsa_layers() > 0 && ss.qsa_states[ss.qsa_primary()].kv_mode == 1+ ? ss.qsa_states[ss.qsa_primary()].n_slots * 4 : 0),+ (long long) slots_all, (long long) mib_all,+ (long long) slots_primary, (long long) mib_primary,+ o.spec, o.mtp_max_t,o.suffix_draft, (long long) (free_b >> 20), cvec_summary.c_str(),- (long long) (strata::kernels::cpu::expert_layout().total >> 20), pool.workers(), o.pcie_frac,+ (long long) ((o.mmap_experts ? src.resident_bytes() : strata::kernels::cpu::expert_layout().total) >> 20),+ pool.workers(), o.pcie_frac,- o.spec_min_p);+ o.spec_min_p, (long long) o.conversation_cache_mib, o.conversation_cache_slots,+ (long long) o.conversation_cache_min_free_mib);}// issue #29: a request whose heartbeat (tokens, prompt chunks, verify windows) stops for this long is stuck on// a flag nobody will raise - end the engine with where it was, so the server starts it again instead of the@@@ -4730,13 -4385,13 +4861,13 @@@}return h;};- const ConvStateSizes z = conv_state_sizes(g);+ const ConvStateSizes z = conv_state_sizes(g, ss);uint64_t h_gdn = hash_dev(ss.gdn_state, z.gdn, 1469598103934665603ull);- if (std::getenv("STRATA_STATE_HASH_GDN") != nullptr) { // per GDN layer: which one differs first- if (std::getenv("STRATA_STATE_HASH_GDN") != nullptr && g.n_gdn_layers() > 0) { // per GDN layer: which one differs first- const size_t per = z.gdn / (size_t) g.n_gdn_layers();++ if (std::getenv("STRATA_STATE_HASH_GDN") != nullptr && ss.gdn_alloc > 0) { // per GDN layer: which one differs first+ const size_t per = z.gdn / (size_t) ss.gdn_alloc;std::string s;char b[8];- for (int64_t i = 0; i < g.n_gdn_layers(); ++i) {+ for (int64_t i = 0; i < ss.gdn_alloc; ++i) {std::snprintf(b, sizeof(b), "%04llx ", (unsigned long long) (hash_dev((const uint8_t*) ss.gdn_state + i * per, per, 1469598103934665603ull) & 0xffff));s += b;}@@@ -4763,11 -4425,14 +4901,14 @@@return a;};const int64_t end_cell = std::min<int64_t>(((L + qs.page_size - 1) / qs.page_size) * qs.page_size,- ss.qsa_states[ss.qsa_primary()].max_cells);- ss.max_cells);- for (int64_t i = 0; i < g.n_qsa_layers(); ++i) {- const strata::core::QsaState& st = ss.qsa_states[i];++ ss.max_cells); // = the primary state's max_cells+ for (int64_t j = 0; j < ss.qsa_alloc; ++j) { // this session's owned QSA ordinals only+ const strata::core::QsaState& st = ss.qsa_states[ss.qsa_ord0 + j];h_tail = hash_dev(st.idx_tail, z.tail, h_tail);+ h_dead = hash_dev(st.idx_dead, z.dead, h_dead);h_pool = hash_dev(st.idx_pooled, (size_t) (L / qs.idx_block) * qs.idx_dim * 4, h_pool);+ h_pool_full = hash_dev(st.idx_pooled, (size_t) (L > 0 ? L / qs.idx_block + 1 : 0) * qs.idx_dim * 4,+ h_pool_full);// KV streaming: the host copy is the identity layout and holds every cellfor (const auto& [pool, w] : kv_arrays(st)) {h_kv = hash_cells(pool, w, 0, L, h_kv);