Merge branch 'f-140' into f-140-j
This commit is contained in:
commit
2e0f28e7d7
42 files changed
+2646
-203
No files matched your search
+86
-21
@@ -2395,6 +2395,7 @@ int main(int argc, char** argv) {
|
||||
return 2;
|
||||
}
|
||||
const strata::core::ModelGeometry g0;
|
||||
const auto embed_t0 = std::chrono::steady_clock::now();
|
||||
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());
|
||||
@@ -2402,9 +2403,10 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
strata::core::set_native_embed(&native_embed);
|
||||
std::fprintf(stderr, "strata generate: native pack: %s experts (largest blob %.2f MB), token embedding "
|
||||
"%s in mapped host memory (%.0f MiB)\n",
|
||||
"%s in mapped host memory (%.0f MiB, %.1f s)\n",
|
||||
o.pack.c_str(), (double) strata::kernels::cpu::expert_layout().max_blob / 1e6,
|
||||
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0);
|
||||
strata::ggml_type_name((uint32_t) native_embed.type()), (double) native_embed.bytes() / 1048576.0,
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - embed_t0).count());
|
||||
}
|
||||
// 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.
|
||||
@@ -2491,14 +2493,21 @@ int main(int argc, char** argv) {
|
||||
(unsigned long long) (total_b >> 20));
|
||||
return 1;
|
||||
}
|
||||
auto load_t0 = std::chrono::steady_clock::now();
|
||||
auto load_s = [&] {
|
||||
const auto t = std::chrono::steady_clock::now();
|
||||
const double s = std::chrono::duration<double>(t - load_t0).count();
|
||||
load_t0 = t;
|
||||
return s;
|
||||
};
|
||||
strata::core::WeightTable wt;
|
||||
if (!wt.load(o.pack, arena, pool_bytes, err, skip.empty() ? nullptr : &skip)) {
|
||||
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(stderr, "strata generate: %llu MiB of weights loaded from %s (%zu canonical tensors skipped: "
|
||||
"served natively)\n",
|
||||
(unsigned long long) (pool_bytes >> 20), o.pack.c_str(), skip.size());
|
||||
std::fprintf(stderr, "strata generate: %llu MiB of weights loaded from %s in %.1f s (%zu canonical tensors "
|
||||
"skipped: served natively)\n",
|
||||
(unsigned long long) (pool_bytes >> 20), o.pack.c_str(), load_s(), skip.size());
|
||||
|
||||
strata::core::NativeDense native_dense;
|
||||
if (!o.native_dense_gguf.empty()) {
|
||||
@@ -2506,8 +2515,8 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: native dense projections: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(stderr, "strata generate: %zu native projection matrices, %.2f MiB of weights\n",
|
||||
native_dense.tensor_count(), (double) native_dense.weight_bytes() / (1024.0 * 1024.0));
|
||||
std::fprintf(stderr, "strata generate: %zu native projection matrices, %.2f MiB of weights, in %.1f s\n",
|
||||
native_dense.tensor_count(), (double) native_dense.weight_bytes() / (1024.0 * 1024.0), load_s());
|
||||
}
|
||||
|
||||
strata::kernels::gr_set_fp32_activations(o.gr_fp32_activations);
|
||||
@@ -3371,12 +3380,14 @@ int main(int argc, char** argv) {
|
||||
const int64_t n_vocab = wo->ne1;
|
||||
strata::core::NativeHead native_head;
|
||||
if (!o.native_head_gguf.empty() && !multi_gpu) { // a layer split's head is on its last stage
|
||||
const auto head_t0 = std::chrono::steady_clock::now();
|
||||
if (!native_head.load(o.native_head_shards, g.n_embd, n_vocab, err)) {
|
||||
std::fprintf(stderr, "strata generate: %s%s\n", err.c_str(), vram_free_note().c_str());
|
||||
return 1;
|
||||
}
|
||||
std::fprintf(stderr, "strata generate: experimental native Q5_K head, %llu bytes\n",
|
||||
(unsigned long long) native_head.weight_bytes());
|
||||
std::fprintf(stderr, "strata generate: experimental native Q5_K head, %llu bytes, in %.1f s\n",
|
||||
(unsigned long long) native_head.weight_bytes(),
|
||||
std::chrono::duration<double>(std::chrono::steady_clock::now() - head_t0).count());
|
||||
}
|
||||
std::vector<float> logits((size_t) n_vocab);
|
||||
float* d_logits = nullptr;
|
||||
@@ -3480,11 +3491,18 @@ int main(int argc, char** argv) {
|
||||
// #286: with a RAM budget the hottest experts live in it, and the rest are read from the drive unbuffered
|
||||
// when the file cache could not keep them beside the budget anyway (a 32 GB PC) - the mapped reads' page
|
||||
// faults are small requests on the critical path, and their pages take the RAM the budget was sized for
|
||||
if (o.resident_budget > 0 || std::getenv("STRATA_UNBUFFERED_LOAD") != nullptr) {
|
||||
// #773: without a RAM budget there is no RAM copy and the file cache IS the expert tier (measured on a
|
||||
// 32 GB, 2 x 16 GB rig: forcing unbuffered reads there re-read 163-629 GB from the drive and halved the
|
||||
// speed), so STRATA_UNBUFFERED_LOAD=1 is not honoured in that mode
|
||||
if (o.resident_budget > 0) {
|
||||
std::string why;
|
||||
const bool ub = src.set_unbuffered(o.resident_budget, why);
|
||||
std::fprintf(stderr, "strata generate: the file tier reads %s (%s)\n",
|
||||
ub ? "unbuffered" : "through the file cache", why.c_str());
|
||||
} else if (const char* env = std::getenv("STRATA_UNBUFFERED_LOAD"); env != nullptr && env[0] != '\0' &&
|
||||
env[0] != '0') {
|
||||
std::fprintf(stderr, "strata generate: the file tier reads through the file cache (STRATA_UNBUFFERED_LOAD=%s "
|
||||
"ignored: without --resident-budget-gib the file cache holds the experts)\n", env);
|
||||
}
|
||||
srcp = &src;
|
||||
} else {
|
||||
@@ -3664,6 +3682,13 @@ int main(int argc, char** argv) {
|
||||
used += b;
|
||||
sized_slots.push_back((int64_t) lay.blob_bytes(pr.first));
|
||||
}
|
||||
// #831: the sized-slots loop walks the profile's pairs, so the profile's length is the ceiling; an explicit
|
||||
// --expert-cache above it used to be cut with no word. A warning only (what is allocated does not change).
|
||||
if (!auto_cache && o.expert_cache > 0 && sized_slots.size() == profile.size() && (size_t) o.expert_cache > profile.size())
|
||||
std::fprintf(stderr, "strata generate: WARNING: --expert-cache %d is more than the %zu pairs of the profile %s: "
|
||||
"%zu slots (the profile is the ceiling on a native pack; a profile that ranks every "
|
||||
"(layer, expert) pair lifts it - tools/make_profile.py)\n", o.expert_cache,
|
||||
profile.size(), o.expert_profile.c_str(), profile.size());
|
||||
o.expert_cache = (int) sized_slots.size();
|
||||
}
|
||||
// #533: --vram-elastic: the cache in physical segments (the VRAM command resizes it between requests). One GPU,
|
||||
@@ -3815,12 +3840,24 @@ int main(int argc, char** argv) {
|
||||
// #286: an unbuffered file tier reads the pairs in batches of 64, the next batch while this one is copied
|
||||
std::future<void> ahead;
|
||||
auto read_batch = [&](int64_t at) { src.prefetch_pairs(profile.data() + at, std::min<int64_t>(64, want - at)); };
|
||||
// mapped reads: advise the next `fill_ahead` pairs so their reads overlap; STRATA_FILL_AHEAD=0 turns it off
|
||||
int64_t fill_ahead = 0;
|
||||
if (!per_layer && srcp == &src && !src.unbuffered()) {
|
||||
const char* v = std::getenv("STRATA_FILL_AHEAD");
|
||||
fill_ahead = v == nullptr ? 256 : std::max(0, std::atoi(v));
|
||||
if (fill_ahead > 0 && !src.advise_pairs(profile.data(), std::min<int64_t>(fill_ahead, want))) fill_ahead = 0;
|
||||
std::fprintf(stderr, "strata generate: the profile fill asks for %lld pairs ahead (STRATA_FILL_AHEAD)\n",
|
||||
(long long) fill_ahead);
|
||||
}
|
||||
const auto fill_t0 = std::chrono::steady_clock::now();
|
||||
uint64_t fill_bytes = 0;
|
||||
for (int64_t i = 0; i < want; ++i) {
|
||||
if (!per_layer && srcp == &src && src.unbuffered() && i % 64 == 0) {
|
||||
if (ahead.valid()) ahead.get();
|
||||
else read_batch(i);
|
||||
if (i + 64 < want) ahead = std::async(std::launch::async, read_batch, i + 64);
|
||||
}
|
||||
if (fill_ahead > 0 && i + fill_ahead < want) (void) src.advise_pairs(profile.data() + i + fill_ahead, 1);
|
||||
const int32_t slot = xcache.admit(profile[(size_t) i].first, profile[(size_t) i].second);
|
||||
if (slot == strata::core::kNotResident) {
|
||||
if (per_layer) continue;
|
||||
@@ -3833,8 +3870,10 @@ int main(int argc, char** argv) {
|
||||
(long long) i, err.c_str());
|
||||
return 1;
|
||||
}
|
||||
fill_bytes += strata::kernels::cpu::expert_layout().blob_bytes(profile[(size_t) i].first);
|
||||
++prefilled;
|
||||
}
|
||||
const double fill_s = std::chrono::duration<double>(std::chrono::steady_clock::now() - fill_t0).count();
|
||||
// **AND ONE SLOT IS READ BACK AND COMPARED.** A residency table that is right about indices and wrong
|
||||
// about bytes produces a plausible token, which is this project's most expensive failure mode; the
|
||||
// cache's own `verify_slot` is the check and it costs one 1.38 MB D2H at startup.
|
||||
@@ -3845,8 +3884,10 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
mem_mark("the profile fill");
|
||||
std::fprintf(stderr, "strata generate: pre-filled %lld of %lld slots from the profile; slot 0 verified\n",
|
||||
(long long) prefilled, (long long) (per_layer ? xcache.slots() : want));
|
||||
std::fprintf(stderr, "strata generate: pre-filled %lld of %lld slots from the profile in %.1f s (%.0f MB/s); "
|
||||
"slot 0 verified\n",
|
||||
(long long) prefilled, (long long) (per_layer ? xcache.slots() : want), fill_s,
|
||||
fill_s > 0 ? (double) fill_bytes / 1e6 / fill_s : 0.0);
|
||||
}
|
||||
|
||||
for (auto& stp : stages) {
|
||||
@@ -3870,9 +3911,23 @@ int main(int argc, char** argv) {
|
||||
used += b;
|
||||
sized.push_back((int64_t) lay.blob_bytes(pr.first));
|
||||
}
|
||||
if (sized.empty() ||
|
||||
!(native_pack ? st.cache.open_sized(sized, g.n_layers, g.n_expert, err)
|
||||
: st.cache.open((int64_t) sized.size(), g.n_layers, g.n_expert, (int64_t) lay.max_blob, err))) {
|
||||
// #841: a stage's cache can fail to open with the VRAM free (the card's allocation is also charged to the
|
||||
// Windows commit, or the free figure ran high): it is tried again with 90% of the slots, up to 3 times, each
|
||||
// try said. Nothing changes when the first open works.
|
||||
bool stage_open = false;
|
||||
for (int attempt = 0; !sized.empty(); ++attempt) {
|
||||
stage_open = native_pack ? st.cache.open_sized(sized, g.n_layers, g.n_expert, err)
|
||||
: st.cache.open((int64_t) sized.size(), g.n_layers, g.n_expert, (int64_t) lay.max_blob, err);
|
||||
if (stage_open || attempt >= 3) break;
|
||||
(void) cudaGetLastError();
|
||||
const size_t keep = sized.size() * 9 / 10;
|
||||
std::fprintf(stderr, "strata generate: layer split, CUDA%d expert cache: %s; trying %zu of %zu slots "
|
||||
"(try %d of 3)\n", st.dev, err.c_str(), keep, sized.size(), attempt + 1);
|
||||
if (keep == 0) break;
|
||||
st.cache.close();
|
||||
sized.resize(keep);
|
||||
}
|
||||
if (!stage_open) {
|
||||
std::fprintf(stderr, "strata generate: layer split, CUDA%d expert cache: %s\n", st.dev,
|
||||
sized.empty() ? "no room" : err.c_str());
|
||||
return 1;
|
||||
@@ -4948,7 +5003,7 @@ int main(int argc, char** argv) {
|
||||
std::string whole_err;
|
||||
if (!resident_ok && o.resident_soft) {
|
||||
// #467: the whole complement does not fit - keep what does, the hottest by the profile, through the #403
|
||||
// budget path (sized by the RAM alone) instead of none: the misses outside it read the same file bytes
|
||||
// budget path (sized by available memory) instead of none: the misses outside it read the same file bytes
|
||||
// the mmap fallback reads, so the answers are unchanged. Nothing pinned: the old fallback below.
|
||||
whole_err = err;
|
||||
resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, stage_pairs, -1, o.resident_headroom,
|
||||
@@ -4991,17 +5046,18 @@ int main(int argc, char** argv) {
|
||||
// #403: a RAM budget that cannot be kept is not a reason to stop - the experts it would have held are
|
||||
// read from the files like the ones outside it (pin_cache_complement leaves nothing half-built)
|
||||
std::fprintf(stderr, "strata generate: WARNING: the RAM budget (--resident-budget-gib) cannot be kept (%s); "
|
||||
"every expert the GPU does not hold is read from the model files through the OS file "
|
||||
"cache (--mmap-experts), which is slower\n", err.c_str());
|
||||
"every expert the GPU does not hold is read from the model files %s "
|
||||
"(--mmap-experts), which is slower\n", err.c_str(),
|
||||
src.unbuffered() ? "with unbuffered I/O" : "through the OS file cache");
|
||||
} else {
|
||||
std::fprintf(stderr, "strata generate: CPU expert residency: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
// #577: the unbuffered choice above was made before the RAM copy existed, from the budget asked for; now the
|
||||
// copy is built, decide again from the RAM it really holds and the expert bytes outside it (on a 96 GB PC
|
||||
// the file cache keeps those, and every refill after a prompt read the drive instead). Windows only: the
|
||||
// unbuffered reads exist there alone
|
||||
#if defined(_WIN32)
|
||||
// the file cache keeps those, and every refill after a prompt read the drive instead). Windows and Linux: the
|
||||
// unbuffered reads exist there
|
||||
#if defined(_WIN32) || defined(__linux__)
|
||||
if (o.mmap_experts && o.resident_budget > 0) {
|
||||
std::string why;
|
||||
const bool was = src.unbuffered();
|
||||
@@ -7781,6 +7837,11 @@ int main(int argc, char** argv) {
|
||||
auto refill_wait = [&](PfPart& p, std::string& e) -> bool {
|
||||
const strata::core::OnDevice on(p.dev);
|
||||
if (!p.cache->sync_queued(e)) return false;
|
||||
#if defined(_WIN32)
|
||||
// The copies have landed: the file pages touched by the loan need not stay in the working set.
|
||||
for (const auto& [i, slot] : p.lent)
|
||||
srcp->release(i / g.n_expert, i % g.n_expert);
|
||||
#endif
|
||||
p.lent.clear();
|
||||
p.lent_chunk = 0;
|
||||
return true;
|
||||
@@ -9260,6 +9321,10 @@ int main(int argc, char** argv) {
|
||||
std::fprintf(stderr, "strata generate: refilling the lent slots failed: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
for (const auto& [i, slot] : lent)
|
||||
srcp->release(i / g.n_expert, i % g.n_expert);
|
||||
#endif
|
||||
res_put(d_res);
|
||||
std::fprintf(stderr, "strata generate: %zu lent slots refilled in %.1f ms\n", lent.size(),
|
||||
std::chrono::duration<double, std::milli>(Clock::now() - tr).count());
|
||||
|
||||
Reference in new issue
Block a user