Archived
radiance 1.3.0
- #47: llama-server's request fields, routes and sampler order, and /props (with baKon's model entry: max_model_len, root and capabilities on /v1/models, and /v1/models/:id) - new APIs: Anthropic's Messages API (/v1/messages), OpenAI's Responses API (/v1/responses), llama-server's /completion and /infill, logprobs (OpenAI's logprobs and top_logprobs, up to 20; llama-server's n_probs), OpenAI's legacy `functions`, and X-Api-Key beside the bearer key - #4: --model takes a Hugging Face repo id (owner/name), fetched before startup into ~/.cache/radiance/hf or --download-dir and checked for changes at every start (redxherring) - #46: --tp 3 --tp-wire wht6 serves -- a three-rank two-shot all-reduce with uneven shards and the tiered-int8 wire over it (baKon); scripts/cardclock.py names what holds each card's clock under load (baKon) - CPU-only serving works again; --kernels names the kernel libraries to load; a model the loaded libraries cannot fully serve refuses at startup instead of failing its first request; --vram-kv-mib and --vram-weights-mib are gone (the split is automatic) - --embedding-placement ram is the default, and `auto` is gone - #40: Swift 1.5 recipes; rad-convert reads which shard holds a tensor from the index - #53: the pinned host pool gets huge pages where shmem THP is off; #57: a crash on video with an odd frame width is fixed
This commit is contained in:
1 parent
6a2ee986d6
commit
89cee7ce41
107 files changed
+6849
-1091
No files matched your search
@@ -168,6 +168,7 @@ int ref_sample_merge_topk (const RadArgs*, RadStream);
|
||||
int ref_sample_mask (const RadArgs*, RadStream);
|
||||
int ref_sample_pick (const RadArgs*, RadStream);
|
||||
int ref_sample_argmax (const RadArgs*, RadStream);
|
||||
int ref_sample_logprobs (const RadArgs*, RadStream);
|
||||
|
||||
/* ============================== OPERAND DESCRIPTION ==============================
|
||||
*
|
||||
@@ -286,6 +287,7 @@ REF_SHAPE_FN(ref_sample_merge_topk);
|
||||
REF_SHAPE_FN(ref_sample_mask);
|
||||
REF_SHAPE_FN(ref_sample_pick);
|
||||
REF_SHAPE_FN(ref_sample_argmax);
|
||||
REF_SHAPE_FN(ref_sample_logprobs);
|
||||
|
||||
} /* extern "C" */
|
||||
#endif /* RAD_REF_OPS_H */
|
||||
@@ -601,6 +601,12 @@ static const RadParamSpec pTopk[] = { P_INT("M"), P_INT("n_vocab"), P_INT
|
||||
static const RadOperandSpec oTopk[] = { OPD("logits"), OPD("params"),
|
||||
OUT("cand_idx"), OUT("cand_val"), OUT_O("pairs") };
|
||||
static const RadOperandSpec oArgmax[] = { OPD("logits"), OPD("params"), OUT("token") };
|
||||
/* `stats` is [M, 2 + 2k]: max, sum of exp(l - max), then k (id, logit) pairs. `k` is geometry --
|
||||
* the sampler declares the one width every request's top_logprobs fits in -- and `vocab_off` is
|
||||
* sample_topk's, for global ids under a split vocabulary. */
|
||||
static const RadParamSpec pLogprobs[] = { P_INT("M"), P_INT("n_vocab"), P_INT("k"),
|
||||
P_INTO("vocab_off") };
|
||||
static const RadOperandSpec oLogprobs[] = { OPD("logits"), OPD("params"), OUT("stats") };
|
||||
static const RadOperandSpec oNarrow[] = { INOUT("cand_idx"), INOUT("cand_val"), OPD("params") };
|
||||
static const RadOperandSpec oPick[] = { OPD("cand_idx"), OPD("cand_val"), OPD("params"),
|
||||
OUT("token") };
|
||||
@@ -1035,6 +1041,9 @@ static const RadOpSchema kSchemas[] = {
|
||||
"same descending form the single-rank path produces. Token ids in `gathered` are already "
|
||||
"global." },
|
||||
{ "sample_argmax", ARR(pMVocab), ARR(oArgmax), "Greedy, ties to the lower token id." },
|
||||
{ "sample_logprobs", ARR(pLogprobs), ARR(oLogprobs),
|
||||
"For a row with RAD_SP_LOGPROBS: the raw logits' max, sum of exp(l - max) and k largest as (id, "
|
||||
"logit) pairs, descending, ties to the lower id. Other rows are not written." },
|
||||
};
|
||||
|
||||
/* ================================================================== the kernel table */
|
||||
@@ -1253,6 +1262,8 @@ SIMPLE("ref_sample_mask", "sample_mask", "sample", "grammar bitmask application"
|
||||
SIMPLE("ref_sample_pick", "sample_pick", "sample", "seeded inverse-CDF draw", DT_FLOAT,
|
||||
ref_sample_pick),
|
||||
SIMPLE("ref_sample_argmax", "sample_argmax", "sample", "greedy pick", DT_FLOAT, ref_sample_argmax),
|
||||
SIMPLE("ref_sample_logprobs", "sample_logprobs", "sample", "the raw distribution's summary",
|
||||
DT_FLOAT, ref_sample_logprobs),
|
||||
SIMPLE("ref_sample_dry", "sample_dry", "sample", "DRY repetition-suffix penalty", DT_FLOAT,
|
||||
ref_sample_dry),
|
||||
SIMPLE("ref_sample_typical", "sample_typical", "sample", "locally typical narrowing in place",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
|
||||
#include "rad_sample.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -616,6 +617,58 @@ int ref_sample_argmax(const RadArgs* a, RadStream) {
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ sample_logprobs */
|
||||
/* THE RAW DISTRIBUTION'S SUMMARY, for a row that asks for logprobs (RAD_SP_LOGPROBS): the row's
|
||||
* maximum, the sum of exp(l - max) over it, and its k largest as (id, logit) pairs, descending,
|
||||
* ties to the lower id, ids as floats (exact below 2^24). Read off the logits before any sampling
|
||||
* stage has touched them, which is the distribution OpenAI's and llama-server's logprobs report.
|
||||
* A row without the flag is not written. Under a split vocabulary the ids are global
|
||||
* (+ `vocab_off`) and the host merges the ranks' summaries; a slot past the row's width is id -1,
|
||||
* logit -infinity. The sum is taken in double here: this is the oracle. */
|
||||
int ref_sample_logprobs(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 3)) return RAD_E_INVAL;
|
||||
const RadTensor *lg = &a->t[0], *pr = &a->t[1], *st = &a->t[2];
|
||||
const int64_t n_vocab = p_int(a, "n_vocab", lg->rank >= 2 ? lg->shape[lg->rank - 1] : 0);
|
||||
const int64_t k = p_int(a, "k", 0);
|
||||
const int64_t voff = p_int(a, "vocab_off", 0);
|
||||
if (n_vocab <= 0 || k <= 0) return RAD_E_SHAPE;
|
||||
const int64_t M = numel(lg) / n_vocab;
|
||||
const int64_t w = 2 + 2 * k;
|
||||
if (M <= 0 || numel(st) < M * w) return RAD_E_SHAPE;
|
||||
Rows R;
|
||||
RAD_REF_TRY(rows_of(pr, M, &R));
|
||||
|
||||
#pragma omp parallel for schedule(static)
|
||||
for (int64_t m = 0; m < M; ++m) {
|
||||
if (!(R.p[m].flags & RAD_SP_LOGPROBS)) continue;
|
||||
const int64_t lb = rowoff(lg, m, n_vocab), ls = laststride(lg);
|
||||
const int64_t sb = rowoff(st, m, w), ss = laststride(st);
|
||||
float mx = -INFINITY;
|
||||
for (int64_t i = 0; i < n_vocab; ++i) mx = std::max(mx, ldt(lg, lb + i * ls));
|
||||
double sum = 0.0;
|
||||
for (int64_t i = 0; i < n_vocab; ++i) sum += std::exp((double)ldt(lg, lb + i * ls) - mx);
|
||||
std::vector<std::pair<float, int64_t>> top;
|
||||
top.reserve((size_t)k + 1);
|
||||
auto above = [](const std::pair<float, int64_t>& x, const std::pair<float, int64_t>& y) {
|
||||
return x.first > y.first || (x.first == y.first && x.second < y.second);
|
||||
};
|
||||
for (int64_t i = 0; i < n_vocab; ++i) {
|
||||
const std::pair<float, int64_t> e{ ldt(lg, lb + i * ls), i };
|
||||
if ((int64_t)top.size() == k && !above(e, top.back())) continue;
|
||||
top.insert(std::upper_bound(top.begin(), top.end(), e, above), e);
|
||||
if ((int64_t)top.size() > k) top.pop_back();
|
||||
}
|
||||
stt(st, sb, mx);
|
||||
stt(st, sb + ss, (float)sum);
|
||||
for (int64_t j = 0; j < k; ++j) {
|
||||
const bool have_j = j < (int64_t)top.size();
|
||||
stt(st, sb + (2 + 2 * j) * ss, have_j ? (float)(top[(size_t)j].second + voff) : -1.0f);
|
||||
stt(st, sb + (3 + 2 * j) * ss, have_j ? top[(size_t)j].first : -INFINITY);
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ sample_merge_topk */
|
||||
/* THE VOCAB-PARALLEL MERGE. lm_head is vocab-sharded, so each rank runs top-k over ITS OWN shard
|
||||
* and the candidate sets are all-gathered -- k * world_size pairs, 2 KiB at k=64 and world_size=4,
|
||||
|
||||
@@ -1946,6 +1946,18 @@ int ref_sample_argmax_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
return o.finish("sample_argmax", operand, out);
|
||||
}
|
||||
|
||||
int ref_sample_logprobs_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
int64_t M = 0, nv = 0;
|
||||
if (sample_vocab(p, n_p, &M, &nv) < 0) return RAD_E_UNSUPPORTED;
|
||||
const int64_t k = gi(p, n_p, "k", 0);
|
||||
if (k <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t((uint32_t)RAD_F32, { M, nv }); /* logits */
|
||||
o.t((uint32_t)RAD_F32, { M, sample_params_words() }); /* params */
|
||||
o.t((uint32_t)RAD_F32, { M, 2 + 2 * k }); /* stats */
|
||||
return o.finish("sample_logprobs", operand, out);
|
||||
}
|
||||
|
||||
int ref_sample_topk_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
int64_t M = 0, nv = 0;
|
||||
if (sample_vocab(p, n_p, &M, &nv) < 0) return RAD_E_UNSUPPORTED;
|
||||
|
||||
Reference in new issue
Block a user