Parking a conversation beats the watchdog: its checkpoint and K/V copies report progress, the stage is named, Windows counts hard page faults as file-tier activity, and the stall report and each request say how little VRAM is free (#2049 #2065)
This commit is contained in:
1 parent
798f3006bb
commit
3804b43f19
4 files changed
+97
-13
No files matched your search
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "strata/core/progress.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -78,6 +80,7 @@ public:
|
||||
segment.resize(count, value);
|
||||
segments_.push_back(std::move(segment));
|
||||
size_ += count;
|
||||
progress_beat(); // #2049: zero-filling 16 MiB of fresh pages is slow when the host is paging
|
||||
}
|
||||
} else {
|
||||
while (!segments_.empty() && size_ - segments_.back().size() >= n) {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "strata/core/conversation_cache.hpp"
|
||||
#include "strata/core/progress.hpp"
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
@@ -31,24 +33,58 @@ inline cudaError_t copy_nonblocking(void* dst, const void* src, size_t bytes) {
|
||||
cudaStream_t s = streams[(size_t) dev];
|
||||
e = cudaMemcpyAsync(dst, src, bytes, cudaMemcpyDefault, s);
|
||||
if (e != cudaSuccess) return e;
|
||||
return cudaStreamSynchronize(s);
|
||||
e = cudaStreamSynchronize(s);
|
||||
core::progress_beat(); // #2049: a parked conversation is many of these; each one that lands is progress
|
||||
return e;
|
||||
}
|
||||
|
||||
/// STRATA_TEST_SLOW_COPY_US=N (tests only): a parked conversation's running checkpoints copy as slowly as when the OS
|
||||
/// has paged them out - N microseconds per MiB copied. Unset: a plain copy.
|
||||
/// #2049 #2065 #1971: a host-to-host copy that tells the watchdog it is moving. Parked state (the running
|
||||
/// checkpoints, the K/V segments) sits in ordinary pageable memory for the whole session; when the OS has written
|
||||
/// it to the pagefile, copying it back runs at the drive's page-in speed (measured in the reports: ~190 hard faults
|
||||
/// a second, under 1 MB/s) and one memcpy of it stays silent past the 60 s limit, so the watchdog ended an engine
|
||||
/// that was only slow. One beat per 1 MiB slice keeps a copy that moves alive and still lets a real stall show.
|
||||
/// STRATA_TEST_SLOW_COPY_US=N (tests only): every 1 MiB slice of a checkpoint copy takes N microseconds more, as when
|
||||
/// the OS has paged the checkpoints out and each slice is read back from the drive. Unset: no delay.
|
||||
inline long test_slow_copy_us() {
|
||||
static const long v = [] { const char* e = std::getenv("STRATA_TEST_SLOW_COPY_US"); return e ? std::atol(e) : 0L; }();
|
||||
return v;
|
||||
}
|
||||
|
||||
inline std::vector<ConversationCheckpoint> copy_checkpoints(const std::vector<ConversationCheckpoint>& cs) {
|
||||
std::vector<ConversationCheckpoint> out = cs;
|
||||
if (const long us = test_slow_copy_us(); us > 0) {
|
||||
size_t bytes = 0;
|
||||
for (const auto& c : out) bytes += c.bytes();
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(us * (long) (bytes >> 20)));
|
||||
template<class T>
|
||||
inline std::vector<T> copy_beating(const std::vector<T>& src) {
|
||||
std::vector<T> out;
|
||||
out.reserve(src.size());
|
||||
const size_t step = std::max<size_t>(1, ((size_t) 1 << 20) / sizeof(T));
|
||||
for (size_t at = 0; at < src.size(); at += step) {
|
||||
out.insert(out.end(), src.begin() + (std::ptrdiff_t) at,
|
||||
src.begin() + (std::ptrdiff_t) std::min(src.size(), at + step));
|
||||
if (const long us = test_slow_copy_us(); us > 0) std::this_thread::sleep_for(std::chrono::microseconds(us));
|
||||
core::progress_beat();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
inline ConversationCheckpoint copy_checkpoint_beating(const ConversationCheckpoint& c) {
|
||||
ConversationCheckpoint o;
|
||||
o.ids = copy_beating(c.ids);
|
||||
o.imgs = copy_beating(c.imgs);
|
||||
o.gdn = copy_beating(c.gdn);
|
||||
o.ple = copy_beating(c.ple);
|
||||
o.tails = copy_beating(c.tails);
|
||||
o.dead = copy_beating(c.dead);
|
||||
o.block_pos = copy_beating(c.block_pos);
|
||||
o.used = c.used;
|
||||
o.pinned = c.pinned;
|
||||
o.stage_parts.reserve(c.stage_parts.size());
|
||||
for (const auto& part : c.stage_parts) o.stage_parts.push_back(copy_checkpoint_beating(part));
|
||||
return o;
|
||||
}
|
||||
|
||||
inline std::vector<ConversationCheckpoint> copy_checkpoints_beating(const std::vector<ConversationCheckpoint>& cs) {
|
||||
std::vector<ConversationCheckpoint> out;
|
||||
out.reserve(cs.size());
|
||||
for (const auto& c : cs) out.push_back(copy_checkpoint_beating(c));
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace strata::core::conversation_detail
|
||||
@@ -257,7 +257,7 @@ bool conversation_snapshot_save(SavedConversation& image, const ConversationView
|
||||
captured.geometry = geometry_key(g);
|
||||
captured.layer_lo = ss.layer_lo; captured.layer_hi = ss.layer_hi;
|
||||
captured.live.ids = view.ids; captured.live.imgs = view.images;
|
||||
captured.cvec = view.cvec; captured.checkpoints = conversation_detail::copy_checkpoints(view.checkpoints);
|
||||
captured.cvec = view.cvec; captured.checkpoints = conversation_detail::copy_checkpoints_beating(view.checkpoints);
|
||||
const int64_t unchanged = reuse.kv.empty() ? 0 : reuse.unchanged_tokens;
|
||||
captured.kv = std::move(reuse.kv);
|
||||
const size_t layers = owned_qsa(ss);
|
||||
@@ -283,7 +283,7 @@ bool conversation_snapshot_sources(SavedConversation& meta, std::vector<SessionK
|
||||
captured.geometry = geometry_key(g);
|
||||
captured.layer_lo = ss.layer_lo; captured.layer_hi = ss.layer_hi;
|
||||
captured.live.ids = view.ids; captured.live.imgs = view.images;
|
||||
captured.cvec = view.cvec; captured.checkpoints = conversation_detail::copy_checkpoints(view.checkpoints);
|
||||
captured.cvec = view.cvec; captured.checkpoints = conversation_detail::copy_checkpoints_beating(view.checkpoints);
|
||||
if (!conversation_checkpoint_save(captured.live, ss, g, error)) return false;
|
||||
const int64_t upto = (int64_t) view.ids.size();
|
||||
const size_t layers = owned_qsa(ss);
|
||||
|
||||
@@ -1156,12 +1156,14 @@ static uint64_t file_tier_activity() {
|
||||
return total;
|
||||
#elif defined(_WIN32)
|
||||
// #1984 #1971: Windows had no measure here, so a prompt waiting on mapped-file page-ins never got the I/O allowance.
|
||||
// Bytes read (MiB) plus page faults / 64 (Windows counts soft faults too; a stuck engine makes almost none).
|
||||
// Bytes read (MiB) plus page faults / 8 (Windows counts soft faults too; a stuck engine makes almost none).
|
||||
uint64_t total = 0;
|
||||
IO_COUNTERS io{};
|
||||
if (GetProcessIoCounters(GetCurrentProcess(), &io)) total += io.ReadTransferCount >> 20;
|
||||
PROCESS_MEMORY_COUNTERS pmc{};
|
||||
if (K32GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof pmc)) total += pmc.PageFaultCount >> 6;
|
||||
// >> 3, not >> 6: a host that pages hard reads from the pagefile at ~200 faults a second (#2049: 190/s, one
|
||||
// thread waiting on one page at a time), which at >> 6 is 3 a second and never counted as busy
|
||||
if (K32GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof pmc)) total += pmc.PageFaultCount >> 3;
|
||||
return total;
|
||||
#else
|
||||
return 0;
|
||||
@@ -1261,12 +1263,29 @@ bool launch_blocking() {
|
||||
#endif
|
||||
}
|
||||
|
||||
/// #2065: the VRAM free when the current request began (-1 before the first); the stall report prints it, because a
|
||||
/// card this full is the one measured cause of a window that never finishes (the driver pages GPU memory).
|
||||
std::atomic<int64_t> g_req_vram_free_mib{-1};
|
||||
constexpr int64_t kVramSafeMib =
|
||||
#ifdef _WIN32
|
||||
1024; // WDDM pages instead of failing (docs/DETAILS.md, the sysmem fallback): the line #2065 fell below
|
||||
#else
|
||||
512;
|
||||
#endif
|
||||
|
||||
void stall_report(std::FILE* f, uint64_t layers_during) {
|
||||
strata::core::Progress& p = strata::core::progress();
|
||||
std::fprintf(f, "strata serve: stall report (engine %s): stage \"%s\" for %lld s; %llu layers served since the "
|
||||
"last finished step (0 = stopped, more = slow)\n", STRATA_VERSION, stage_text().c_str(),
|
||||
(long long) ((strata::core::progress_now_ms() - p.since_ms.load()) / 1000),
|
||||
(unsigned long long) layers_during);
|
||||
if (const int64_t vf = g_req_vram_free_mib.load(); vf >= 0) {
|
||||
std::fprintf(f, " VRAM free when this request began: %lld MiB%s\n", (long long) vf,
|
||||
vf >= kVramSafeMib ? "" : " - LOW: a card this full can page GPU memory to system RAM (decode "
|
||||
"falls to a few tok/s, then a window never finishes, #2065); a larger --vram-reserve-mib, a "
|
||||
"smaller --max-context, or 'Prefer No Sysmem Fallback' for the engine in the NVIDIA control panel "
|
||||
"(docs/DETAILS.md) leaves room");
|
||||
}
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
if (pass == 1) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
@@ -7844,6 +7863,14 @@ int main(int argc, char** argv) {
|
||||
// addresses change: all parked images live in ordinary host vectors.
|
||||
auto park_current_body = [&](size_t held) -> bool {
|
||||
if (!conversations.enabled() || !live_ok || live.empty()) return true;
|
||||
// #2049: parking copies the outgoing conversation's running checkpoints and K/V into host memory, which
|
||||
// is a silent stretch of the "request" stage; when the OS has paged that memory out it takes minutes.
|
||||
// Named, so a stall report says "parking"; its copies beat (conversation_copy.hpp), so the watchdog
|
||||
// sees a park that moves and ends one that does not.
|
||||
struct ParkStage {
|
||||
ParkStage() { strata::core::progress_at("request: parking the previous conversation"); }
|
||||
~ParkStage() { strata::core::progress_at("request"); strata::core::progress_beat(); }
|
||||
} park_stage;
|
||||
// --conversation-cache-min-tokens: a short conversation is not worth one of the slots. Parking is a
|
||||
// switch-time decision, so a client's small side requests would otherwise park themselves and, once the
|
||||
// cache is full, evict the long conversation they were interleaved with (oldest first) - the reuse it
|
||||
@@ -9819,6 +9846,24 @@ int main(int argc, char** argv) {
|
||||
strata::core::progress_at("idle");
|
||||
}
|
||||
} busy_scope;
|
||||
{ // #2065: said, never changed - the free VRAM now (the verify windows' captures and the batch layouts
|
||||
// eat into what startup reported), once per 128 MiB lower it gets
|
||||
size_t vf_b = 0, vt_b = 0;
|
||||
if (cudaMemGetInfo(&vf_b, &vt_b) == cudaSuccess) {
|
||||
const int64_t vf = (int64_t) (vf_b >> 20);
|
||||
g_req_vram_free_mib.store(vf);
|
||||
static int64_t low_said_at = INT64_MAX;
|
||||
if (vf < kVramSafeMib && vf + 128 <= low_said_at) {
|
||||
low_said_at = vf;
|
||||
std::fprintf(stderr, "strata serve: WARNING: only %lld MiB of VRAM free at the start of this request "
|
||||
"(below %lld MiB): when the card is this full the driver can page GPU memory "
|
||||
"to system RAM, decode falls to a few tok/s and a window may never finish "
|
||||
"(#2065). Add --vram-reserve-mib %lld to the config's args, or lower "
|
||||
"--max-context / --batch\n", (long long) vf, (long long) kVramSafeMib,
|
||||
(long long) ((o.vram_reserve_mib + (kVramSafeMib - vf) + 63) / 64 * 64));
|
||||
}
|
||||
}
|
||||
}
|
||||
stop_req.store(false); // a STOP that arrived between requests is stale
|
||||
err.clear();
|
||||
// Disk sessions: SAVE <path> | RESTORE <path>, between requests (the path runs to the end of the line,
|
||||
|
||||
Reference in new issue
Block a user