Merge main into laya-arch-plugin

This commit is contained in:
Brandon Bertelsen committed 2026-10-29 13:45:18 -04:00
commit ec243c2a7d
189 files changed
+11212 -7060

No files matched your search

+2
View File
@@ -123,6 +123,7 @@ public:
int op_declared (const char* op) const;
int decl_name_map(const RadNameMap* m);
int declare_logits(rad_buf b);
int declare_scores(rad_buf hidden, rad_weight table);
int declare_pooled(rad_buf b);
int declare_plugin_words(int64_t max_words);
int declare_drafter(const RadDrafterDecl* d);
@@ -131,6 +132,7 @@ public:
int lora_alias(const char* native, const char* from, const char* to, int64_t from_lo,
int64_t from_hi, int64_t to_lo);
int drafter_short_block(int64_t block);
int drafter_tree(rad_buf parents);
int declare_encoder(const RadEncoderDecl* d);
int declare_generator(const RadGeneratorDecl* d);
int declare_audio_generator(const RadAudioGenDecl* d);
+83 -5
View File
@@ -1134,6 +1134,30 @@ int Builder::decl_name_map(const RadNameMap* m) {
/* The buffer the core samples from. A second call is refused rather than winning: a target and
* its drafter declaring into one builder (spec §10) both have logits, and keeping the second would
* sample the draft distribution. The drafter's logits are reached through its scope. */
int Builder::declare_scores(rad_buf hidden, rad_weight table) {
if (finished_) { err(RAD_E_STATE, "declare_scores after declare finished"); return RAD_E_STATE; }
if (hidden == RAD_NULL_HANDLE || (size_t)hidden >= prog_.buffers.size()) {
err(RAD_E_INVAL, "declare_scores: %u is not a declared buffer", (unsigned)hidden);
return RAD_E_INVAL;
}
if (table == RAD_NULL_HANDLE || (size_t)table >= prog_.weights.size()) {
err(RAD_E_INVAL, "declare_scores: %u is not a declared weight", (unsigned)table);
return RAD_E_INVAL;
}
const RadBufDecl& h = prog_.buffers[hidden].decl;
const auto& w = prog_.weights[table];
if (h.dtype != RAD_BF16 || h.rank != 2 || w.decl.dtype != RAD_BF16 || w.decl.rank != 2 ||
w.decl.shape[1] != h.shape[1]) {
err(RAD_E_INVAL, "declare_scores: the hidden rows ('%s') and the table ('%s') must be bf16 "
"[rows, n_embd] and [n_vocab, n_embd]", prog_.buffers[hidden].name.c_str(),
w.name.c_str());
return RAD_E_INVAL;
}
prog_.score_hidden = hidden;
prog_.score_table = table;
return RAD_OK;
}
int Builder::declare_logits(rad_buf b) {
if (finished_) { err(RAD_E_STATE, "declare_logits after declare finished"); return RAD_E_STATE; }
if (b == RAD_NULL_HANDLE || (size_t)b >= prog_.buffers.size()) {
@@ -1943,7 +1967,10 @@ int Builder::declare_drafter(const RadDrafterDecl* d) {
int64_t block = d->block;
if (d->kind == RAD_DRAFT_BLOCK) {
if (block == 0) block = (int64_t)d->depth + 1;
if (block < 2 || block < (int64_t)d->depth || block > (int64_t)d->depth + 1) {
/* A tree's (rad_drafter_tree) node count is not its block's draft count: more nodes
* than draft positions (a wider tree) or fewer (a block longer than the tree is deep on
* most steps). Checked at finish, once the tree is or is not declared. */
if (block < 2) {
err(RAD_E_INVAL, "declare_drafter '%s': block %lld rows at depth %d. The head runs "
"over the last %d rows of the block, so the block is either %d rows "
"(the anchor predicts nothing) or %d (it does).",
@@ -2077,17 +2104,48 @@ int Builder::drafter_short_block(int64_t block) {
}
const int64_t full = prog_.drafter.block > 0 ? prog_.drafter.block : prog_.drafter.depth + 1;
const int64_t lead = full - prog_.drafter.depth; /* rows ahead of the proposing ones */
if (block >= full || block - lead < 1) {
/* A tree (rad_drafter_tree, declared first) grows a tree of its own over the shorter pass, up
* to block - 1 nodes whatever its own node count, so it needs only two rows. */
if (prog_.drafter_tree ? (block < 2 || block >= full) : (block >= full || block - lead < 1)) {
err(RAD_E_INVAL, "drafter_short_block '%s': %lld rows. The short block must be shorter "
"than the drafter's own (%lld) and still propose a token (more than %lld "
"rows).", prog_.drafter_name.c_str(), (long long)block, (long long)full,
(long long)lead);
"than the drafter's own (%lld) and still propose a token (%s %lld rows).",
prog_.drafter_name.c_str(), (long long)block, (long long)full,
prog_.drafter_tree ? "at least" : "more than",
(long long)(prog_.drafter_tree ? 2 : lead));
return RAD_E_INVAL;
}
prog_.drafter_short_block = block;
return RAD_OK;
}
/* A block drafter whose proposal is a tree (rad_builder.h). */
int Builder::drafter_tree(rad_buf parents) {
if (finished_) {
err(RAD_E_STATE, "drafter_tree after declare finished");
return RAD_E_STATE;
}
if (prog_.drafter.kind != RAD_DRAFT_BLOCK) {
err(RAD_E_STATE, "drafter_tree: %s. Only a BLOCK drafter's one pass proposes every node at "
"once; declare it with rad_declare_drafter first.",
prog_.drafter.kind == RAD_DRAFT_NONE ? "no drafter is declared"
: "the declared drafter is a SERIAL head");
return RAD_E_STATE;
}
if (parents == RAD_NULL_HANDLE || (size_t)parents >= prog_.buffers.size()) {
err(RAD_E_INVAL, "drafter_tree '%s': parents buffer %u is not a declared buffer",
prog_.drafter_name.c_str(), (unsigned)parents);
return RAD_E_INVAL;
}
if (prog_.buffers[parents].decl.dtype != RAD_I32) {
err(RAD_E_DTYPE, "drafter_tree '%s': parents buffer '%s' is not i32",
prog_.drafter_name.c_str(), prog_.buffers[parents].name.c_str());
return RAD_E_DTYPE;
}
prog_.drafter_tree = true;
prog_.drafter_parents = parents;
return RAD_OK;
}
void Builder::note_v(const char* f, va_list ap) {
char msg[1024];
vsnprintf(msg, sizeof msg, f ? f : "", ap);
@@ -2442,6 +2500,16 @@ int Builder::finish() {
w.source.c_str(), rad_dtype_name(w.decl.dtype));
}
if (prog_.drafter.kind == RAD_DRAFT_BLOCK && !prog_.drafter_tree &&
(prog_.drafter.block < prog_.drafter.depth ||
prog_.drafter.block > (int64_t)prog_.drafter.depth + 1))
err(RAD_E_INVAL, "declare_drafter '%s': block %lld rows at depth %d. The head runs over the "
"last %d rows of the block, so the block is either %d rows (the anchor "
"predicts nothing) or %d (it does); only a tree (rad_drafter_tree) "
"proposes a node count other than its block's drafts.",
prog_.drafter_name.c_str(), (long long)prog_.drafter.block, prog_.drafter.depth,
prog_.drafter.depth, prog_.drafter.depth + 1, prog_.drafter.depth);
if (instances_) finish_instances();
fill_tune_instances();
finish_weight_uses();
@@ -2599,6 +2667,11 @@ int rad_declare_logits(RadBuilder* b, rad_buf logits) {
return B(b)->declare_logits(logits);
}
int rad_declare_scores(RadBuilder* b, rad_buf hidden, rad_weight table) {
if (!b) return RAD_E_INVAL;
return B(b)->declare_scores(hidden, table);
}
int rad_declare_pooled(RadBuilder* b, rad_buf pooled) {
if (!b) return RAD_E_INVAL;
return B(b)->declare_pooled(pooled);
@@ -2630,6 +2703,11 @@ int rad_lora_alias(RadBuilder* b, const char* native, const char* from, const ch
return B(b)->lora_alias(native, from, to, from_lo, from_hi, to_lo);
}
int rad_drafter_tree(RadBuilder* b, rad_buf parents) {
if (!b) return RAD_E_INVAL;
return B(b)->drafter_tree(parents);
}
int rad_chain_on(void) { return rad_dev_chain_enabled(); }
int rad_drafter_short_block(RadBuilder* b, int64_t block) {
+4 -1
View File
@@ -19,6 +19,7 @@
#include <nlohmann/json.hpp>
#include <algorithm>
#include <atomic>
#include <climits>
#include <unordered_map>
#include <cstring>
@@ -650,7 +651,9 @@ std::string dump_graph_json(const Program& p) {
j["geometry"] = o.base.str();
j["ranged"] = o.ranged_key;
if (!o.ranged_key.empty()) { j["range_lo"] = o.range_lo; j["range_hi"] = o.range_hi; }
j["issued"] = o.issued;
/* Read through an atomic_ref: the step path stores this flag from the engine thread
* (Ctx::flush_issued); a plain read here would race it. */
j["issued"] = std::atomic_ref<const bool>(o.issued).load(std::memory_order_relaxed);
j["schema"] = schema_json(o.schema ? o.schema : reg.schema(o.op));
json ws = json::array();
+7 -3
View File
@@ -175,8 +175,12 @@ int rad_tools_load_plugins(const std::string& home, const std::vector<std::strin
/* An imported quantisation is served by the family's quantised plugin (startup.h). A plugin
* that declines imports (rad_arch_serves_imports) is left out of the family here: neither
* counted as a second quantised plugin nor picked as the only one. */
if (imported && !arch_id.empty() && out->arch_plugin.empty()) {
* counted as a second quantised plugin nor picked as the only one. Block-scaled fp8 reads
* stock weight by weight, so a family with no plugin claiming it is served the same way: the
* plugin declares each weight at the encoding it finds (Qwen3.8-Flash-Next-FP8: fp8 routed
* experts beside bf16 linears, served by qwen4exp_fp8). */
const bool stock = quant == "fp8_e4m3";
if ((imported || stock) && !arch_id.empty() && out->arch_plugin.empty()) {
std::vector<const Plugin*> fam, quantised;
for (const Plugin& p : r.plugins())
if (p.kind == RAD_PLUGIN_ARCH && p.arch_id == arch_id && p.arch_serves_imports) {
@@ -198,7 +202,7 @@ int rad_tools_load_plugins(const std::string& home, const std::vector<std::strin
out->arch_version = pick->version;
out->arch_id = pick->arch_id;
out->arch_quant = pick->arch_quant;
RAD_INFO("quantisation '%s' is imported weight by weight; '%s' serves it as %s",
RAD_INFO("quantisation '%s' is read weight by weight; '%s' serves it as %s",
quant.c_str(), pick->name.c_str(),
pick->arch_quant.empty() ? "(unquantised)" : pick->arch_quant.c_str());
}
+3 -2
View File
@@ -68,8 +68,9 @@ std::string rad_home_file(const std::string& home, const std::string& rel);
* its descriptor names the producing tool and no plugin claims it. The family's quantised plugin
* serves it: the one plugin claiming a descriptor, or the only plugin if none does. Two quantised
* plugins are refused by name. A plugin whose rad_arch_serves_imports returns 0 is left out of
* both counts. `out->arch_quant` is the chosen descriptor, which a container
* converted from it records. */
* both counts. Block-scaled fp8 (`fp8_e4m3`) that no plugin of the family claims is served the
* same way, since its weights read stock. `out->arch_quant` is the chosen descriptor, which a
* container converted from it records. */
int rad_tools_load_plugins(const std::string& radiance_home,
const std::vector<std::string>& hierarchy,
const std::string& arch_id,