Archived
--host-headroom-mib N: the RAM radiance leaves free for the system at startup becomes a flag -- kLockMargin's fixed 4 GiB suited a busy server, and a 30 GiB host paid it in dead RAM to no purpose: startup refuses a host pin unless available memory covers it with that much still free, and --checkpoint-slots auto's bound is priced with it; so when 1.7.0 began counting the checkpoint store against this check, configs that 1.6.0 ran refused to start and the fix cost a quarter of the prefix cache.
This commit is contained in:
1 parent
d37639ef71
commit
f10c8521cd
7 files changed
+57
-36
No files matched your search
@@ -73,6 +73,8 @@ static const Flag g_flags[] = {
|
||||
{ "--gpu-headroom-mib", "N", "VRAM left unclaimed on every card (default 96)" },
|
||||
{ "--kv-cache-dtype", "T", "bf16 | fp8 -- fp8 halves what a token of context costs" },
|
||||
{ "--host-pool-mib", "N", "pinned host tier" },
|
||||
{ "--host-headroom-mib", "N", "host RAM to leave free for the system when radiance\n"
|
||||
" pins its host memory at startup (default 4096)" },
|
||||
{ "--embedding-placement", "WHERE", "ram (default) | vram: where the token embedding lives. ram\n"
|
||||
" pins it in host memory beside --host-pool-mib, read over the\n"
|
||||
" link in place; by default a model whose output head reads the\n"
|
||||
@@ -461,6 +463,7 @@ int config_parse(int argc, char** argv, Config* c) {
|
||||
/* --gpu-headroom is accepted as an alias of --gpu-headroom-mib. */
|
||||
else if (S("--gpu-headroom-mib") || S("--gpu-headroom"))
|
||||
{ if (!num(0, INT64_MAX, &c->gpu_headroom_mib)) return RAD_E_INVAL; }
|
||||
else if (S("--host-headroom-mib")) { if (!num(0, INT64_MAX, &c->host_headroom_mib)) return RAD_E_INVAL; }
|
||||
else if (S("--kv-cache-dtype")) {
|
||||
if (!(v = need(i))) return RAD_E_INVAL;
|
||||
if (std::strcmp(v, "bf16") && std::strcmp(v, "fp8")) {
|
||||
@@ -1000,6 +1003,7 @@ const ShowRow kShow[] = {
|
||||
{ "--gpu-headroom-mib", [](const Config& c) { return num(c.gpu_headroom_mib); } },
|
||||
{ "--kv-cache-dtype", [](const Config& c) { return c.kv_cache_dtype; } },
|
||||
{ "--host-pool-mib", [](const Config& c) { return num(c.host_pool_mib); } },
|
||||
{ "--host-headroom-mib", [](const Config& c) { return num(c.host_headroom_mib); } },
|
||||
{ "--embedding-placement", [](const Config& c) { return std::string(table_placement_name(c.embedding_placement)); } },
|
||||
{ "--ngram-placement", [](const Config& c) { return std::string(table_placement_name(c.ngram_placement)); } },
|
||||
{ "--vision-tower-placement", [](const Config& c) { return std::string(table_placement_name(c.tower_placement)); } },
|
||||
|
||||
@@ -159,6 +159,10 @@ private:
|
||||
* time. Requests and unloads go to the table alone and never wait for a load's copy. */
|
||||
std::mutex lora_mu_;
|
||||
std::set<std::string> lora_targets_;
|
||||
/* --host-headroom-mib in bytes: the host RAM startup leaves free for the system when it
|
||||
* pins host memory (engine_bringup.cpp). 4 GiB suits a busy server; a small host wants to
|
||||
* leave less to make room for its tiers, which is why it is a flag and not a constant. */
|
||||
int64_t host_headroom_bytes() const { return cfg_.host_headroom_mib * ((int64_t)1 << 20); }
|
||||
/* Resolves --embedding-placement, --vision-tower-placement and --ngram-placement into Config
|
||||
* before the card is split (engine_bringup.cpp describes how auto chooses). `wfs` is every
|
||||
* rank's footprint, read for its towers. `host_late` is the pinned host memory startup
|
||||
|
||||
+36
-29
@@ -275,10 +275,11 @@ static void report_pool_refusal(int rank, int device, const Pools& pools, const
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ locked host memory */
|
||||
/* Host memory left free beside a table locked whole: the process's unpooled allocations, the
|
||||
* load's staging windows, and the page cache holding the container's hot pages. Without it the
|
||||
* kernel reclaims the files the engine reads, then the OOM killer runs. */
|
||||
static const int64_t kLockMargin = (int64_t)4 << 30;
|
||||
/* The margin (--host-headroom-mib, Engine::host_headroom_bytes): host memory left free beside a
|
||||
* table locked whole -- the process's unpooled allocations, the load's staging windows, and the
|
||||
* page cache holding the container's hot pages. Without it the kernel reclaims the files the
|
||||
* engine reads, then the OOM killer runs. It is dead RAM by design; a host that can reclaim
|
||||
* cheaply trades it for pool, cache or slots. */
|
||||
|
||||
/* Every level of every memory cgroup the process is in, leaf first: `visit(dir, room)` until it
|
||||
* returns false (cgroup_levels). /proc/self/cgroup reads "0::/path" on v2 and "N:memory:/path"
|
||||
@@ -309,12 +310,13 @@ static void memory_cgroups(const std::function<bool(const std::string&, int64_t)
|
||||
}
|
||||
|
||||
/* Whether `need` more bytes fit in host memory after `still` more this process will allocate
|
||||
* first, or why not. Checks MemAvailable; every memory cgroup from the process's own up to the
|
||||
* visible root (Docker's --memory, enforced by the OOM killer); and, for an mlock()ed copy
|
||||
* (`mlocks`), RLIMIT_MEMLOCK unless the process has CAP_IPC_LOCK. Pinned memory a card reads is a
|
||||
* driver userptr mapping, which RLIMIT_MEMLOCK does not count. An unreadable limit is ignored,
|
||||
* never guessed. */
|
||||
static bool lockable_room(int64_t need, int64_t still, bool mlocks, std::string* why) {
|
||||
* first and `margin` (--host-headroom-mib) stays free, or why not. Checks MemAvailable; every
|
||||
* memory cgroup from the process's own up to the visible root (Docker's --memory, enforced by
|
||||
* the OOM killer); and, for an mlock()ed copy (`mlocks`), RLIMIT_MEMLOCK unless the process has
|
||||
* CAP_IPC_LOCK. Pinned memory a card reads is a driver userptr mapping, which RLIMIT_MEMLOCK
|
||||
* does not count. An unreadable limit is ignored, never guessed. */
|
||||
static bool lockable_room(int64_t need, int64_t still, int64_t margin, bool mlocks,
|
||||
std::string* why) {
|
||||
long long locked_kb = 0;
|
||||
unsigned long long caps = 0;
|
||||
{
|
||||
@@ -334,43 +336,44 @@ static bool lockable_room(int64_t need, int64_t still, bool mlocks, std::string*
|
||||
return false;
|
||||
}
|
||||
if (const int64_t avail = meminfo_bytes("MemAvailable");
|
||||
avail >= 0 && avail - still - kLockMargin < need) {
|
||||
avail >= 0 && avail - still - margin < need) {
|
||||
*why = fmt("%s of memory is available, %s more is still to be allocated (the pinned host "
|
||||
"pools, the prefix cache's host tier, the checkpoint slots and the host "
|
||||
"activation arenas), and this wants %s with %s to spare",
|
||||
"activation arenas), and this wants %s with %s to spare "
|
||||
"(--host-headroom-mib)",
|
||||
humanb(avail).c_str(), humanb(still).c_str(), humanb(need).c_str(),
|
||||
humanb(kLockMargin).c_str());
|
||||
humanb(margin).c_str());
|
||||
return false;
|
||||
}
|
||||
bool fits = true;
|
||||
memory_cgroups([&](const std::string& dir, int64_t room) {
|
||||
if (room - still - kLockMargin >= need) return true;
|
||||
if (room - still - margin >= need) return true;
|
||||
*why = fmt("the memory cgroup at %s leaves %s, %s more is still to be allocated, "
|
||||
"and this wants %s with %s to spare", dir.c_str(),
|
||||
"and this wants %s with %s to spare (--host-headroom-mib)", dir.c_str(),
|
||||
humanb(room).c_str(), humanb(still).c_str(), humanb(need).c_str(),
|
||||
humanb(kLockMargin).c_str());
|
||||
humanb(margin).c_str());
|
||||
fits = false;
|
||||
return false;
|
||||
});
|
||||
return fits;
|
||||
}
|
||||
|
||||
/* The most lockable_room(need, still, false) admits, and in `limit` the bound that decides it.
|
||||
* INT64_MAX when no limit can be read. */
|
||||
static int64_t lockable_bytes(int64_t still, std::string* limit) {
|
||||
/* The most lockable_room(need, still, margin, false) admits, and in `limit` the bound that
|
||||
* decides it. INT64_MAX when no limit can be read. */
|
||||
static int64_t lockable_bytes(int64_t still, int64_t margin, std::string* limit) {
|
||||
int64_t most = INT64_MAX;
|
||||
*limit = "no readable memory limit";
|
||||
if (const int64_t avail = meminfo_bytes("MemAvailable"); avail >= 0) {
|
||||
most = avail - still - kLockMargin;
|
||||
most = avail - still - margin;
|
||||
*limit = fmt("%s of memory available, less %s still to be allocated and %s to spare",
|
||||
humanb(avail).c_str(), humanb(still).c_str(), humanb(kLockMargin).c_str());
|
||||
humanb(avail).c_str(), humanb(still).c_str(), humanb(margin).c_str());
|
||||
}
|
||||
memory_cgroups([&](const std::string& dir, int64_t room) {
|
||||
if (room - still - kLockMargin < most) {
|
||||
most = room - still - kLockMargin;
|
||||
if (room - still - margin < most) {
|
||||
most = room - still - margin;
|
||||
*limit = fmt("the memory cgroup at %s, which leaves %s, less %s still to be allocated "
|
||||
"and %s to spare", dir.c_str(), humanb(room).c_str(),
|
||||
humanb(still).c_str(), humanb(kLockMargin).c_str());
|
||||
humanb(still).c_str(), humanb(margin).c_str());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
@@ -470,7 +473,9 @@ int Engine::resolve_table_placement(const std::vector<VramFacts>& facts,
|
||||
const int64_t pools_still = (int64_t)cfg_.tp * cfg_.host_pool_mib * MiB +
|
||||
cfg_.prefix_cache_mib * MiB + host_late;
|
||||
std::string emb_room_why;
|
||||
auto emb_room = [&]() { return lockable_room(emb_pin, pools_still, false, &emb_room_why); };
|
||||
auto emb_room = [&]() {
|
||||
return lockable_room(emb_pin, pools_still, host_headroom_bytes(), false, &emb_room_why);
|
||||
};
|
||||
if (emb_max == 0) {
|
||||
if (emb == TablePlacement::Ram && emb_asked) {
|
||||
RAD_ERR("--embedding-placement ram: this model has no token embedding table that only "
|
||||
@@ -525,7 +530,7 @@ int Engine::resolve_table_placement(const std::vector<VramFacts>& facts,
|
||||
std::string why;
|
||||
const int64_t pin = (int64_t)cfg_.tp * align_up(tower_max, (int64_t)MiB);
|
||||
if (!lockable_room(pin, pools_still + (int64_t)cfg_.tp * cfg_.embedding_host_mib * MiB,
|
||||
false, &why)) {
|
||||
host_headroom_bytes(), false, &why)) {
|
||||
RAD_ERR("--vision-tower-placement ram: the encoder towers (%s a rank, pinned on every "
|
||||
"rank) cannot be held in host memory: %s. Use vram.", humanb(tower_max).c_str(),
|
||||
why.c_str());
|
||||
@@ -609,7 +614,8 @@ int Engine::resolve_table_placement(const std::vector<VramFacts>& facts,
|
||||
} else {
|
||||
std::string card_why, ram_why;
|
||||
const bool card = ng == TablePlacement::Auto && ngram_device && card_holds(&card_why);
|
||||
const bool room = !card && lockable_room(need, still, !ngram_device, &ram_why);
|
||||
const bool room =
|
||||
!card && lockable_room(need, still, host_headroom_bytes(), !ngram_device, &ram_why);
|
||||
if (ng == TablePlacement::Ram) {
|
||||
if (!room) {
|
||||
RAD_ERR("--ngram-placement ram: the n-gram table (%s) cannot be held in memory as "
|
||||
@@ -2763,7 +2769,7 @@ int Engine::size_checkpoint_store(int64_t slot, const char* what) {
|
||||
int64_t still = cfg_.prefix_cache_mib * ((int64_t)1 << 20);
|
||||
for (const auto& r : ranks_) still += arena_host_bytes(r->program);
|
||||
std::string limit;
|
||||
int64_t room = lockable_bytes(still, &limit);
|
||||
int64_t room = lockable_bytes(still, host_headroom_bytes(), &limit);
|
||||
if (!device_is_host()) {
|
||||
bool lifted = false;
|
||||
if (const int64_t cap = amdgpu_pin_cap(&lifted); cap > 0) {
|
||||
@@ -2906,7 +2912,8 @@ int Engine::configure_kv() {
|
||||
};
|
||||
if (!sized) return refuse("no host has");
|
||||
std::string why;
|
||||
if (!lockable_room(slot * n, 0, false, &why)) return refuse("does not fit: " + why);
|
||||
if (!lockable_room(slot * n, 0, host_headroom_bytes(), false, &why))
|
||||
return refuse("does not fit: " + why);
|
||||
if (ck_store_.open(slot, slot * n) != RAD_OK)
|
||||
return refuse(std::string("the host did not pin: ") + rad_dev_last_error());
|
||||
if (!sized_auto)
|
||||
|
||||
@@ -743,6 +743,7 @@ struct Config {
|
||||
* always resolve to bf16 and only add a third name. */
|
||||
std::string kv_cache_dtype = "bf16";
|
||||
int64_t host_pool_mib = 0;
|
||||
int64_t host_headroom_mib = 4096; /* --host-headroom-mib: RAM left free for the system at startup */
|
||||
/* File tier for weights: what fits in neither the VRAM slab nor the pinned host pool is read
|
||||
* from the container with O_DIRECT ahead of the ops that read it (a scheduled unit by the
|
||||
* exact prefetch, a routed expert a routed layer at a time). Off by default because disk
|
||||
|
||||
+9
-6
@@ -685,7 +685,8 @@ GiB a card at `--tp 2`. Under `ram` each rank pins its own shard in host memory
|
||||
`--host-pool-mib`, and the lookup reads a step's rows over the link, so the table costs no VRAM. The
|
||||
table is the model-level weight only `embed_lookup` reads. A model whose head is tied to it keeps it
|
||||
on the card (the head's GEMM would stream it whole every step), and so does a host that cannot pin
|
||||
it (available memory and memory cgroups, after the pools, with 4 GiB to spare); startup says which.
|
||||
it (available memory and memory cgroups, after the pools, with `--host-headroom-mib` to spare,
|
||||
default 4 GiB); startup says which.
|
||||
An explicit `ram` turns either case into a refusal. `disk` is refused: the lookup writes activations
|
||||
the card reads, which a host kernel reading the container cannot do.
|
||||
|
||||
@@ -711,9 +712,9 @@ from the container through a row cache with direct reads on the host; about half
|
||||
are first-seen, so steps wait on the drive. `ram` copies the table into host memory at load (12 to
|
||||
40 s more startup, depending on the page cache) and the card's gather kernel reads the pinned copy,
|
||||
so a step has no host work. `vram` puts all of it on every card. `ram` needs the table's size free
|
||||
after the pinned host pools and the prefix cache's host tier, with 4 GiB to spare, under every
|
||||
memory cgroup the process sits in, and refuses the start otherwise. `auto` takes the first of `vram`,
|
||||
`ram` and `disk` that holds the table. Without a device kernel for the gather (no libr4d) the table is
|
||||
after the pinned host pools and the prefix cache's host tier, with `--host-headroom-mib` to spare
|
||||
(default 4 GiB), under every memory cgroup the process sits in, and refuses the start otherwise.
|
||||
`auto` takes the first of `vram`, `ram` and `disk` that holds the table. Without a device kernel for the gather (no libr4d) the table is
|
||||
read on the host: `vram` is refused, and `ram` is a copy in locked huge pages, which also needs a
|
||||
memlock limit that large (`--ulimit memlock=-1` in Docker, `LimitMEMLOCK=infinity` under systemd).
|
||||
|
||||
@@ -1072,8 +1073,9 @@ running or not, and a conversation without a snapshot under its next prompt reus
|
||||
backoff keeps 9 for a 200K-token conversation at the default 2048-token interval, so 10 a sequence,
|
||||
80 at `--max-num-seqs 8`. The store is pinned for the life of the server, so `auto` takes at most an
|
||||
eighth of host memory (and never less than 8 slots where the host can pin them), and never more than
|
||||
the host can pin after the host pools, the host tier and the activation arenas. The startup log says
|
||||
what it chose; Flash-Next at `--tp 2 --max-num-seqs 8` on a host with 128 GB of RAM:
|
||||
the host can pin after the host pools, the host tier, the activation arenas and
|
||||
`--host-headroom-mib`. The startup log says what it chose; Flash-Next at `--tp 2
|
||||
--max-num-seqs 8` on a host with 128 GB of RAM:
|
||||
|
||||
```
|
||||
checkpoint slots: auto: 80 linear-state snapshot(s) of 113.50 MiB in pinned host memory (8.87 GiB),
|
||||
@@ -1267,6 +1269,7 @@ still verified by the adapter, so output is exact and only the acceptance rate c
|
||||
| `--gpu-headroom-mib N` | 96 | VRAM left unclaimed on every card |
|
||||
| `--kv-cache-dtype T` | bf16 | `bf16` or `fp8` |
|
||||
| `--host-pool-mib N` | 0 | pinned host tier (weights) |
|
||||
| `--host-headroom-mib N` | 4096 | host RAM left free for the system when startup pins host memory — kept for the unpooled allocations, staging and page cache (§4.3) |
|
||||
| `--embedding-placement WHERE` | ram | `ram` or `vram`: the token embedding pinned in host memory beside `--host-pool-mib` and read in place, or on the card (§4.3) |
|
||||
| `--ngram-placement WHERE` | auto | `auto`, `vram`, `ram` or `disk`: an n-gram table on the card, as a copy in RAM made at load and read by the card, or read from the container (§4.3) |
|
||||
| `--vision-tower-placement WHERE` | vram | `vram` or `ram`: the encoder towers (vision, and audio where a model has one) on the card, or pinned in host memory beside `--host-pool-mib` and read in place once an image (§4.3) |
|
||||
|
||||
@@ -894,6 +894,7 @@ utilisation fraction:
|
||||
|---|---|
|
||||
| `--gpu-headroom-mib` | VRAM left unclaimed on every card (default 96) |
|
||||
| `--host-pool-mib` | the pinned host tier |
|
||||
| `--host-headroom-mib` | host RAM left free for the system at startup (default 4096) |
|
||||
| `--weights-disk-tier` | the file tier for weights, read from the container; needs `O_DIRECT` |
|
||||
| `--max-model-len`, `--max-num-seqs` | the KV cache's bound |
|
||||
|
||||
|
||||
@@ -417,7 +417,8 @@ const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
{ "--max-num-seqs", { "4" } },
|
||||
{ "--max-model-len", { "4096" } }, { "--rope-scaling", { "yarn:4" } },
|
||||
{ "--gpu-headroom-mib", { "128" } }, { "--kv-cache-dtype", { "fp8" } },
|
||||
{ "--host-pool-mib", { "1024" } }, { "--embedding-placement", { "vram" } },
|
||||
{ "--host-pool-mib", { "1024" } }, { "--host-headroom-mib", { "2048" } },
|
||||
{ "--embedding-placement", { "vram" } },
|
||||
{ "--vision-tower-placement", { "ram" } }, { "--ngram-placement", { "disk" } },
|
||||
{ "--prefix-cache-mib", { "256" } }, { "--prefix-cache-ttl", { "60" } },
|
||||
{ "--placement", { "all_vram" } }, { "--checkpoint-interval", { "256" } },
|
||||
|
||||
Reference in new issue
Block a user