diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 6b31bfb0..a7a97499 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -6420,6 +6420,28 @@ int main(int argc, char** argv) { o.prefill_chunk = std::min(o.prefill_chunk, 8192); } } + // #2090 (bdwilton): the gfx12 16384 ceiling lends the prompt path about twice the slots of 8192 (R9700, Swift 1.5 + // IQ3_XXS: 3,907 slots / 6.38 GiB against 2,068 / 3.37 GiB), and every lent slot's expert is read from the RAM side + // during the read. On a 30 GB PC with --resident-experts that was 3.4 GB available, 20 GB in swap, 1.5M major faults + // and a killed engine on 38-47K prompts; 8192 ran them at 95 tok/s. The ceiling is the engine's default, not the + // user's pick, so when the RAM available now does not cover the extra loan plus 4 GiB the default stays at 8192. + // STRATA_GFX12_CHUNK=1 keeps 16384 anyway. + if (o.prefill_gfx12_16k && auto_ceiling > 8192) { + static const char* force16 = std::getenv("STRATA_GFX12_CHUNK"); + const int64_t extra_slots = std::max(0, lend_slots(16384) - lend_slots(8192)); + const uint64_t extra_mib = ((uint64_t) extra_slots * strata::kernels::cpu::expert_layout().max_blob) >> 20; + const auto hm = strata::core::sample_host_memory(); // the cgroup / --memory-limit-mib cap counts too + const uint64_t avail_mib = hm ? hm->available >> 20 : mem_sample().avail_mib; + if (avail_mib > 0 && avail_mib < extra_mib + 4096 && !(force16 != nullptr && force16[0] == '1')) { + auto_ceiling = std::min(auto_ceiling, 8192); + o.prefill_auto_max = std::min(o.prefill_auto_max, 8192); + o.prefill_chunk = std::min(o.prefill_chunk, 8192); + std::fprintf(stderr, "strata generate: gfx12: prompt chunks stay at 8192: 16384 would lend %lld more cache slots " + "(%llu MiB read from RAM during a prompt) and %llu MiB of RAM is available (#2090; " + "STRATA_GFX12_CHUNK=1 takes 16384 anyway)\n", + (long long) extra_slots, (unsigned long long) extra_mib, (unsigned long long) avail_mib); + } + } if (o.prefill_auto_cap > 0) auto_ceiling = std::min(auto_ceiling, o.prefill_auto_cap); // #1630 // The auto scan used to walk a fixed list of sizes - 32768, 16384, 8192, 6144, ... - and take the first that // fit. That list is coarse exactly where a rig needs it: this one affords ~8,700 tokens and was handed 8192,