Archived
New models and formats: - IQR for Qwen3.8-27B: weights on the int8 grid under GPTQ, a trellis down each GPTQ column (IQR-V2), and IQR-V3, a computed trellis code under one scale a row, kept at its codes' width in VRAM and decoded in the GEMM; 15 IQR-V3 recipes from ~2 to ~7 bits a weight (data/recipes/q38-27b-*-v3.recipe, docs/IQR.md) - libhalo: a kernel library for Strix Halo (gfx1151), preferred there over libr3d - Nemotron 3.5 Embed 1B and 8B (nemotron35_embed): text and image embeddings through a Pixtral tower, on the card and on the CPU - Nemotron 3.5 Rerank 8B - /v1/systemone: Cloudflare's clef and clef-flash, Convai Innovations' Laya and Mica beside LiquidAI d1; scored steps read the candidates' logits from the head table with no lm_head pass - LFM2's 8-bit trunk: block-fp8 or int8 linears with the fused producers, and the d1-3B recipe - DeepSeek-V4.1's reply format with DSML tool calls and typed argument tags Weights on the drive: - The file tier reads only the experts the pass routes rows to; the draft head's weights stay in the host pool - A hot VRAM cache for routed experts read off the drive, reads deposited straight into free host pool slots, and copyless evictions; the file tier's counters are now ssd_* - GLM-5 Next shards its routed experts by expert, not by width, so they can live on the drive - The stall watch counts drive reads as progress, and the DMA lane's room check reads the lane's own completion fence Quantisation tooling: - --calib-corpus, --calib-dir and --calib-layers record each linear's input Hessian; beside --kld-record the reference's own run records them - --kld-top N records a sparse KL reference (the N most likely tokens and the tail's mass) - GPTQ in a third of the time with the same codes, trellis GPTQ on the card, vector codebooks with coordinate descent, and rad-convert --reuse repeated, each container supplying what the earlier ones lack Speculation: - Prompt lookup alone (--spec-ngram K, --spec-ngram-min/-max): each sequence keeps an index of its n-grams, and a proposal is verified only when its measured step cost says it pays; --draft-window adaptive follows it Speed: - IQR decode: the narrow tile splits K for four times the int8 tile's waves and folds each 128-K block once; at 8 tokens down and the output projections run in 0.61-0.82x and 0.70-0.92x FP8's time (2-6 bits); IQ6R-S-V3 with its DFlash2 drafter steps in 26.3 ms at TP2, against 29.4 ms before and FP8's 27.3 - Qwen MXFP4 feed-forward: the gated fold up to 16 rows, not 8 - libr4d: the gated prefill fold, the short-prompt split row, and the rows forms of rmsnorm and rope; KLATE again for the head-256 gqa6 paged prefill; gram_accum on the matrix cores Features: - /health, /v1/health and /ping answer 503 with "status": "stuck" once the device has advanced nothing for a minute or a queue has faulted, so a supervisor can restart a wedged server (#356) - --image-gen-max-pixels and --image-gen-max-refs size an image generator's buffers (#344) - The startup report lists only the options not at their default, with a count; -v lists all (#250) - --preempt-wait-ms bounds how long a preempted prefill waits for its whole-recompute room - --placement layer_offload spills dense layers so one --max-model-len sequence fits - Startup refuses amdgpu with CWSR off and says how to fix it; --proceed-with-incompatible-configuration starts anyway under an UNSUPPORTED banner Fixes: - The n-gram read-ahead hands each row to the reader once and reads only as far ahead as the row cache holds, and pauses while decode reads: about one drive read a row instead of two (#355) - A file-tier window reads each of its runs once, not once a run per run - The decode split law's verify floor is bounded by the batch's workgroups: max_seqs 256 no longer declares 64x the scratch (#342) - A prefetch DMA list's mark stays out of the signal pool until the engine has read it, and a prefill stage copies only the blocks its own tables name (#343) - The split-KV row sum is read with fetch-inactive (#328) - LFM2 on the host backend: libref and libavx serve the row-form ops it declares (#348) - The preempted-prefill gate skips a KV group that holds no blocks (#352) - Every request entry point bounded, gated and sanitised (JSON depth, invalid UTF-8, control bytes in the log, the dashboard's CSP, cross-origin browsers on the loopback-only routes); a prompt id outside the vocabulary refused at admission; --api-key "" refused at startup - The telemetry the HTTP thread reads is atomic - An RMS norm row no longer depends on how many rows its launch carries; prefill attention's rescale is decided by live rows only - A --kld-record prefill chunk that finishes no sequence gets its logits on a tied-head model - A kernel's lazily made counter block is zeroed outside the lock other ranks take (a TP2 first-step hang) Changes: Plugin ABI 32. Every plugin exports a layout fingerprint of the ABI structs and the loader refuses a plugin without it or with another (#302), so out-of-tree plugins must be rebuilt. Appended: RadBuildCtx calib_* and gen_max_*, RadArchProbe gen_max_*, RadBatch score_only and plugin_words, RadDeviceProps::unified, RadChatFormat arg_json_value_prefix.
188 lines
8.1 KiB
C++
188 lines
8.1 KiB
C++
/* rad_internal.h -- shared by everything under core/, tools/ and tests/. Not installed and not
|
|
* visible to plugins, which see only abi/. C++20 is fine here.
|
|
*/
|
|
#pragma once
|
|
#include "rad_abi.h"
|
|
#include "rad_device.h"
|
|
#include "rad_builder.h"
|
|
#include "rad_runtime.h"
|
|
#include "rad_format.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstdarg>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
namespace rad {
|
|
|
|
/* ------------------------------------------------------------------ logging */
|
|
/* Normal operation is a few lines. Everything verbose is off by default (spec §16). */
|
|
enum class Log { Error = 0, Warn = 1, Info = 2, Debug = 3, Trace = 4 };
|
|
|
|
void log_set_level(Log l);
|
|
Log log_level();
|
|
void log_emit(Log l, const char* file, int line, const char* fmt, ...)
|
|
__attribute__((format(printf, 4, 5)));
|
|
/* rad_mono_ns of the last line written at any level; StallWatch reads it as progress. 0 before
|
|
* the first. */
|
|
uint64_t log_last_line_ns();
|
|
|
|
/* A copy safe to interpolate into a log line: every byte below 0x20 but '\t', and DEL, becomes
|
|
* '?'. Client-controlled text reaches the log -- session labels, echoed request fields -- and an
|
|
* unfiltered newline forges a line while an ESC sequence drives the terminal that reads it.
|
|
* Multi-byte UTF-8 is left alone; only control bytes are replaced. */
|
|
std::string log_sanitize(const std::string& s);
|
|
|
|
/* Rank tags on log lines. Per-rank components (pools, planner, mover, sampler) print the same
|
|
* line once per rank, so under TP each line needs its rank. LogRank sets the tag as a scope
|
|
* because the printers are several layers down, where threading a rank argument through every
|
|
* call is error-prone. Off unless log_rank_tags(true): at tp 1, and in tools, there is one rank. */
|
|
void log_rank_tags(bool on);
|
|
|
|
class LogRank {
|
|
public:
|
|
explicit LogRank(int rank);
|
|
~LogRank();
|
|
LogRank(const LogRank&) = delete;
|
|
LogRank& operator=(const LogRank&) = delete;
|
|
private:
|
|
int prev_;
|
|
};
|
|
|
|
#define RAD_LOG(lvl, ...) \
|
|
do { if ((int)::rad::Log::lvl <= (int)::rad::log_level()) \
|
|
::rad::log_emit(::rad::Log::lvl, __FILE__, __LINE__, __VA_ARGS__); } while (0)
|
|
|
|
#define RAD_ERR(...) RAD_LOG(Error, __VA_ARGS__)
|
|
#define RAD_WARN(...) RAD_LOG(Warn, __VA_ARGS__)
|
|
#define RAD_INFO(...) RAD_LOG(Info, __VA_ARGS__)
|
|
#define RAD_DEBUG(...) RAD_LOG(Debug, __VA_ARGS__)
|
|
#define RAD_TRACE(...) RAD_LOG(Trace, __VA_ARGS__)
|
|
|
|
/* RAD_LOG with the level as a runtime value, for sites where the level depends on what was
|
|
* found. */
|
|
#define RAD_LOG_AT(lvl, ...) \
|
|
do { ::rad::Log _l = (lvl); \
|
|
if ((int)_l <= (int)::rad::log_level()) \
|
|
::rad::log_emit(_l, __FILE__, __LINE__, __VA_ARGS__); } while (0)
|
|
|
|
/* Propagate a negative status, logging where it came from. */
|
|
#define RAD_TRY(expr) \
|
|
do { int _s = (expr); \
|
|
if (_s < 0) { RAD_DEBUG("%s -> %s", #expr, rad_strerror(_s)); return _s; } } while (0)
|
|
|
|
/* An unrecoverable condition: a device fault, a corrupt container, an invariant broken. Prints
|
|
* and exits non-zero rather than serving from a wedged queue (spec §17). */
|
|
[[noreturn]] void fatal(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
/* ------------------------------------------------------------------ small helpers */
|
|
std::string fmt(const char* f, ...) __attribute__((format(printf, 1, 2)));
|
|
|
|
inline int64_t align_up(int64_t v, int64_t a) { return (v + a - 1) / a * a; }
|
|
|
|
/* Human-readable byte counts, for every report that prints a size. */
|
|
std::string humanb(int64_t bytes);
|
|
|
|
/* The one monotonic clock for all elapsed-time logic. The idle-session tiers stamp an entry on
|
|
* use and compare against the stamp in another translation unit, so both sides must use the same
|
|
* clock. Monotonic so an NTP step cannot age entries. */
|
|
uint64_t rad_mono_ns();
|
|
|
|
/* Split on spaces, tabs and commas: the encoding of RAD_C_IN's set. */
|
|
std::vector<std::string_view> split_ws(std::string_view s);
|
|
|
|
/* The strings joined with `sep` between them. */
|
|
inline std::string join(const std::vector<std::string>& v, const char* sep = ", ") {
|
|
std::string s;
|
|
for (size_t i = 0; i < v.size(); ++i) { if (i) s += sep; s += v[i]; }
|
|
return s;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ geometry */
|
|
/* A resolved parameter set: the geometry after ranges are collapsed to a band's upper bound.
|
|
* Owns its strings, because a RadParam's char* may point into a plugin the core outlives. */
|
|
class Geometry {
|
|
public:
|
|
Geometry() = default;
|
|
|
|
/* Every write keeps the RadParam view current; it is never built lazily on read. A lazy
|
|
* rebuild from a const reader is a write, and concurrent readers exist (the sizing declares
|
|
* in Engine::probe_arena_levels read the same geometries in parallel). So params() writes
|
|
* nothing, and an unwritten Geometry is safe to read from any number of threads.
|
|
*
|
|
* The view holds char* into this object's strings. A copy rebuilds its own view. A move
|
|
* takes the view too, since the vectors hand over their arrays and the pointers stay valid;
|
|
* the source is cleared, view included, leaving a valid empty geometry. */
|
|
Geometry(const Geometry& o)
|
|
: keys_(o.keys_), svals_(o.svals_), ivals_(o.ivals_), dvals_(o.dvals_), kinds_(o.kinds_) {
|
|
rebuild();
|
|
}
|
|
|
|
Geometry& operator=(const Geometry& o) {
|
|
if (this != &o) {
|
|
keys_ = o.keys_; svals_ = o.svals_; ivals_ = o.ivals_; dvals_ = o.dvals_;
|
|
kinds_ = o.kinds_;
|
|
rebuild();
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Geometry(Geometry&& o) noexcept
|
|
: keys_(std::move(o.keys_)), svals_(std::move(o.svals_)),
|
|
view_(std::move(o.view_)), ivals_(std::move(o.ivals_)),
|
|
dvals_(std::move(o.dvals_)), kinds_(std::move(o.kinds_)) {
|
|
o.clear();
|
|
}
|
|
|
|
Geometry& operator=(Geometry&& o) noexcept {
|
|
if (this != &o) {
|
|
keys_ = std::move(o.keys_); svals_ = std::move(o.svals_);
|
|
view_ = std::move(o.view_);
|
|
ivals_ = std::move(o.ivals_); dvals_ = std::move(o.dvals_);
|
|
kinds_ = std::move(o.kinds_);
|
|
o.clear();
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
void set_i(std::string_view k, long long v);
|
|
void set_s(std::string_view k, std::string_view v);
|
|
/* Floats (eps, rope theta, an attention scale) reach RadArgs.p but are never matched on; see
|
|
* constraint_holds(). */
|
|
void set_f(std::string_view k, double v);
|
|
bool get_i(std::string_view k, long long* out) const;
|
|
bool get_f(std::string_view k, double* out) const;
|
|
const char* get_s(std::string_view k) const;
|
|
bool has(std::string_view k) const;
|
|
|
|
/* A view suitable for RadArgs.p. Valid while this object lives and is not written. */
|
|
const RadParam* params() const { return view_.data(); }
|
|
int n_params() const { return (int)view_.size(); }
|
|
|
|
std::string str() const; /* "M=64 N=8192 K=5120 dtype=w4a8", for diagnostics */
|
|
|
|
private:
|
|
std::vector<std::string> keys_, svals_;
|
|
std::vector<RadParam> view_;
|
|
size_t slot(std::string_view k, int kind); /* find or append k, set its kind */
|
|
void rebuild();
|
|
void clear() noexcept {
|
|
keys_.clear(); svals_.clear(); view_.clear(); ivals_.clear(); dvals_.clear();
|
|
kinds_.clear();
|
|
}
|
|
std::vector<long long> ivals_;
|
|
std::vector<double> dvals_;
|
|
std::vector<int> kinds_;
|
|
};
|
|
|
|
/* Whether the geometry satisfies the constraint; the one place the matching rule lives. A
|
|
* constraint on a float key never holds (get_i and get_s miss RAD_P_F64 slots): a tolerance is
|
|
* not a predicate, and a kernel that discriminates on eps that precisely has a bug. */
|
|
bool constraint_holds(const RadConstraint& c, const Geometry& g);
|
|
/* Why not, for the selection table's miss column (spec §16). */
|
|
std::string constraint_why(const RadConstraint& c, const Geometry& g);
|
|
|
|
} /* namespace rad */
|