mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 08:18:54 +00:00
The chunk (prompt tokens per forward step, default 512) limited prefill: RTX 5090, strata-inkling --bench, one stream, 4K prompt, SQ-20: 512 -> 8.1K tok/s,
1024 -> 9.5K, 2048 -> 10.5K, 4096 -> 10.7K (16K prompt 7.0K -> 8.9K at 2048, 32K 6.1K -> 7.5K); UD-Q4_K_XL 4.07K -> 4.47K at 2048, flat after; nothing
is lost up to 8192. A bigger chunk costs working memory: the runner and K/V took 1460 / 1822 / 2710 / 4558 MiB at chunk 512 / 1024 / 2048 / 4096 on an
RTX 4090 (SQ-20 all resident, 5255 MiB free after the experts; the engine caps max_batch at 4096) and 1440 / 1804 MiB at 512 / 1024 on an RTX 3060 Ti
8 GB, where 2048 did not fit and the halve-on-fail retry (859276060) brought it back to 1024.
- strata/core/ink_chunk.hpp: ink_auto_chunk(free_after_load_mib, slots): the largest of 2048 / 1024 that fits (the memory the runner takes at that chunk
+ 1500 MiB margin for K/V growth, the drafter and the desktop), else 512; capped by the slot count: 2048 for 1-3 slots, 1024 for 4-15, 512 from 16.
The experts are placed first, with their reserve computed for chunk 512, so a bigger chunk never displaces an expert: a hybrid card with little left
keeps 512, a card whose experts are all resident gets 2048. Test ink_chunk_test (the 4090 and 3060 Ti ledgers, the cap, monotone in memory).
- InkCudaBackend::init resolves the chunk after the experts are placed and logs "[InkCUDA] prefill chunk N (auto: M MiB free after the experts, S slot(s);
--chunk N sets it)"; effective_chunk() reports what the runner really got; ink_serve (token_budget) and --bench use it. --chunk N still wins,
STRATA_INK_CHUNK_AUTO=0 keeps 512. HIP, SYCL, Metal and CPU keep 512 (BackendOpts::chunk_auto is read only by the CUDA backend).
- The slot cap comes from the mixed-work case, 32 slots, a 16K prompt arriving among 31 decoders, longest wait of a decoding slot at chunk 512 / 1024 /
2048: RTX 3060 Ti 8 GB (SQ-10 hybrid) 2322 / 2210 / 43,424 ms (the long prompt read in 91 / 56 / 218 s); RTX 4090 (SQ-20 resident) 2096 / 3974 ms with the
long prompt at 108 / 110 s; RTX 3060 12 GB 3897 ms at 512, 2804 ms at 1024. Throughput of 32 requests of 512 tokens at once (prompt + output tok/s):
8 GB 55 (512) / 83 (1024) / 125 (2048); 12 GB 65 / 95; 4090 43 / 51. These ran on boxes whose CPUs were loaded by other jobs: relative numbers only.
- Equivalence: RTX 4090 SQ-20 (resident): greedy tokens identical between the auto chunk (2048) and --chunk 512 for prompts of 15, 200, 3000, 16000 and 30000
tokens; serve prefill 3000 / 16000 / 30000 tokens 2788 / 2979 / 4608 -> 3088 / 3247 / 5053 tok/s. Hybrid SQ-10 (8 and 12 GB): identical up to 3000
tokens, different at 16K (and 30K on the 8 GB card) between the two chunks, with the 512 runs of the two cards also differing from each other (expert
promotion of the hybrid path); a same-chunk repeat is queued.
- No OOM and no retry in any gate run (8 / 12 / 24 GB, 1 and 32 slots).
53 lines
2.7 KiB
C++
53 lines
2.7 KiB
C++
// The prefill chunk strata-inkling picks without --chunk (strata/core/ink_chunk.hpp): the memory left after the experts decides, the slot count caps it.
|
|
#include "strata/core/ink_chunk.hpp"
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace strata::core;
|
|
|
|
namespace {
|
|
int failed = 0;
|
|
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
|
|
} // namespace
|
|
|
|
int main() {
|
|
// measured: RTX 3060 Ti 8 GB, SQ-10, 2955 MiB free after the experts: 512 (chunk 1024 would take 1804 MiB and leave 1151 MiB, below the margin)
|
|
CHECK(ink_auto_chunk(2955.0, 1) == 512);
|
|
// the ledger of an RTX 4090 (SQ-20, all resident, 5255 MiB free after the experts): runner + K/V took 1460 / 1822 / 2710 / 4558 MiB at 512 / 1024 / 2048 / 4096
|
|
CHECK(ink_chunk_need_mib(4096) - ink_chunk_need_mib(512) > (4558.0 - 1460.0) * 0.97);
|
|
CHECK(ink_chunk_need_mib(4096) - ink_chunk_need_mib(512) < (4558.0 - 1460.0) * 1.06);
|
|
CHECK(ink_chunk_need_mib(2048) - ink_chunk_need_mib(512) > (2710.0 - 1460.0) * 0.97);
|
|
CHECK(ink_chunk_need_mib(1024) - ink_chunk_need_mib(512) > (1822.0 - 1460.0));
|
|
CHECK(ink_auto_chunk(5255.0, 1) == 2048); // that 4090: 2048 leaves 2545 MiB
|
|
// a card that kept room: bigger chunks, one step at a time; never above 2048 by itself (4096 is for --chunk)
|
|
CHECK(ink_auto_chunk(3500.0, 1) == 1024);
|
|
CHECK(ink_auto_chunk(4400.0, 1) == 2048);
|
|
CHECK(ink_auto_chunk(6200.0, 1) == 2048);
|
|
CHECK(ink_auto_chunk(12000.0, 1) == 2048); // an RTX 5090 with every expert resident
|
|
CHECK(ink_auto_chunk(1.0e9, 1) == 2048);
|
|
// never below the old default, never from an unknown amount
|
|
CHECK(ink_auto_chunk(0.0, 1) == 512);
|
|
CHECK(ink_auto_chunk(-1.0, 1) == 512);
|
|
// slots cap the chunk: a decoding slot waits for the prefill tokens of the others in the same step (8 GB card: 43 s stall at 2048 with 32 slots)
|
|
CHECK(ink_auto_chunk(12000.0, 2) == 2048);
|
|
CHECK(ink_auto_chunk(12000.0, 3) == 2048);
|
|
CHECK(ink_auto_chunk(12000.0, 4) == 1024);
|
|
CHECK(ink_auto_chunk(12000.0, 8) == 1024);
|
|
CHECK(ink_auto_chunk(12000.0, 15) == 1024);
|
|
CHECK(ink_auto_chunk(12000.0, 16) == 512); // heavy parallel keeps the old chunk
|
|
CHECK(ink_auto_chunk(12000.0, 32) == 512);
|
|
CHECK(ink_auto_chunk(12000.0, 64) == 512);
|
|
CHECK(ink_auto_chunk(3500.0, 8) == 1024);
|
|
CHECK(ink_auto_chunk(2000.0, 8) == 512);
|
|
// monotone: more free memory never gives a smaller chunk
|
|
int last = 0;
|
|
for (double f = 0.0; f <= 20000.0; f += 50.0) {
|
|
const int c = ink_auto_chunk(f, 1);
|
|
CHECK(c >= last);
|
|
last = c;
|
|
}
|
|
if (failed) { std::fprintf(stderr, "%d check(s) failed\n", failed); return 1; }
|
|
std::puts("ink_chunk_test: ok");
|
|
return 0;
|
|
}
|