Archived
radiance 1.10.0
LoRA for image and video generators: - civitai and Hugging Face adapter files as published: kohya, ComfyUI and diffusers/PEFT key names; LoRA, LoCon, LoHa, LoKr and full-weight diffs; DoRA, OFT and Tucker are refused by name - stacked per request with a strength each, through the `loras` field or <lora:name:strength> tags in the prompt; --lora-dir serves every file in a directory, GET /v1/loras lists them, and --max-loras / --max-lora-rank size the slots on the card (generators default to rank 64) - Krea 2, Qwen-Image 2.1, FLUX.3 [klein], MiniMax H3, LTX-2.5, Anima and SDXL New models: - Anima (base, aesthetic and turbo): Cosmos-Predict2 DiT with the Qwen3-0.6B text encoder and the Qwen-Image VAE, on one card - Stable Diffusion XL and its single-file finetunes (Illustrious, NoobAI including V-Pred, Pony), read as civitai ships them, with the Euler, Euler a and DPM++ 2M samplers Recipes: - q38-27b-mxfp4-df2: any bf16 Qwen3.8-27B or finetune at MXFP4 with the DFlash2 drafter - Krea 2 finetunes from civitai: scripts/krea2_native.py reads Krea's own key names, and krea-2-fp8-unscaled keeps a plain-fp8 file's codes exactly Changes: --max-num-batched-tokens defaults to 2048 (was 8192). Plugin ABI 25: out-of-tree plugins must be rebuilt.
This commit is contained in:
1 parent
685ec5bd85
commit
4246a1dd04
124 files changed
+14326
-387
No files matched your search
@@ -180,6 +180,78 @@ TEST(a_plain_tensor_is_its_own_encoding_and_reads_back_as_itself) {
|
||||
CHECK_EQ(std::memcmp(raw.data(), (const uint8_t*)ck.find("a.weight")->data + 32, 16), 0);
|
||||
}
|
||||
|
||||
/* A single-file SDXL checkpoint (Stability's sgm layout) is read under the names its adapters use:
|
||||
* the UNet and CLIP ViT-L as they are, OpenCLIP bigG in transformers' names with its fused
|
||||
* in_proj split into q/k/v rows and its (in, out) text_projection transposed, the VAE decoder in
|
||||
* diffusers' names with up blocks counted the other way, a v_pred marker as the prediction type,
|
||||
* and bigG's dimensions as the model's. */
|
||||
TEST(a_single_file_sdxl_checkpoint_is_read_in_its_adapters_names) {
|
||||
const std::string g = "conditioner.embedders.1.model.";
|
||||
T proj{ g + "text_projection", "F32", { 2, 3 }, {} };
|
||||
proj.bytes.resize(6 * 4);
|
||||
for (int i = 0; i < 6; ++i) rad_store_f32(proj.bytes.data(), RAD_F32, i, (float)i);
|
||||
const std::string dir = fresh_dir();
|
||||
const std::string file = dir + "/sdxl.safetensors";
|
||||
write_shard(file, {
|
||||
bf16("model.diffusion_model.label_emb.0.0.weight", { 2, 4 }, 1.0f),
|
||||
bf16("conditioner.embedders.0.transformer.text_model.final_layer_norm.weight", { 4 }, 2.0f),
|
||||
bf16(g + "transformer.resblocks.3.attn.in_proj_weight", { 6, 4 }, 0.0f),
|
||||
bf16(g + "transformer.resblocks.3.attn.in_proj_bias", { 6 }, 0.0f),
|
||||
bf16(g + "transformer.resblocks.3.mlp.c_fc.weight", { 8, 4 }, 3.0f),
|
||||
bf16(g + "transformer.resblocks.3.ln_2.bias", { 4 }, 4.0f),
|
||||
bf16(g + "ln_final.weight", { 4 }, 5.0f),
|
||||
bf16(g + "token_embedding.weight", { 16, 4 }, 0.0f),
|
||||
bf16(g + "transformer.resblocks.0.ln_1.weight", { 4 }, 0.0f),
|
||||
bf16(g + "transformer.resblocks.0.mlp.c_fc.weight", { 8, 4 }, 0.0f),
|
||||
bf16(g + "positional_embedding", { 77, 4 }, 6.0f),
|
||||
proj,
|
||||
bf16("first_stage_model.decoder.up.0.block.2.nin_shortcut.weight", { 4, 8, 1, 1 }, 7.0f),
|
||||
bf16("first_stage_model.decoder.up.3.upsample.conv.bias", { 4 }, 8.0f),
|
||||
bf16("first_stage_model.decoder.mid.attn_1.proj_out.weight", { 4, 4, 1, 1 }, 9.0f),
|
||||
bf16("first_stage_model.encoder.conv_in.weight", { 4, 3, 3, 3 }, 10.0f),
|
||||
T{ "v_pred", "F32", { 0 }, {} },
|
||||
});
|
||||
Checkpoint ck;
|
||||
REQUIRE_EQ(ck.open(file), RAD_OK);
|
||||
CHECK_EQ(ck.meta().arch, std::string("sdxl"));
|
||||
REQUIRE(ck.meta().get("sdxl.prediction") != nullptr);
|
||||
CHECK_EQ(std::string(ck.meta().get("sdxl.prediction")), std::string("v"));
|
||||
/* The typed dimensions are bigG's: its width, vocabulary and feed-forward off its tensors,
|
||||
* its layers counted from 0 while they run on. */
|
||||
CHECK_EQ(ck.meta().m.n_embd, (int64_t)4);
|
||||
CHECK_EQ(ck.meta().m.n_vocab, (int64_t)16);
|
||||
CHECK_EQ(ck.meta().m.n_ff, (int64_t)8);
|
||||
CHECK_EQ(ck.meta().m.n_layers, (int64_t)1);
|
||||
CHECK(ck.find("model.diffusion_model.label_emb.0.0.weight") != nullptr);
|
||||
CHECK(ck.find("conditioner.embedders.0.transformer.text_model.final_layer_norm.weight") != nullptr);
|
||||
const std::string t = "conditioner.embedders.1.transformer.";
|
||||
const std::string l = t + "text_model.encoder.layers.3.";
|
||||
const SrcTensor* q = ck.find(l + "self_attn.q_proj.weight");
|
||||
const SrcTensor* v = ck.find(l + "self_attn.v_proj.weight");
|
||||
const SrcTensor* vb = ck.find(l + "self_attn.v_proj.bias");
|
||||
REQUIRE(q && v && vb);
|
||||
CHECK(q->shape == std::vector<int64_t>({ 2, 4 }));
|
||||
/* v is rows 4..5 of in_proj: elements 16..23, each its index (mod 64) in bf16. */
|
||||
CHECK_EQ(rad_load_f32(v->data, RAD_BF16, 0), 16.0f);
|
||||
CHECK_EQ(rad_load_f32(vb->data, RAD_BF16, 1), 5.0f);
|
||||
CHECK(ck.find(g + "transformer.resblocks.3.attn.in_proj_weight") == nullptr);
|
||||
CHECK(ck.find(l + "mlp.fc1.weight") != nullptr);
|
||||
CHECK(ck.find(l + "layer_norm2.bias") != nullptr);
|
||||
CHECK(ck.find(t + "text_model.final_layer_norm.weight") != nullptr);
|
||||
CHECK(ck.find(t + "text_model.embeddings.position_embedding.weight") != nullptr);
|
||||
const SrcTensor* p = ck.find(t + "text_projection.weight");
|
||||
REQUIRE(p != nullptr);
|
||||
CHECK(p->shape == std::vector<int64_t>({ 3, 2 }));
|
||||
/* P^T: element (j, i) is P(i, j) = 3 i + j. */
|
||||
for (int j = 0; j < 3; ++j)
|
||||
for (int i = 0; i < 2; ++i)
|
||||
CHECK_EQ(rad_load_f32(p->data, RAD_F32, j * 2 + i), (float)(3 * i + j));
|
||||
CHECK(ck.find("vae.decoder.up_blocks.3.resnets.2.conv_shortcut.weight") != nullptr);
|
||||
CHECK(ck.find("vae.decoder.up_blocks.0.upsamplers.0.conv.bias") != nullptr);
|
||||
CHECK(ck.find("vae.decoder.mid_block.attentions.0.to_out.0.weight") != nullptr);
|
||||
CHECK(ck.find("first_stage_model.encoder.conv_in.weight") != nullptr);
|
||||
}
|
||||
|
||||
/* Block-scaled FP8 is one weight of two planes; each value is its code times the scale of the
|
||||
* block containing it along both axes. */
|
||||
TEST(block_fp8_is_the_codes_and_their_scale_plane) {
|
||||
@@ -2735,4 +2807,82 @@ TEST(a_companion_folder_is_read_under_its_name) {
|
||||
CHECK_EQ(mget("codec.decoder_config.dim"), std::string("7"));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/* A RAD_MAP_ROWS or RAD_MAP_COLS map: source k starts at index[k] and spans rows[k]. */
|
||||
RadNameMap ranged(const char* declared, int mode, std::vector<const char*> src,
|
||||
std::vector<int> index, std::vector<int64_t> rows) {
|
||||
RadNameMap m = map(declared, mode, std::move(src), std::move(index));
|
||||
for (size_t i = 0; i < rows.size(); ++i) m.src_rows[i] = rows[i];
|
||||
return m;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* A column range of the last dimension, in every leading slice; a range past the end is
|
||||
* refused. */
|
||||
TEST(a_column_range_is_those_columns_of_every_row) {
|
||||
const std::string dir = write_checkpoint({ bf16("x.weight", { 3, 5 }, 0.0f) }, kConfig);
|
||||
Checkpoint ck;
|
||||
REQUIRE_EQ(ck.open(dir), RAD_OK);
|
||||
Program prog;
|
||||
prog.name_map.push_back(ranged("xc", RAD_MAP_COLS, { "x.weight" }, { 1 }, { 3 }));
|
||||
prog.name_map.push_back(ranged("far", RAD_MAP_COLS, { "x.weight" }, { 3 }, { 3 }));
|
||||
CkptWeight w;
|
||||
std::string why;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "xc", false, &w, &why), RAD_OK);
|
||||
CHECK(!w.trivial);
|
||||
REQUIRE_EQ(w.rank, (uint32_t)2);
|
||||
CHECK_EQ(w.shape[0], (int64_t)3);
|
||||
CHECK_EQ(w.shape[1], (int64_t)3);
|
||||
std::vector<float> f(9);
|
||||
REQUIRE_EQ(ckpt_rows_f32(w, 0, 3, f.data(), &why), RAD_OK);
|
||||
for (int r = 0; r < 3; ++r)
|
||||
for (int c = 0; c < 3; ++c) CHECK_EQ(f[(size_t)(r * 3 + c)], (float)(r * 5 + 1 + c));
|
||||
CHECK_EQ(ckpt_resolve(ck, prog, "far", false, &w, &why), (int)RAD_E_SHAPE);
|
||||
}
|
||||
|
||||
/* Row pieces declared over several maps of one name join in declaration order, so a permutation
|
||||
* of a weight's rows can be stated one row at a time. */
|
||||
TEST(row_pieces_over_several_maps_join_in_order) {
|
||||
const std::string dir = write_checkpoint({ bf16("w", { 4, 3 }, 0.0f) }, kConfig);
|
||||
Checkpoint ck;
|
||||
REQUIRE_EQ(ck.open(dir), RAD_OK);
|
||||
Program prog;
|
||||
prog.name_map.push_back(ranged("p", RAD_MAP_ROWS, { "w" }, { 2 }, { 1 }));
|
||||
prog.name_map.push_back(ranged("p", RAD_MAP_ROWS, { "w", "w" }, { 0, 3 }, { 1, 1 }));
|
||||
CkptWeight w;
|
||||
std::string why;
|
||||
REQUIRE_EQ(ckpt_resolve(ck, prog, "p", false, &w, &why), RAD_OK);
|
||||
CHECK_EQ(w.shape[0], (int64_t)3);
|
||||
CHECK_EQ(w.shape[1], (int64_t)3);
|
||||
std::vector<float> f(9);
|
||||
REQUIRE_EQ(ckpt_rows_f32(w, 0, 3, f.data(), &why), RAD_OK);
|
||||
const int order[3] = { 2, 0, 3 };
|
||||
for (int r = 0; r < 3; ++r)
|
||||
for (int c = 0; c < 3; ++c) CHECK_EQ(f[(size_t)(r * 3 + c)], (float)(order[r] * 3 + c));
|
||||
}
|
||||
|
||||
/* A release split into single files merges them under their own names; a name two files share
|
||||
* is refused. The metadata and tokenizer come from the directory set before open(). */
|
||||
TEST(single_files_merge_by_name_and_read_their_metadata_elsewhere) {
|
||||
const std::string dir = fresh_dir();
|
||||
write_shard(dir + "/dit.safetensors", { bf16("net.a", { 2, 2 }, 1.0f) });
|
||||
write_shard(dir + "/te.safetensors", { bf16("model.b", { 2, 2 }, 2.0f) });
|
||||
write_shard(dir + "/dup.safetensors", { bf16("net.a", { 2, 2 }, 3.0f) });
|
||||
const std::string meta = fresh_dir();
|
||||
write_file(meta + "/config.json", "{\"model_type\":\"qwen3\",\"hidden_size\":64}");
|
||||
write_file(meta + "/tokenizer.json", "{}");
|
||||
Checkpoint ck;
|
||||
ck.set_meta_dir(meta);
|
||||
REQUIRE_EQ(ck.open(dir + "/dit.safetensors"), RAD_OK);
|
||||
REQUIRE_EQ(ck.add_file(dir + "/te.safetensors"), RAD_OK);
|
||||
CHECK(ck.find("net.a") != nullptr);
|
||||
CHECK(ck.find("model.b") != nullptr);
|
||||
CHECK(ck.add_file(dir + "/dup.safetensors") < 0);
|
||||
const char* mt = ck.meta().get("model_type");
|
||||
CHECK_EQ(std::string(mt ? mt : ""), std::string("qwen3"));
|
||||
CHECK_EQ(ck.tok_dir(), meta);
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
Reference in new issue
Block a user