Elastic K/V (--kv-grow): the K/V takes VRAM as the context grows, the expert cache holds the rest
At --max-context 262144 the K/V is allocated whole at start (3.35 GiB at int8 with the drafter's) and the expert cache is sized around it. With --kv-grow (or STRATA_KV_GROW=1) the K/V pools and the cache arena are CUDA VMM ranges (core/vmm.hpp; the driver calls through the runtime's entry-point query, nothing links the driver library). The K/V maps 2 MiB chunks for the cells the requests reach (16384 at start); when a request needs more, slots just below the prompt path's loan give theirs up, a hotter expert in them first moving into the slot of the coldest one in the loan region. A short request after a long one hands the chunks back and the slots refill from the profile. No address moves, so no graph is captured again, and --max-context cells always fit. - serve: grows at a request (its prompt, and a parked conversation before its restore) and in the decode rounds; trims once the outgoing session is parked - generate: grows once for the prompt and max_new, before the loan - one GPU with a profile, the whole K/V in VRAM (no --kv-resident), every expert in RAM (not the low-RAM tier); STRATA_KV_GROW_INIT / _STEP / _FLOOR for tests. Off by default: more slots move experts between GPU and CPU. - tests/core/vmm_test: map, a chunk moved between ranges keeps its bytes, release IQ2_XS, RTX 5090, 262K, fixed cache: first-token logits and 64 tokens bit-identical to 0.1.31 off, mapped whole, grown into new VRAM, and grown by giving up 266 slots. Cache auto: 15,119-15,207 -> 17,300-17,503 slots, short chat 15.06-15.33 -> 14.71-14.83 ms a round; an emulated 16 GB card: 3,396 -> 5,719 slots, short chat 100 -> 115 tok/s, a 32K prompt 7.44 -> 6.36 s and 24.6 -> 22.2 ms a round after it.
This commit is contained in:
1 parent
91cc8149b0
commit
9e3dbfe74a
9 files changed
+758
-5
No files matched your search
@@ -449,6 +449,12 @@ bool ExpertCache::ensure_blocking_staging(std::size_t bytes, std::string& err) {
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
bool g_cache_vmm = false; // set_vmm
|
||||
} // namespace
|
||||
|
||||
void ExpertCache::set_vmm(bool enabled) { g_cache_vmm = enabled; }
|
||||
|
||||
bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int64_t blob_bytes,
|
||||
std::string& err) {
|
||||
close();
|
||||
@@ -487,6 +493,18 @@ bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int6
|
||||
|
||||
if (seg_req_ > 0) { // #533: --vram-elastic: physical segments behind one address range (zeroed below)
|
||||
if (!open_segmented(want, err)) return false;
|
||||
} else if (g_cache_vmm && vmm_available()) {
|
||||
// the elastic K/V: every chunk mapped now; the K/V may later take some of them (and give them back)
|
||||
auto r = std::make_unique<VmmRange>();
|
||||
if (!r->reserve(want) || !r->map_range(0, r->chunks(), [] { return (VmmChunk) 0; })) {
|
||||
char buf[256];
|
||||
std::snprintf(buf, sizeof buf, "ExpertCache: mapping %.2f GiB of VRAM failed: out of memory",
|
||||
(double) want / 1073741824.0);
|
||||
err = buf;
|
||||
return false;
|
||||
}
|
||||
base_ = r->base();
|
||||
vmm_ = std::move(r);
|
||||
} else if (cudaMalloc((void**) &base_, (size_t) want) != cudaSuccess) {
|
||||
base_ = nullptr;
|
||||
char buf[256];
|
||||
@@ -571,6 +589,9 @@ void ExpertCache::close() {
|
||||
off_.clear();
|
||||
if (!segs_.empty()) {
|
||||
release_segmented();
|
||||
} else if (vmm_) {
|
||||
vmm_.reset(); // unmaps and frees every chunk it still holds
|
||||
base_ = nullptr;
|
||||
} else if (base_ != nullptr) {
|
||||
cudaFree(base_);
|
||||
base_ = nullptr;
|
||||
|
||||
Reference in new issue
Block a user