Linux: read ahead of the mapped loads at start
On Linux every load phase read its files one page fault (one 128 KB readahead) at a time, so a cold start spent most of its time waiting on the drive at queue depth ~2. A new platform::advise_willneed asks the kernel for a range in 128 KiB steps (WILLNEED reads at most one readahead window per call), and is called before the weight load, the native dense upload, the profile fill (256 pairs ahead, STRATA_FILL_AHEAD), the peer tier's fill (--peer-device), the resident RAM copy and the MTP draft files. STRATA_READ_AHEAD=0 turns it off. Each phase logs its time. Gen3 NVMe, RTX 5090, 32 GB, Q2_0 resident at 262K: ready in 70 s, was ~920 s.
This commit is contained in:
1 parent
2de94bca5e
commit
cb33c0bac5
10 files changed
+137
-10
No files matched your search
@@ -2422,14 +2422,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()) {
|
||||
@@ -2437,8 +2444,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);
|
||||
@@ -3743,12 +3750,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;
|
||||
@@ -3761,8 +3780,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.
|
||||
@@ -3773,8 +3794,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) {
|
||||
|
||||
Reference in new issue
Block a user