Conversation checkpoints: opt-in STRATA_CKPT_ASYNC (background device-to-host copy) and STRATA_CKPT_VRAM_SLOTS (#3779, #3712)
Problem: on a slow host link a turn checkpoint copies the whole GDN state to the host on the request path (118 MB at 1.64 GB/s on a PCIe Gen2 x4 card, 72 ms; an independent RTX 3090 on PCIe 3.0 x16 showed 73 ms to 62 ms with the switch). Restoring a parked conversation copies it back. Change, both opt-in and CUDA only (off on HIP, gfx906 and Metal): - STRATA_CKPT_ASYNC=1: the GDN state is copied device to device into a VRAM stage (one buffer the size of the state, allocated at the first checkpoint save, plus a pinned host buffer of the same size; if either allocation fails the save falls back to the synchronous copy), and a background thread moves it in 4 MiB pieces into the checkpoint's host vector. Every reader joins first and only for the copy it needs (restore, snapshot save and restore, the parked copies, the serve loop at each request start, the SAVE/RESTORE session handler). - STRATA_CKPT_VRAM_SLOTS=N (with ASYNC): the last N saved GDN states stay in VRAM, tag-checked, only allocated while 1.5 GB stays free; a restore of a checkpoint whose tag a slot holds copies device to device. - STRATA_TRACE lines carry a steady-clock timestamp; STRATA_PARK_TRACE prints the timing of the save steps. - Unset: the code adds a mutex-guarded no-op join per checkpoint save, restore and snapshot, a tag field that stays 0 and a few clock reads; the copies are the synchronous ones as before. Differs from the PR as submitted: the PR put a join into conversation_file.cpp (put_checkpoint), which broke the conversation_file_test and session_save_reclaim_test builds without CUDA and matched only the copied vector, not the one the copy in flight writes, so a SAVE within one checkpoint copy after a turn could write an incomplete GDN state (found by bitaccesscomau; fixed in the PR's last commit 33a8146a). This commit carries that fix: conversation_file.cpp stays as it is and the join runs first in the SAVE/RESTORE handler of generate.cpp. The commit 33a8146a is therefore not a separate commit here. One more join, found by running the new ctest entries: conversation_snapshot_sources (the SAVE path of a session file) saves the running state with the background copy and the caller writes it to the file at once, after the handler's join has already run. It now joins the copy of that checkpoint before it returns; without it a session file written with STRATA_CKPT_ASYNC=1 could hold an incomplete GDN state (conversation_snapshot_test failed at "both files read" before the join). Tests: conversation_snapshot_test now joins after each save and, with STRATA_TEST_BIG_GDN=1 (a GDN state over 1 MiB, so the async path is taken), runs as the new ctest entries conversation_snapshot_test_ckpt_async and conversation_snapshot_test_ckpt_vram_slots: every checkpoint, capture and restore must give the same bytes as the plain run. Not covered: no test destroys a checkpoint while its copy is in flight (readers join; the cache's eviction paths do not); the reporter saw 3 of about 35 engine starts stop answering after a park with evictions, on the paths with the switches off, and could not reproduce it in 15 reruns. The VRAM stage has no headroom check of its own (an RTX 3090 with 147 MiB minimum free showed no failure in 42 of 42 saves; the allocation failure falls back silently). Reporter's numbers (linxuhao, CMP 170HX): turn checkpoint 71.4 -> 0.9 ms, restore 114-126 -> 28-47 ms. Independent data (bitaccesscomau, RTX 3090 24 GB, PCIe 3.0 x16, release defaults, 4 pairs): checkpoint save 73.2 -> 62.4 ms, tiny-prompt time to first token median ratio 1.038, outputs byte-identical. Theirs, not measured here. Original change by linxuhao (PR #3779, commits 0d512925 and 33a8146a).
This commit is contained in:
1 parent
8c2a846947
commit
0f7224d168
7 files changed
+222
-19
No files matched your search
@@ -1816,6 +1816,7 @@ public:
|
||||
bool on() const { return on_; }
|
||||
void give(ConvCheckpoint&& c) {
|
||||
if (!on_ || c.gdn.empty()) return;
|
||||
strata::core::conversation_checkpoint_join(c.gdn.data());
|
||||
clear_marks(c);
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
if (free_.size() < cap_) free_.push_back(std::move(c));
|
||||
@@ -1839,7 +1840,7 @@ public:
|
||||
}
|
||||
private:
|
||||
static void clear_marks(ConvCheckpoint& c) {
|
||||
c.ids.clear(); c.imgs.clear(); c.used = 0; c.pinned = false;
|
||||
c.ids.clear(); c.imgs.clear(); c.used = 0; c.pinned = false; c.dev_tag = 0;
|
||||
for (ConvCheckpoint& part : c.stage_parts) clear_marks(part);
|
||||
}
|
||||
bool on_;
|
||||
@@ -9935,6 +9936,7 @@ int main(int argc, char** argv) {
|
||||
if (parts != nullptr) {
|
||||
if (parts->size() != stages.size() + 1) return false;
|
||||
c.gdn = std::move((*parts)[0].gdn);
|
||||
c.dev_tag = (*parts)[0].dev_tag;
|
||||
c.ple = std::move((*parts)[0].ple);
|
||||
c.tails = std::move((*parts)[0].tails);
|
||||
c.dead = std::move((*parts)[0].dead);
|
||||
@@ -11242,7 +11244,8 @@ int main(int argc, char** argv) {
|
||||
const bool trace = std::getenv("STRATA_TRACE") != nullptr;
|
||||
auto tr = [&](const char* what, long long a = -1, long long b = -1) {
|
||||
if (!trace) return;
|
||||
std::fprintf(stderr, "strata trace: %s %lld %lld\n", what, a, b);
|
||||
std::fprintf(stderr, "strata trace: %s %lld %lld @%.1f\n", what, a, b,
|
||||
std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now().time_since_epoch()).count());
|
||||
std::fflush(stderr);
|
||||
};
|
||||
{
|
||||
@@ -12443,6 +12446,9 @@ int main(int argc, char** argv) {
|
||||
std::fflush(stdout);
|
||||
};
|
||||
strata::core::progress_at(save ? "saving a session" : "restoring a session");
|
||||
// the background copy of the last turn checkpoint (STRATA_CKPT_ASYNC) lands before anything below copies, frees
|
||||
// or writes the checkpoints (a join inside the session file writer would match only the copy of a checkpoint)
|
||||
strata::core::conversation_checkpoint_join(nullptr);
|
||||
if (path.empty()) { refuse("missing path"); continue; }
|
||||
if (!stages.empty() || multi_gpu) { refuse("session files do not support --layer-split"); continue; }
|
||||
if (o.peer_device >= 1) { refuse("session files do not support --peer-device"); continue; }
|
||||
@@ -12875,6 +12881,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
cur = ids;
|
||||
const Clock::time_point r0 = Clock::now();
|
||||
tr("r0");
|
||||
strata::core::conversation_checkpoint_join(nullptr); // STRATA_CKPT_ASYNC: the last save's copy has landed
|
||||
const int64_t streamed0 = sp.chain_experts_streamed(); // the DONE line's experts_streamed= is the difference
|
||||
// ---- where this request starts reading: the live session, or a checkpoint, whose tokens AND pictures are
|
||||
// exactly the start of this prompt - at most n - 1 of them, the last token is always the first window
|
||||
|
||||
Reference in new issue
Block a user