Archived
laya: rad-convert rounds Laya's f16 to bf16 itself; the tiny test is f16
This commit is contained in:
1 parent
cc58402b71
commit
b6cf2b3574
5 files changed
+41
-27
No files matched your search
@@ -1,21 +0,0 @@
|
||||
# laya-bf16.recipe -- Convai Innovations' Laya (laya, laya-typed-decisions, laya-multilingual) for the
|
||||
# laya plugin (arch/laya).
|
||||
#
|
||||
# rad-convert convaiinnovations/laya-typed-decisions --recipe data/recipes/laya-bf16.recipe \
|
||||
# -o laya-typed-decisions.rad
|
||||
#
|
||||
# The release ships f16. The plugin reads its linears and tables in bf16, as the release computes them
|
||||
# on a card under bf16 autocast, and f16 to bf16 rounds, so it is a rule here. Norms and biases are
|
||||
# declared f32, an exact widening of f16, and no rule names them.
|
||||
token_embd.weight cast dtype=bf16
|
||||
type_emb.weight cast dtype=bf16
|
||||
scorer.fc1.weight cast dtype=bf16
|
||||
scorer.fc2.weight cast dtype=bf16
|
||||
blk.*.attn_qkv.weight cast dtype=bf16
|
||||
blk.*.attn_out.weight cast dtype=bf16
|
||||
blk.*.ffn_in_gate.weight cast dtype=bf16
|
||||
blk.*.ffn_down.weight cast dtype=bf16
|
||||
head.*.attn_qkv.weight cast dtype=bf16
|
||||
head.*.attn_out.weight cast dtype=bf16
|
||||
head.*.ffn_up.weight cast dtype=bf16
|
||||
head.*.ffn_down.weight cast dtype=bf16
|
||||
+4
-4
@@ -2851,8 +2851,7 @@ runs the encoder and head in the `laya` plugin (`arch/laya`), on the embedding p
|
||||
every question of a request in one step, each answered in its pooled row.
|
||||
|
||||
```sh
|
||||
rad-convert /srv/models/laya-typed-decisions -o laya-typed-decisions.rad --set decision.type=laya \
|
||||
--recipe data/recipes/laya-bf16.recipe
|
||||
rad-convert /srv/models/laya-typed-decisions -o laya-typed-decisions.rad --set decision.type=laya
|
||||
radiance --model laya-typed-decisions.rad --port 8000
|
||||
```
|
||||
|
||||
@@ -2860,8 +2859,9 @@ rad-convert reads the release's folders: `encoder/config.json` for the geometry,
|
||||
`rl_agent_config.json` for the sequence budget and the fitted temperatures, and `tokenizer/`. The
|
||||
checkpoint's `config.json` already says `model_type: laya`, so `--set decision.type=laya` is
|
||||
optional. A checkpoint as the `laya` package downloads it, with no `config.json` of its own,
|
||||
converts the same way. The release ships f16 weights, and the recipe rounds the linears and tables
|
||||
to bf16, which is how the release computes them on a card.
|
||||
converts the same way. The release ships f16 weights. rad-convert rounds the linears and tables to
|
||||
bf16 itself, which is how the release computes them on a card, and records the rule in the
|
||||
container's recipe.
|
||||
|
||||
The request and the response are the same as d1's above. What differs:
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"weights_fnv": "230e9131e87efe05",
|
||||
"weights_fnv": "e1a5d79faebbea22",
|
||||
"laya_commit": "fe9a6c3502",
|
||||
"requests": [
|
||||
{
|
||||
@@ -120,7 +120,7 @@
|
||||
"confidence": 0.0081,
|
||||
"answer_confidence": 0.3787,
|
||||
"action": {
|
||||
"act_probability": 0.6045
|
||||
"act_probability": 0.6046
|
||||
}
|
||||
},
|
||||
"tone": {
|
||||
|
||||
@@ -82,6 +82,15 @@ bool write_tiny_laya(const std::string& dir, uint64_t seed) {
|
||||
lin("act_head.2.weight", 2, A);
|
||||
bias("act_head.2.bias", 2);
|
||||
ts.push_back(tiny::noise("temperature", { 3 }, r, 0.0f, 1.0f, "F32"));
|
||||
/* f16, as the release and laya's trainer save it, so the convert's rounding to bf16 is tested. */
|
||||
for (tiny::Tensor& t : ts) {
|
||||
if (t.dtype != "BF16") continue;
|
||||
const int64_t n = tiny::numel(t.shape);
|
||||
std::vector<uint8_t> h((size_t)n * 2);
|
||||
for (int64_t i = 0; i < n; ++i) rad_store_f32(h.data(), RAD_F16, i, rad_load_f32(t.bytes.data(), RAD_BF16, i));
|
||||
t.bytes = std::move(h);
|
||||
t.dtype = "F16";
|
||||
}
|
||||
if (!tiny::write_safetensors(dir + "/model.safetensors", ts)) return false;
|
||||
|
||||
nlohmann::ordered_json root;
|
||||
|
||||
@@ -123,6 +123,23 @@ int clef_metadata(const std::string& in, const std::string& config_dir, const Ch
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The rounding every Laya checkpoint needs: the release ships f16 (laya.train saves .half()), and
|
||||
* the laya plugin reads its linears and tables in bf16, as the release computes them on a card.
|
||||
* Norms and biases are declared f32, an exact widening of f16, so no rule names them. */
|
||||
const char* const kLayaBf16 =
|
||||
"token_embd.weight cast dtype=bf16\n"
|
||||
"type_emb.weight cast dtype=bf16\n"
|
||||
"scorer.fc1.weight cast dtype=bf16\n"
|
||||
"scorer.fc2.weight cast dtype=bf16\n"
|
||||
"blk.*.attn_qkv.weight cast dtype=bf16\n"
|
||||
"blk.*.attn_out.weight cast dtype=bf16\n"
|
||||
"blk.*.ffn_in_gate.weight cast dtype=bf16\n"
|
||||
"blk.*.ffn_down.weight cast dtype=bf16\n"
|
||||
"head.*.attn_qkv.weight cast dtype=bf16\n"
|
||||
"head.*.attn_out.weight cast dtype=bf16\n"
|
||||
"head.*.ffn_up.weight cast dtype=bf16\n"
|
||||
"head.*.ffn_down.weight cast dtype=bf16\n";
|
||||
|
||||
/* Laya (a checkpoint whose config.json says model_type laya, or --set decision.type=laya): the
|
||||
* release keeps its parts in folders, so the encoder's geometry comes from encoder/config.json,
|
||||
* the head's settings from rl_agent_config.json and the vocabulary from tokenizer/. The plugin
|
||||
@@ -605,6 +622,15 @@ int main(int argc, char** argv) {
|
||||
(meta.arch == "laya" || (dt && !std::strcmp(dt, "laya"))) &&
|
||||
laya_metadata(in, config_dir, meta, &tokjson) < 0)
|
||||
return 1;
|
||||
/* f16 to bf16 rounds, so it is a recipe's rule (spec §4.4). Every Laya checkpoint needs the same
|
||||
* rules, so they follow any the caller gave, and the container records them with the rest. */
|
||||
if (meta.arch == "laya") {
|
||||
std::string why;
|
||||
if (recipe.add_text(kLayaBf16, "laya's f16 to bf16 (built in)", &why) < 0) {
|
||||
RAD_ERR("%s", why.c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* The quantisation descriptor (which selects the plugin pair) is derived from
|
||||
* quantization_config, so a --set of it re-derives the descriptor. E.g. a bf16 checkpoint
|
||||
* whose recipe writes Qwen's block fp8 targets qwen35_fp8 by setting what that release
|
||||
|
||||
Reference in new issue
Block a user