fix(minimaxh3): keep mixed-site encoder operands host-readable

This commit is contained in:
John authored and StillDeadcode committed 2026-11-17 18:28:50 +01:00
1 parent 73a284d799
commit 590dbcc178
4 files changed
+63 -11

No files matched your search

+2 -1
View File
@@ -729,7 +729,8 @@ typedef struct RadVideoGenBatch {
/* VENCODE: f32 [enc_frames, enc_height, enc_width, 3] RGB in 0..255, the frames padded to
* whole clips by repeating the last (rad_arch_encode_geom's entry 23). AENCODE: f32
* [enc_channels, enc_n_samples], each channel padded with zeros to the hop (entry 0). Both:
* the pass's geometry as rad_arch_encode_geom gave it, i32 on the device, and the media's
* the pass's geometry as rad_arch_encode_geom gave it, i32 in pinned host memory also readable
* by device kernels (mixed-site encoders share it), and the media's
* kind (RAD_ENC_*, below) and its number within the kind from 1. */
const float* enc_pixels;
int32_t enc_frames, enc_height, enc_width;
+17 -7
View File
@@ -2346,7 +2346,11 @@ static int declare_venc(RadBuilder* b, const RadModelMeta* meta, Model& m) {
m.ve_fold_mul = join_list(fm);
m.ve_fold_add = join_list(fa);
m.b_epix32 = decl_b(b, nm.f("venc.pix32"), RAD_F32, { Rmax, 3 });
m.b_epix = decl_b(b, nm.f("venc.pix"), RAD_BF16, { Rmax, 3 });
/* conv_in and the k=1 projections run on the host. Their activation operands must be
* pinned host buffers too: joining a device queue does not make its VRAM CPU-readable.
* Device convolutions can read/write these boundary buffers over the link in place. */
m.b_epix = decl_b(b, nm.f("venc.pix"), RAD_BF16, { Rmax, 3 },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST);
m.b_egn = decl_b(b, nm.f("venc.gn"), RAD_F32, { G * (2 + 3 * 1024) });
const rad_buf st = m.b_egn;
/* The tiled encode's two planes and the quant_conv are declared ahead of the trunk, and the
@@ -2354,12 +2358,16 @@ static int declare_venc(RadBuilder* b, const RadModelMeta* meta, Model& m) {
* tiled pass reruns the whole trunk once a tile while `b_vtile` holds every tile's pixels and
* `b_eqt` the finished tiles' moments, so both lifetimes must span the trunk's ops (from
* op_ve_pix's and op_ve_q's use to op_vt_crop and op_vt_join). */
m.b_tplan = decl_b(b, nm.f("venc.tplan"), RAD_I32, { m.tiles, 22 }, RAD_BUF_PERSIST);
m.b_tplan = decl_b(b, nm.f("venc.tplan"), RAD_I32, { m.tiles, 22 },
RAD_BUF_PERSIST, RAD_DOMAIN_HOST);
m.b_vtile = decl_b(b, nm.f("venc.vtile"), RAD_F32,
{ m.tiles * (int64_t)kEncMaxSide * kEncMaxSide, 3 });
m.b_eq48 = decl_b(b, nm.f("venc.q48"), RAD_BF16, { R[5], 48 });
m.b_eq2 = decl_b(b, nm.f("venc.q"), RAD_BF16, { R[5], 48 });
m.b_eqt = decl_b(b, nm.f("venc.qt"), RAD_BF16, { m.tiles * (int64_t)kTile * kTile, 48 });
m.b_eq48 = decl_b(b, nm.f("venc.q48"), RAD_BF16, { R[5], 48 },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST);
m.b_eq2 = decl_b(b, nm.f("venc.q"), RAD_BF16, { R[5], 48 },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST);
m.b_eqt = decl_b(b, nm.f("venc.qt"), RAD_BF16, { m.tiles * (int64_t)kTile * kTile, 48 },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST);
m.ve_qw = wh(nm.f("venc.q.weight"), nm.ckpt("vae.quant_conv.weight"), { 48, 48, 1, 1, 1 });
m.ve_qb = wh(nm.f("venc.q.bias"), nm.ckpt("vae.quant_conv.bias"), { 48 });
/* The whole-canvas pass writes b_eq2; the tiled pass writes a tile's slice of b_eqt, which
@@ -2396,7 +2404,8 @@ static int declare_venc(RadBuilder* b, const RadModelMeta* meta, Model& m) {
const int64_t cout = (int64_t)dims[L], cin = L == 0 ? cout : (int64_t)dims[L - 1];
const bool sc = L > 0 && cout != cin;
E.cin = cin, E.cout = cout, E.rows = R[L], E.pf = PF[L], E.frames = tf[L];
E.a = decl_b(b, nm.f("venc.l%d.a", L), RAD_BF16, { R[L], cout });
E.a = decl_b(b, nm.f("venc.l%d.a", L), RAD_BF16, { R[L], cout },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST);
E.b = decl_b(b, nm.f("venc.l%d.b", L), RAD_BF16, { R[L], cout });
E.c = decl_b(b, nm.f("venc.l%d.c", L), RAD_BF16, { R[L], cout });
/* A level that changes the width takes its input in a buffer of that width, which the
@@ -2404,7 +2413,8 @@ static int declare_venc(RadBuilder* b, const RadModelMeta* meta, Model& m) {
* none. */
if (sc) {
const bool dn_in = (int64_t)sds[L - 1] == 2 || (int64_t)tds[L - 1] == 2;
E.in = dn_in ? decl_b(b, nm.f("venc.l%d.in", L), RAD_BF16, { R[L], cin })
E.in = dn_in ? decl_b(b, nm.f("venc.l%d.in", L), RAD_BF16, { R[L], cin },
RAD_BUF_TRANSIENT, RAD_DOMAIN_HOST)
: m.v_lv[(size_t)L - 1].a;
const char* sc_src = nm.ckpt("vae.encoder.down_blocks.%d.resnets.0.conv_shortcut", L);
E.scw = wh(nm.f("venc.l%d.sc.weight", L), nm.ckpt("%s.weight", sc_src),
+5 -1
View File
@@ -1264,7 +1264,11 @@ const RadBatch* VideoDriver::build_encode(Job& j, int step) {
for (size_t r = 0; r < ranks_.size(); ++r) {
const int ri = (int)r;
RadVideoGenBatch& V = vout_[(size_t)r];
V.enc_geom_d = dptr<int32_t>(ri, R_ENCG);
/* The encoder mixes device kernels with host-only k=1 convolutions and snake
* activations. Those host ops dereference their raw geometry operand directly;
* a rank's VRAM copy segfaults on discrete GPUs. The pinned staging table is
* readable by both execution sites and lives until this pass has completed. */
V.enc_geom_d = hptr<int32_t>(R_ENCG);
V.enc_kind = it.kind;
V.enc_slot = it.slot;
if (audio) {
+39 -2
View File
@@ -143,7 +143,7 @@ struct VideoFixture {
int start() { return drv.init(prog, fake_positions, { gen::VideoDriver::RankIO{} }); }
/* With the reference conditioning of a container with the video VAE's encoder, and the audio
* VAE's too when `audio`. */
int start_refs(bool audio = true) {
int start_refs(bool audio = true, int ranks = 1) {
RadVideoGenDecl& d = prog.video_gen;
d.max_ref_images = 9;
d.max_ref_videos = 3;
@@ -153,7 +153,8 @@ struct VideoFixture {
d.max_enc_samples = audio ? 500000 : 0;
d.enc_ratio = 16;
d.max_mod_cells = 8;
return drv.init(prog, fake_positions, { gen::VideoDriver::RankIO{} }, fake_pack,
return drv.init(prog, fake_positions,
std::vector<gen::VideoDriver::RankIO>((size_t)ranks), fake_pack,
fake_encode_geom);
}
std::unique_ptr<gen::VideoRequest> req(int32_t chunks = 2, int32_t steps = 0) {
@@ -1042,6 +1043,42 @@ TEST(a_reference_picture_is_encoded_shown_and_laid_into_the_step) {
CHECK_EQ(kinds, std::string("ECSSADD"));
}
/* Mixed host/device encoders read their small geometry on either execution site. All ranks
* must receive the shared pinned-host table, not their separate, CPU-inaccessible VRAM copies. */
TEST(reference_encoder_geometry_is_shared_by_host_and_device_ranks) {
VideoFixture f;
f.build();
CHECK_OK(f.start_refs(true, 2));
auto r = f.req(2);
r->refs.push_back(picture(gen::VideoRefMedia::FIRST_FRAME, "first_frame", 1, 64, 32));
r->refs.push_back(sound(gen::VideoRefMedia::AUDIO, "ref_audio_1", 1, 1000));
std::string why;
CHECK_OK(f.drv.submit(std::move(r), &why));
int encoded = 0;
for (int i = 0; i < 16; ++i) {
const RadBatch* b = f.drv.next(i);
if (!b) break;
if (b->gen == RAD_GEN_PASS_VENCODE || b->gen == RAD_GEN_PASS_AENCODE) {
const RadBatch* other = f.drv.batch_for(1);
REQUIRE(other != nullptr);
const int32_t* geometry = b->vgen_b->enc_geom_d;
REQUIRE(geometry != nullptr);
CHECK(geometry == other->vgen_b->enc_geom_d);
int32_t want[32] = {};
const bool audio = b->gen == RAD_GEN_PASS_AENCODE;
const int64_t in[4] = { audio ? 1000 : 1, audio ? 0 : 32,
audio ? 0 : 64, audio ? 2 : 3 };
const int64_t n = fake_encode_geom(b->gen, in, want, 32);
REQUIRE(n > 0);
for (int64_t j = 0; j < n; ++j) CHECK_EQ(geometry[j], want[j]);
++encoded;
}
f.answer(0);
CHECK_OK(f.drv.done());
}
CHECK_EQ(encoded, 2);
}
/* A first and a last frame at the video's size: one Vencode pass each, the keyframe table pinning
* frame 0 and the last frame, and their blocks ahead of the latents. */
TEST(a_keyframe_pair_is_encoded_and_pins_both_ends) {