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
@@ -88,6 +88,29 @@ TEST(the_schedule_is_diffusers_flow_match_euler) {
|
||||
CHECK_EQ(gen::schedule(d, {}, 0, 64).size(), (size_t)d.default_steps + 1);
|
||||
}
|
||||
|
||||
/* A schedule off a table of timesteps is ComfyUI's `simple` scheduler over its discrete flow
|
||||
* sampling (1000 timesteps, shift 3, multiplier 1): the sigmas below are what ComfyUI hands its
|
||||
* sampler, as f32. */
|
||||
TEST(a_sigma_grid_is_comfyui_simple_schedule) {
|
||||
RadGeneratorDecl d = decl_base();
|
||||
d.dyn_shift = 0; d.shift_terminal = 0; d.shift = 3.0;
|
||||
d.sigma_grid = 1000;
|
||||
const double want30[] = { 1, 0.988752544, 0.976987481, 0.964285672, 0.951353252, 0.937781036,
|
||||
0.923076987, 0.908050597, 0.892220497, 0.87499994, 0.857326388,
|
||||
0.838624299, 0.818181813, 0.797094703, 0.774661541, 0.75,
|
||||
0.724405408, 0.697002113, 0.666666687, 0.634948134, 0.600719392,
|
||||
0.5625, 0.522164285, 0.478201658, 0.428571463, 0.375562221,
|
||||
0.317034721, 0.25, 0.177248672, 0.095505625, 0 };
|
||||
const std::vector<float> s = gen::schedule(d, {}, 30, 4096);
|
||||
REQUIRE_EQ(s.size(), (size_t)31);
|
||||
for (size_t i = 0; i < s.size(); ++i) CHECK_NEAR(s[i], want30[i], 1e-8);
|
||||
const double want7[] = { 1, 0.94771713, 0.882716119, 0.800373137, 0.69268024, 0.54580152,
|
||||
0.333592534, 0 };
|
||||
const std::vector<float> s7 = gen::schedule(d, {}, 7, 1024);
|
||||
REQUIRE_EQ(s7.size(), (size_t)8);
|
||||
for (size_t i = 0; i < s7.size(); ++i) CHECK_NEAR(s7[i], want7[i], 1e-8);
|
||||
}
|
||||
|
||||
/* A fixed schedule is taken as declared (with shift 1), then closed with 0. */
|
||||
TEST(a_fixed_schedule_is_used_as_declared) {
|
||||
RadGeneratorDecl d = decl_base();
|
||||
@@ -96,6 +119,146 @@ TEST(a_fixed_schedule_is_used_as_declared) {
|
||||
CHECK_EQ(s[0], 0.9f); CHECK_EQ(s[1], 0.5f); CHECK_EQ(s[2], 0.125f); CHECK_EQ(s[3], 0.0f);
|
||||
}
|
||||
|
||||
/* ================================================================== a discrete-time schedule */
|
||||
/* Stable Diffusion XL's: 1000 timesteps, scaled-linear betas 0.00085..0.012. */
|
||||
RadGeneratorDecl decl_discrete() {
|
||||
RadGeneratorDecl d = decl_base();
|
||||
d.train_steps = 1000;
|
||||
d.beta_schedule = RAD_GEN_BETAS_SCALED_LINEAR;
|
||||
d.beta_start = 0.00085;
|
||||
d.beta_end = 0.012;
|
||||
d.samplers = (1u << RAD_GEN_SAMPLER_COUNT) - 1;
|
||||
d.default_steps = 5;
|
||||
return d;
|
||||
}
|
||||
|
||||
/* Each scheduler places five sigmas as ComfyUI's ModelSamplingDiscrete does (reference values
|
||||
* from its schedulers over the same table), and each sigma is conditioned at the timestep
|
||||
* ComfyUI picks for it. The table's ends are SDXL's sigma_min and sigma_max. */
|
||||
TEST(a_discrete_schedule_is_comfyuis) {
|
||||
const RadGeneratorDecl d = decl_discrete();
|
||||
gen::DiscreteTable t;
|
||||
std::string why;
|
||||
REQUIRE_EQ(gen::discrete_table(d, &t, &why), (int)RAD_OK);
|
||||
CHECK_NEAR(t.sigma_min(), 0.0291671585, 1e-8);
|
||||
CHECK_NEAR(t.sigma_max(), 14.6146412, 2e-5);
|
||||
struct Want { int32_t sched; double s[5]; int32_t ts[5]; };
|
||||
const Want want[] = {
|
||||
{ RAD_GEN_SCHED_NORMAL, { 14.6146402, 4.08608103, 1.61558032, 0.695149541, 0.0291671604 },
|
||||
{ 999, 749, 500, 250, 0 } },
|
||||
{ RAD_GEN_SCHED_KARRAS, { 14.6146431, 4.79653454, 1.27410078, 0.247949973, 0.0291671772 },
|
||||
{ 999, 786, 427, 59, 0 } },
|
||||
{ RAD_GEN_SCHED_EXPONENTIAL,
|
||||
{ 14.6146402, 3.08897638, 0.652891755, 0.137996376, 0.0291671604 },
|
||||
{ 999, 681, 233, 20, 0 } },
|
||||
{ RAD_GEN_SCHED_SGM_UNIFORM,
|
||||
{ 14.6146402, 5.09240818, 2.27973056, 1.16286457, 0.571188867 },
|
||||
{ 999, 799, 599, 400, 200 } },
|
||||
{ RAD_GEN_SCHED_SIMPLE, { 14.6146412, 5.08776331, 2.27646303, 1.16057837, 0.569284916 },
|
||||
{ 999, 799, 599, 399, 199 } },
|
||||
};
|
||||
for (const Want& w : want) {
|
||||
const std::vector<float> s = gen::schedule_discrete(d, t, w.sched, 0);
|
||||
REQUIRE_EQ(s.size(), (size_t)6);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
CHECK_NEAR(s[(size_t)i], w.s[i], 2e-6 * w.s[i] + 1e-7);
|
||||
CHECK_EQ(t.timestep(s[(size_t)i]), w.ts[i]);
|
||||
}
|
||||
CHECK_EQ(s[5], 0.0f);
|
||||
CHECK_EQ(std::string(gen::scheduler_name(w.sched)).empty(), false);
|
||||
CHECK_EQ(gen::scheduler_id(gen::scheduler_name(w.sched)), w.sched);
|
||||
}
|
||||
/* Zero terminal SNR keeps the smallest sigma and makes the largest ComfyUI's 4518.76. */
|
||||
RadGeneratorDecl z = d;
|
||||
z.zero_snr = 1;
|
||||
gen::DiscreteTable tz;
|
||||
REQUIRE_EQ(gen::discrete_table(z, &tz, &why), (int)RAD_OK);
|
||||
CHECK_NEAR(tz.sigma_min(), 0.0291671585, 1e-8);
|
||||
CHECK_NEAR(tz.sigma_max(), 4518.76367, 0.01);
|
||||
CHECK_EQ(gen::sampler_id("dpmpp_2m"), (int32_t)RAD_GEN_SAMPLER_DPMPP_2M);
|
||||
CHECK_EQ(gen::sampler_id("ddim"), (int32_t)-1);
|
||||
}
|
||||
|
||||
/* A discrete-time model's step carries, per entry, its sigmas (the one before included), the
|
||||
* timestep, the request's sampler, the step, the image's size, and on the host the entry's
|
||||
* conditioning rows, size and branch; the conditioning pass carries its tokens on the host. */
|
||||
TEST(a_discrete_step_carries_its_sampler_and_each_entrys_geometry) {
|
||||
Program prog;
|
||||
prog.generator = decl_discrete();
|
||||
RadGeneratorDecl& d = prog.generator;
|
||||
d.layout = RAD_GEN_LAYOUT_JOINT_STEP;
|
||||
d.latent_scale = 8;
|
||||
d.cond_rows = 2 * 77;
|
||||
d.rope_hw_scale = 1.0;
|
||||
d.chunk_tokens = 75;
|
||||
d.chunk_bos = 49406;
|
||||
d.chunk_eos = 49407;
|
||||
d.pad_token = 49407;
|
||||
prog.ctx.max_tok = 4096;
|
||||
prog.ctx.max_seqs = 8;
|
||||
prog.kv_groups.emplace_back();
|
||||
gen::Driver drv;
|
||||
REQUIRE_EQ(drv.init(prog, nullptr, { gen::Driver::RankIO{} }), (int)RAD_OK);
|
||||
auto r = std::make_unique<gen::Request>();
|
||||
r->width = 64;
|
||||
r->height = 32;
|
||||
r->steps = 3;
|
||||
r->sampler = RAD_GEN_SAMPLER_DPMPP_2M;
|
||||
r->scheduler = RAD_GEN_SCHED_KARRAS;
|
||||
r->pos.tokens.assign(77, 5);
|
||||
r->has_neg = true;
|
||||
r->neg.tokens.assign(77, 6);
|
||||
r->cfg = 6.0f;
|
||||
r->ticket = std::make_shared<gen::Ticket>();
|
||||
std::string why;
|
||||
REQUIRE_EQ(drv.submit(std::move(r), &why), (int)RAD_OK);
|
||||
const RadBatch* b = drv.next(0);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE_EQ(b->gen, (int32_t)RAD_GEN_PASS_COND);
|
||||
REQUIRE(b->gen_b->tokens_h != nullptr);
|
||||
CHECK_EQ(b->gen_b->tokens_h[76], (int32_t)5);
|
||||
CHECK_OK(drv.done());
|
||||
REQUIRE(drv.next(1) != nullptr);
|
||||
CHECK_OK(drv.done());
|
||||
gen::DiscreteTable t;
|
||||
REQUIRE_EQ(gen::discrete_table(d, &t, &why), (int)RAD_OK);
|
||||
const std::vector<float> s = gen::schedule_discrete(d, t, RAD_GEN_SCHED_KARRAS, 3);
|
||||
for (int step = 0; step < 3; ++step) {
|
||||
b = drv.next(2 + step);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE_EQ(b->gen, (int32_t)RAD_GEN_PASS_DENOISE);
|
||||
const RadGenBatch* G = b->gen_b;
|
||||
REQUIRE_EQ(b->n_seq, (int64_t)2);
|
||||
CHECK_EQ(b->n_tok, (int64_t)(2 * (77 + 32)));
|
||||
for (int e = 0; e < 2; ++e) {
|
||||
CHECK_EQ(G->sigma[e], s[(size_t)step]);
|
||||
CHECK_EQ(G->sigma_next[e], s[(size_t)step + 1]);
|
||||
CHECK_EQ(G->sigma_prev[e], step ? s[(size_t)step - 1] : 0.0f);
|
||||
CHECK_EQ(G->timestep[e], (float)t.timestep(s[(size_t)step]));
|
||||
CHECK_EQ(G->sampler[e], (int32_t)RAD_GEN_SAMPLER_DPMPP_2M);
|
||||
CHECK_EQ(G->step[e], (int32_t)step);
|
||||
CHECK_EQ(G->size_px[2 * e], 32.0f);
|
||||
CHECK_EQ(G->size_px[2 * e + 1], 64.0f);
|
||||
CHECK_EQ(G->entry_h[4 * e], (int32_t)77);
|
||||
CHECK_EQ(G->entry_h[4 * e + 1], (int32_t)32);
|
||||
CHECK_EQ(G->entry_h[4 * e + 2], (int32_t)64);
|
||||
CHECK_EQ(G->entry_h[4 * e + 3], (int32_t)e);
|
||||
}
|
||||
CHECK_OK(drv.done());
|
||||
}
|
||||
/* A sampler the model does not serve is refused at submit. */
|
||||
d.samplers = 1u << RAD_GEN_SAMPLER_EULER;
|
||||
gen::Driver drv2;
|
||||
REQUIRE_EQ(drv2.init(prog, nullptr, { gen::Driver::RankIO{} }), (int)RAD_OK);
|
||||
auto r2 = std::make_unique<gen::Request>();
|
||||
r2->width = 64;
|
||||
r2->height = 32;
|
||||
r2->sampler = RAD_GEN_SAMPLER_EULER_ANCESTRAL;
|
||||
r2->pos.tokens.assign(77, 5);
|
||||
r2->ticket = std::make_shared<gen::Ticket>();
|
||||
CHECK_EQ(drv2.submit(std::move(r2), &why), (int)RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* ================================================================== the sequence */
|
||||
/* An h x w image at frame `pos`: every row at that frame, height and width centred on zero. */
|
||||
TEST(image_rotary_positions_centre_the_grid_on_its_frame) {
|
||||
@@ -422,4 +585,65 @@ TEST(the_joint_layout_carries_the_conditioning_in_every_step) {
|
||||
CHECK_OK(drv.done());
|
||||
}
|
||||
|
||||
/* A generator that reads its prompt through a second tokenizer (RadGeneratorDecl::aux_tokens):
|
||||
* each branch's COND pass carries that branch's ids and {0, n} on the device, and no other pass
|
||||
* does; a branch with none, or more than declared, is refused at submission. */
|
||||
TEST(a_second_tokenizers_ids_ride_in_each_conditioning) {
|
||||
Program prog;
|
||||
prog.generator = decl_base();
|
||||
RadGeneratorDecl& d = prog.generator;
|
||||
d.layout = RAD_GEN_LAYOUT_JOINT_STEP;
|
||||
d.cond_rows = 16;
|
||||
d.pad_multiple = 16;
|
||||
d.pad_token = 99;
|
||||
d.aux_tokens = 1;
|
||||
d.aux_max_tokens = 6;
|
||||
prog.ctx.max_tok = 2048;
|
||||
prog.ctx.max_seqs = 8;
|
||||
prog.kv_groups.emplace_back();
|
||||
gen::Driver drv;
|
||||
REQUIRE_EQ(drv.init(prog, nullptr, { gen::Driver::RankIO{} }), (int)RAD_OK);
|
||||
auto mk = [](std::vector<int32_t> aux, std::vector<int32_t> neg_aux) {
|
||||
auto r = std::make_unique<gen::Request>();
|
||||
r->width = 64;
|
||||
r->height = 64;
|
||||
r->pos.tokens = { 1, 2, 3 };
|
||||
r->pos.aux = std::move(aux);
|
||||
r->has_neg = true;
|
||||
r->neg.tokens = { 5 };
|
||||
r->neg.aux = std::move(neg_aux);
|
||||
r->cfg = 4.0f;
|
||||
r->ticket = std::make_shared<gen::Ticket>();
|
||||
return r;
|
||||
};
|
||||
std::string why;
|
||||
CHECK_EQ(drv.submit(mk({ 7, 8 }, {}), &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "second tokenizer"));
|
||||
CHECK_EQ(drv.submit(mk({ 1, 2, 3, 4, 5, 6, 7 }, { 1 }), &why), (int)RAD_E_INVAL);
|
||||
REQUIRE_EQ(drv.submit(mk({ 7, 8, 1 }, { 1 }), &why), (int)RAD_OK);
|
||||
|
||||
const RadBatch* b = drv.next(0);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE_EQ(b->gen, (int32_t)RAD_GEN_PASS_COND);
|
||||
const RadGenBatch* G = b->gen_b;
|
||||
REQUIRE_EQ(G->n_aux, (int64_t)3);
|
||||
CHECK_EQ(G->aux_ids[0], (int32_t)7);
|
||||
CHECK_EQ(G->aux_ids[2], (int32_t)1);
|
||||
CHECK_EQ(G->aux_cu[0], (int32_t)0);
|
||||
CHECK_EQ(G->aux_cu[1], (int32_t)3);
|
||||
CHECK_OK(drv.done());
|
||||
b = drv.next(1);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE_EQ(b->gen_b->n_aux, (int64_t)1);
|
||||
CHECK_EQ(b->gen_b->aux_ids[0], (int32_t)1);
|
||||
CHECK_EQ(b->gen_b->aux_cu[1], (int32_t)1);
|
||||
CHECK_OK(drv.done());
|
||||
b = drv.next(2);
|
||||
REQUIRE(b != nullptr);
|
||||
REQUIRE_EQ(b->gen, (int32_t)RAD_GEN_PASS_DENOISE);
|
||||
CHECK_EQ(b->gen_b->n_aux, (int64_t)0);
|
||||
CHECK(b->gen_b->aux_ids == nullptr);
|
||||
CHECK_OK(drv.done());
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
Reference in new issue
Block a user