mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 07:18:50 +00:00
ling32 tier store: adaptive warm RAM tier on by default for the Windows iGPU plain decode
The adaptive warm tier (decayed use counts, promotion of SSD-resident experts from the ring into spare RAM-tier slots, quarantined demotion) is now on by default where the RAM tier is read in place (zero-copy, Windows iGPU). Spare slots 8 per size class, quarantine 24, queue 16; knobs STRATA_L32_AD_Q / AD_SPARE / AD_QUAR; STRATA_L32_ADAPT=0 / 1 still overrides. It is only used for single-token decode: promotion and use counting are skipped for MTP verify batches, and main sets StoreOptions::adaptive_default = false when --mtp is given (the first default-on build cost -10 % with MTP: the copies and the spare slots taken from the warm prefix buy nothing there). Drop-reason counters (ring slot gone / no spare / not hotter / queue full) are printed with the PF_COV statistics. Strix Halo (gfx1151), 48 short prompts, greedy ids identical to the switched-off runs in every arm: plain 23.6 tok/s vs 22.9-23.0 off (+2.6 %, SSD wait 45 s vs 55 s); MTP default 31.2 vs 31.4 off (parity, ids identical).
This commit is contained in:
1 parent
55e42b3818
commit
dc10bc0a03
4 files changed
+20
-11
No files matched your search
@@ -41,7 +41,7 @@ struct TierStats {
|
||||
uint64_t lead_n[3] = {};
|
||||
uint64_t hint_marked = 0, pf_inflight_skips = 0;
|
||||
uint64_t ssd_layer_dem[64] = {}; // demand SSD reads per layer (statistics)
|
||||
uint64_t ad_promos = 0, ad_promo_bytes = 0, ad_dropped = 0; // adaptive warm tier: promotions into the RAM tier, bytes, candidates dropped
|
||||
uint64_t ad_promos = 0, ad_promo_bytes = 0, ad_dropped = 0, ad_drop_ring = 0, ad_drop_spare = 0, ad_drop_score = 0, ad_qfull = 0; // adaptive warm tier: promotions, bytes, candidates dropped (why)
|
||||
// STRATA_L32_PF_COV=1: ceiling of an ADAPTIVE warm tier: uses of experts outside the card prefix, by where the static tiers keep them and by a usage-counted tier of the same size (decay 0.99 / 0.998 per token)
|
||||
uint64_t ad_uses = 0, ad_static_ram = 0, ad_adapt[2] = {}, ad_ssd_uses = 0, ad_ssd_rep[3] = {}; // ad_ssd_rep: SSD-resident uses that were used before within 64 / 256 / 1024 tokens (at least twice)
|
||||
// STRATA_L32_PF_COV=1: coverage of the experts of a decode / verify layer that are NOT in the card prefix, by the previous forward of the same layer ("history") and by the top 8 / 16 / 24 / 32 of the union of the
|
||||
|
||||
@@ -638,6 +638,7 @@ int cmd_run(const RunOpts& o) {
|
||||
so.device = o.device;
|
||||
so.max_tokens = o.chunk;
|
||||
so.zero_copy = o.miss_explicit ? !o.miss_stage : (igpu_zero_copy ? true : !o.miss_stage);
|
||||
so.adaptive_default = o.mtp_file.empty();
|
||||
so.prefill_budget = o.prefill_budget;
|
||||
so.turbo = o.turbo_ssd && plan.mode == TierMode::C;
|
||||
so.turbo_threshold = o.turbo_threshold;
|
||||
|
||||
@@ -187,6 +187,7 @@ struct ExpertStore::Impl {
|
||||
std::vector<std::pair<int, long long>> quarantine; // (slot, the step after which it is a spare again)
|
||||
bool adapt_on = false;
|
||||
double ad_decay = 0.99, ad_margin = 0.5, ad_min = 2.0;
|
||||
int ad_qmax = 16, ad_spare = 8, ad_quar = 24;
|
||||
std::vector<float> uc; // decayed use counts per expert
|
||||
std::vector<long long> ut;
|
||||
struct Promo { int gi, rs, tries; };
|
||||
@@ -324,10 +325,14 @@ struct ExpertStore::Impl {
|
||||
if (vp && !fill_vram(err)) return false;
|
||||
if (!so.quiet) std::printf("tier store: hot prefix filled; reading the warm prefix (%.2f GiB)\n", rp / 1073741824.0);
|
||||
if (rp && !fill_host(err)) return false;
|
||||
adapt_on = so.zero_copy && so.adaptive_default && rp > 0; // default: on where the RAM tier is read in place (the Windows iGPU); STRATA_L32_ADAPT=0 / 1 overrides
|
||||
if (const char* e = std::getenv("STRATA_L32_ADAPT")) adapt_on = e[0] == '1' && rp > 0;
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_DECAY")) ad_decay = std::max(0.5, std::min(0.9999, std::atof(e)));
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_MARGIN")) ad_margin = std::max(0.0, std::atof(e));
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_MIN")) ad_min = std::max(0.0, std::atof(e));
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_Q")) ad_qmax = std::max(1, std::min(std::atoi(e), 256));
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_SPARE")) ad_spare = std::max(1, std::min(std::atoi(e), 64));
|
||||
if (const char* e = std::getenv("STRATA_L32_AD_QUAR")) ad_quar = std::max(2, std::min(std::atoi(e), 4000));
|
||||
init_ram_slots();
|
||||
S.load_s = now_s() - t0;
|
||||
if (so.verify && !verify(err)) return false;
|
||||
@@ -601,7 +606,7 @@ struct ExpertStore::Impl {
|
||||
for (auto& kv : cls_all) { // spares: the two slots of the class that are last in the file (the coldest ranks)
|
||||
std::vector<int>& v = kv.second;
|
||||
if (v.size() < 8) continue;
|
||||
for (int k = 0; k < 2; ++k) {
|
||||
for (int k = 0; k < ad_spare; ++k) {
|
||||
const int sid = v[v.size() - 1 - static_cast<size_t>(k)];
|
||||
ram_slot_of[static_cast<size_t>(rslots[static_cast<size_t>(sid)].gi)] = -1;
|
||||
rslots[static_cast<size_t>(sid)].gi = -1;
|
||||
@@ -627,7 +632,8 @@ struct ExpertStore::Impl {
|
||||
ut[g] = now;
|
||||
}
|
||||
void maybe_promote(int gi, int rs) { // (under mu) an SSD-resident expert that is in the ring: queue it for the RAM tier if it is used often enough
|
||||
if (!adapt_on || rp == 0 || cur_tokens > 16 || promo_q.size() >= 6) return;
|
||||
if (!adapt_on || rp == 0 || cur_tokens > 1) return; // single-token decode only: with MTP verify batches the copies cost more than they save (Strix ABAB -10 %)
|
||||
if (promo_q.size() >= static_cast<size_t>(ad_qmax)) { ++S.ad_qfull; return; }
|
||||
if (use_score(gi, static_cast<long long>(S.tokens)) < ad_min) return;
|
||||
const uint32_t cls = static_cast<uint32_t>(ed[static_cast<size_t>(gi)].body_bytes);
|
||||
if (!cls_all.count(cls)) return;
|
||||
@@ -655,10 +661,10 @@ struct ExpertStore::Impl {
|
||||
promo_q.pop_front();
|
||||
Ring& r = ring[static_cast<size_t>(p.rs)];
|
||||
if (r.gi == p.gi && r.state == 1 && p.tries < 60) { ++p.tries; promo_q.push_back(p); return false; } // the read is still in flight: look again when it has completed
|
||||
if (r.gi != p.gi || r.state != 2 || ram_slot_of[static_cast<size_t>(p.gi)] >= 0) { ++S.ad_dropped; return true; }
|
||||
if (r.gi != p.gi || r.state != 2 || ram_slot_of[static_cast<size_t>(p.gi)] >= 0) { ++S.ad_dropped; ++S.ad_drop_ring; return true; }
|
||||
bytes = static_cast<uint32_t>(ed[static_cast<size_t>(p.gi)].body_bytes);
|
||||
auto sp = cls_spare.find(bytes);
|
||||
if (sp == cls_spare.end() || sp->second.empty()) { ++S.ad_dropped; return true; }
|
||||
if (sp == cls_spare.end() || sp->second.empty()) { ++S.ad_dropped; ++S.ad_drop_spare; return true; }
|
||||
const long long now = static_cast<long long>(S.tokens);
|
||||
const double cand = use_score(p.gi, now);
|
||||
double best = 1e300;
|
||||
@@ -668,7 +674,7 @@ struct ExpertStore::Impl {
|
||||
const double sc = use_score(g, now);
|
||||
if (sc < best) { best = sc; victim = sid; }
|
||||
}
|
||||
if (victim < 0 || cand <= best + ad_margin) { ++S.ad_dropped; return true; }
|
||||
if (victim < 0 || cand <= best + ad_margin) { ++S.ad_dropped; ++S.ad_drop_score; return true; }
|
||||
spare = sp->second.back();
|
||||
sp->second.pop_back();
|
||||
r.state = 3; // the ring slot stays put until the copy is done
|
||||
@@ -683,7 +689,7 @@ struct ExpertStore::Impl {
|
||||
const int vg = rslots[static_cast<size_t>(victim)].gi;
|
||||
ram_slot_of[static_cast<size_t>(vg)] = -1;
|
||||
rslots[static_cast<size_t>(victim)].gi = -1;
|
||||
quarantine.emplace_back(victim, static_cast<long long>(step) + 80); // the GPU or a DMA may still read the demoted slab: the slot is reused after 80 layer steps
|
||||
quarantine.emplace_back(victim, static_cast<long long>(step) + ad_quar); // the GPU or a DMA may still read the demoted slab: the slot is reused after 80 layer steps
|
||||
++S.ad_promos;
|
||||
S.ad_promo_bytes += bytes;
|
||||
}
|
||||
@@ -899,7 +905,7 @@ struct ExpertStore::Impl {
|
||||
it.kind = 4;
|
||||
stage.push_back(static_cast<int>(i));
|
||||
}
|
||||
if (adapt_on) { // usage counts of the experts outside the card prefix; SSD-resident ones that are in the ring become candidates for the RAM tier
|
||||
if (adapt_on && cur_tokens <= 1) { // usage counts of the experts outside the card prefix; SSD-resident ones that are in the ring become candidates for the RAM tier
|
||||
for (const Item& it : items) if (it.off + it.bytes > vp) ad_touch(it.gi, static_cast<long long>(S.tokens));
|
||||
for (const Item& it : items) if (!it.src_host && it.kind >= 3 && it.rslot >= 0) maybe_promote(it.gi, it.rslot);
|
||||
}
|
||||
@@ -1588,9 +1594,10 @@ std::string ExpertStore::report() const {
|
||||
}
|
||||
}
|
||||
if (s.ad_promos || s.ad_dropped) {
|
||||
char c9[200];
|
||||
std::snprintf(c9, sizeof c9, "\n adaptive warm tier: %llu promotions into the RAM tier (%.1f MB per token), %llu candidates dropped",
|
||||
static_cast<unsigned long long>(s.ad_promos), s.ad_promo_bytes / 1048576.0 / std::max<double>(1.0, static_cast<double>(s.tokens)), static_cast<unsigned long long>(s.ad_dropped));
|
||||
char c9[320];
|
||||
std::snprintf(c9, sizeof c9, "\n adaptive warm tier: %llu promotions into the RAM tier (%.1f MB per token), %llu candidates dropped (ring slot gone %llu, no spare slot %llu, not hotter than the victim %llu), %llu not queued (queue full)",
|
||||
static_cast<unsigned long long>(s.ad_promos), s.ad_promo_bytes / 1048576.0 / std::max<double>(1.0, static_cast<double>(s.tokens)), static_cast<unsigned long long>(s.ad_dropped),
|
||||
static_cast<unsigned long long>(s.ad_drop_ring), static_cast<unsigned long long>(s.ad_drop_spare), static_cast<unsigned long long>(s.ad_drop_score), static_cast<unsigned long long>(s.ad_qfull));
|
||||
out += c9;
|
||||
}
|
||||
if (s.ad_uses > 0) {
|
||||
|
||||
@@ -22,6 +22,7 @@ struct StoreOptions {
|
||||
int device = 0;
|
||||
int max_tokens = 256; // forward() batch size (sizes the host tables)
|
||||
bool zero_copy = false; // a miss used by one token is read in place (pinned RAM / ring); false: always staged into a slot first
|
||||
bool adaptive_default = true; // the adaptive warm tier is on by default where zero_copy and a RAM tier exist; main turns it off for MTP (its verify batches gain nothing: Strix ABAB -2 %)
|
||||
bool verify = true; // compare a few slabs of every loaded tier with the file after the start-up fill
|
||||
int prefill_budget = 192; // experts per layer prefetched for a batch (ranked union)
|
||||
bool turbo = false; // --turbo-ssd: skip SSD-resident experts of decode layers once the covered routing mass reaches turbo_threshold (renormalised weights); NOT exact
|
||||
|
||||
Reference in new issue
Block a user