New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr), fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8 (read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1 / 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790, step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of 0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583), with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork. GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16 weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex (#598). Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card, +17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602). `draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a second at a 70k-token prompt on one card. Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash (#570). Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589). memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked model (#592); the first card listed chooses the architecture (#458). Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS packed on the card by baKon. Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552). Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and "minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541). rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up: shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer named after the retired fp8 formats. Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter (StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with NVFP4, int8 or 4-bit experts, is refused by name and needs converting again. Plugin ABI 44: out-of-tree plugins need to be rebuilt. Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol, @eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha, @dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
171 lines
5.8 KiB
C++
171 lines
5.8 KiB
C++
/* rowprefetch.cpp -- see rowprefetch.h. */
|
|
#include "runtime/rowprefetch.h"
|
|
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
#include <algorithm>
|
|
|
|
namespace rad {
|
|
|
|
bool row_gather_op(const std::string& op) {
|
|
return op == "embed_lookup" || op == "embed_lookup_q" || op == "embed_lookup_planes" ||
|
|
op == "embed_lookup_ggml";
|
|
}
|
|
|
|
int64_t row_prefetch_page() {
|
|
static const int64_t pg = [] {
|
|
const long v = ::sysconf(_SC_PAGESIZE);
|
|
return v > 0 ? (int64_t)v : (int64_t)4096;
|
|
}();
|
|
return pg;
|
|
}
|
|
|
|
bool row_id_at(const RadTensor& ids, int64_t i, int64_t* out) {
|
|
/* Row-major over the shape, through the strides (elements). */
|
|
int64_t off = i;
|
|
if (ids.rank >= 1) {
|
|
off = 0;
|
|
int64_t r = i;
|
|
for (int d = (int)ids.rank - 1; d >= 0; --d) {
|
|
const int64_t s = ids.shape[d] > 0 ? ids.shape[d] : 1;
|
|
off += (r % s) * ids.stride[d];
|
|
r /= s;
|
|
}
|
|
}
|
|
switch (ids.dtype) {
|
|
case RAD_I32: *out = (int64_t)((const int32_t*)ids.data)[off]; return true;
|
|
case RAD_U32: *out = (int64_t)((const uint32_t*)ids.data)[off]; return true;
|
|
case RAD_I64: *out = ((const int64_t*)ids.data)[off]; return true;
|
|
case RAD_I16: *out = (int64_t)((const int16_t*)ids.data)[off]; return true;
|
|
default: *out = 0; return false;
|
|
}
|
|
}
|
|
|
|
void row_runs_merge(std::vector<PageRun>* runs) {
|
|
std::vector<PageRun>& v = *runs;
|
|
if (v.size() < 2) return;
|
|
std::sort(v.begin(), v.end());
|
|
size_t w = 0;
|
|
for (size_t r = 1; r < v.size(); ++r) {
|
|
if (v[r].first <= v[w].second) {
|
|
if (v[r].second > v[w].second) v[w].second = v[r].second;
|
|
} else {
|
|
v[++w] = v[r];
|
|
}
|
|
}
|
|
v.resize(w + 1);
|
|
}
|
|
|
|
int64_t row_prefetch(const RowPrefetch& rp, const RadTensor& ids, int64_t m, const RadTensor* t,
|
|
RowPrefetchScratch* s) {
|
|
return row_page_runs(rp, ids, m, t, row_prefetch_page(), s, [](const PageRun& r) {
|
|
/* The table is read-only and mapped; a failure (a range the kernel will not read ahead)
|
|
* leaves the read to the fault, as without the hint. */
|
|
(void)::madvise((void*)r.first, (size_t)(r.second - r.first), MADV_WILLNEED);
|
|
});
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ beside the kernel */
|
|
|
|
bool row_pages_resident(const RowPrefetch& rp, const RadTensor& ids, int64_t m, const RadTensor* t) {
|
|
if (rp.n <= 0 || m <= 0 || !ids.data) return false;
|
|
const int64_t pg = row_prefetch_page();
|
|
const uintptr_t mask = ~(uintptr_t)(pg - 1);
|
|
const int64_t S = m < kRowAheadSample ? m : kRowAheadSample;
|
|
for (int64_t j = 0; j < S; ++j) {
|
|
int64_t id;
|
|
if (!row_id_at(ids, (2 * j + 1) * m / (2 * S), &id)) return false;
|
|
id -= rp.voff;
|
|
if (id < 0 || id >= rp.rows) continue;
|
|
for (int k = 0; k < rp.n; ++k) {
|
|
const uint8_t* base = (const uint8_t*)t[rp.opd[k]].data;
|
|
if (!base || rp.row_bytes[k] <= 0) continue;
|
|
const uintptr_t a = (uintptr_t)(base + id * rp.row_bytes[k]);
|
|
/* The row's first and last page. */
|
|
for (const uintptr_t p : { a & mask, (a + (uintptr_t)rp.row_bytes[k] - 1) & mask }) {
|
|
unsigned char v = 0;
|
|
if (::mincore((void*)p, (size_t)pg, &v) != 0 || !(v & 1)) return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
RowPrefetchWorker::~RowPrefetchWorker() {
|
|
if (!th_.joinable()) return;
|
|
stop_.store(true, std::memory_order_relaxed);
|
|
{
|
|
std::lock_guard<std::mutex> lk(mu_);
|
|
quit_ = true;
|
|
}
|
|
cv_.notify_all();
|
|
th_.join();
|
|
}
|
|
|
|
void RowPrefetchWorker::start(const RowPrefetch& rp, const RadTensor& ids, int64_t m,
|
|
const RadTensor* t) {
|
|
/* finish() ran for the previous job, so the helper is idle: the job is ours to write. */
|
|
rp_ = rp;
|
|
rp_.n = 0;
|
|
for (int k = 0; k < rp.n && k < kRowTablesMax; ++k) {
|
|
t_[k] = t[rp.opd[k]];
|
|
rp_.opd[k] = (int8_t)k;
|
|
rp_.row_bytes[k] = rp.row_bytes[k];
|
|
++rp_.n;
|
|
}
|
|
ids_ = ids;
|
|
m_ = m;
|
|
pages_ = 0;
|
|
stop_.store(false, std::memory_order_relaxed);
|
|
busy_.store(true, std::memory_order_release);
|
|
if (!th_.joinable()) {
|
|
s_.reserve(4096);
|
|
th_ = std::thread([this] { loop(); });
|
|
}
|
|
{
|
|
std::lock_guard<std::mutex> lk(mu_);
|
|
have_ = true;
|
|
}
|
|
cv_.notify_one();
|
|
}
|
|
|
|
void RowPrefetchWorker::loop() {
|
|
for (;;) {
|
|
{
|
|
std::unique_lock<std::mutex> lk(mu_);
|
|
cv_.wait(lk, [&] { return have_ || quit_; });
|
|
if (quit_) return;
|
|
have_ = false;
|
|
}
|
|
const int64_t pages = row_page_runs(rp_, ids_, m_, t_, row_prefetch_page(), &s_,
|
|
[&](const PageRun& r) {
|
|
if (stop_.load(std::memory_order_relaxed)) return false;
|
|
(void)::madvise((void*)r.first, (size_t)(r.second - r.first), MADV_WILLNEED);
|
|
return true;
|
|
});
|
|
pages_ = pages > 0 ? pages : 0;
|
|
/* Release: pages_ is published, and the ids are no longer read. */
|
|
busy_.store(false, std::memory_order_release);
|
|
}
|
|
}
|
|
|
|
int64_t RowPrefetchWorker::finish() {
|
|
stop_.store(true, std::memory_order_relaxed);
|
|
{
|
|
/* Not picked up yet (the kernel was quicker than the wake-up): take it back. */
|
|
std::lock_guard<std::mutex> lk(mu_);
|
|
if (have_) {
|
|
have_ = false;
|
|
busy_.store(false, std::memory_order_release);
|
|
return 0;
|
|
}
|
|
}
|
|
/* The helper checks stop_ before every hint, so this waits at most one madvise plus the walk
|
|
* to the next flush of the scratch (a few thousand ids of page arithmetic). */
|
|
while (busy_.load(std::memory_order_acquire)) std::this_thread::yield();
|
|
return pages_;
|
|
}
|
|
|
|
} /* namespace rad */
|