Archived
radiance 1.13.0
New models: - Tencent Hy-Memory (HYV3) from its BF16, FP8 and GGUF checkpoints, with its native tool calls - M2XFP4: metadata-augmented MXFP4 weights for Qwen3.8-27B and its DFlash2 drafter (top-1 89.1% -> 92.4% against plain MXFP4), its quantiser and recipe, and ParoQuant's M2XFP4 checkpoints - Gemma 4 E2B/E4B audio input; NVIDIA-Nemotron-3.5-Bolt-E4B in int8 and 4-bit, on two cards by default; Ornith-1.5-122B compose files Speed: - Weight reads beside the decode all-reduces (qwen35_fp8, gemma3; --weight-prefetch, on by default): the 27B MXFP4 with DFlash2 61.2 -> 67.9 tok/s at c1, TranslateGemma 27B +13% - Head-256 split-KV decode attention at 256 workgroups and without bank conflicts (27B: +3-5% a step at 25-41K context), and the prefill KV split for small launches (a short turn over a long context decodes the other sequences 27% faster in that step) - MXFP4 decode gate_up, activation and fp8 quantiser in one launch (27B, Gemma 3 up to 64 rows: TranslateGemma +2-5% at 2-8 streams) - ParoQuant int4/int5 tiled GEMMs 6-9% faster - Speculation: a step's tokens are sent before the drafter's passes end, no step waits behind one that ends its requests, and the MTP head's first draft no longer collapses after short chats in the prefix cache Features: - --kv-resident N: KV streaming for a context bigger than VRAM (qwen4exp_fp8, GLM-5.3) - MiniMax-H3: reference media and keyframe conditioning with the VAE encoders - Krea 2 rebalance presets balanced, detail and subtle - The dashboard's request history; a stall watch that reports a frozen step's thread and stack - rad-tune at the served configuration, collectives measured as the exchange; Gemma 4 E2B/E4B's per-layer embeddings read ahead off the step path - A GPTQ calibration tap and recipe for Gemma 4 31B's w4a8 container Fixes: - The two-rank all-reduce checks that a peer's push has landed before reducing it - z-lab's DFlash drafter on Gemma 4 31B keeps drafting after a prefix-cache hit - MiniMax-H3's modulation rows Changes: Plugin ABI 31: out-of-tree plugins must be rebuilt. RADIANCE_PREFETCH_BESIDE is --weight-prefetch now; RADIANCE_NO_HUGE_PAGES, RADIANCE_IDS_EARLY, RADIANCE_ATTN_BAND_SPLIT, R4D_PREFILL_SPLITS, RAD_PLE_TIMING and RAD_PLE_CACHE_ROWS are gone.
This commit is contained in:
commit
6645337f69
198 files changed
+20904
-3240
No files matched your search
@@ -7,4 +7,9 @@ if(NOT COMMAND rad_add_plugin)
|
||||
rad_plugin_defaults()
|
||||
endif()
|
||||
|
||||
rad_add_plugin(minimaxh3 architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/minimaxh3.cpp)
|
||||
# rad_ref2va_pack.cpp holds the reference sequence's packing and rad_vae_geom.cpp the encoders'
|
||||
# geometry: pure host arithmetic, which tests/ref2va_pack_test.cpp and tests/vae_geom_test.cpp
|
||||
# compile in directly.
|
||||
rad_add_plugin(minimaxh3 architectures SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/minimaxh3.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rad_ref2va_pack.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rad_vae_geom.cpp)
|
||||
+1696
-168
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,301 @@
|
||||
/* rad_ref2va_pack.cpp -- see rad_ref2va_pack.h. The positions are computed in f64 as ComfyUI
|
||||
* computes them and stored in f32. */
|
||||
|
||||
#include "rad_ref2va_pack.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace minimaxh3 {
|
||||
|
||||
/* The pixel frames the k-th latent frame of a video covers, cycling, and the time a pixel frame
|
||||
* spans in soundtrack latents. */
|
||||
static const int kFramePerToken[5] = { 1, 4, 4, 4, 4 };
|
||||
static const double kFrameRescale = 5.0 / 3.0;
|
||||
|
||||
int ref2va_seg_tag(int kind) {
|
||||
switch (kind) {
|
||||
case kR2VText: return 1;
|
||||
case kR2VAudio: case kR2VCondAudio: case kR2VRefAudio: return 2;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int ref2va_is_img(int kind) {
|
||||
return kind == kR2VCond || kind == kR2VRefImg || kind == kR2VVideo;
|
||||
}
|
||||
|
||||
int ref2va_is_audio(int kind) {
|
||||
return kind == kR2VCondAudio || kind == kR2VRefAudio || kind == kR2VAudio;
|
||||
}
|
||||
|
||||
/* A side of `dim` latents in 2x2 patches: dim / 2 positions over
|
||||
* [(1 - ratio) / 2, (1 + ratio) / 2) x 32, ratio = dim / sqrt(h w), so every aspect spans the same
|
||||
* area. */
|
||||
static std::vector<double> axis_from_sqrt_area(int dim, int patch, double sqrt_area) {
|
||||
const double ratio = (double)dim / sqrt_area;
|
||||
const int n = dim / patch;
|
||||
std::vector<double> v((size_t)n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
v[(size_t)i] = ((double)i * (ratio / n) + (1.0 - ratio) / 2.0) * 32.0;
|
||||
return v;
|
||||
}
|
||||
|
||||
/* A latent frame's patches as (row, column) pairs, row-major, and the column axis, whose ends the
|
||||
* two soundtrack channels sit at. */
|
||||
static void frame_grid(int h, int w, std::vector<double>* frame, std::vector<double>* w_grid) {
|
||||
const double area = std::sqrt((double)h * (double)w);
|
||||
std::vector<double> hg = axis_from_sqrt_area(h, 2, area), wg = axis_from_sqrt_area(w, 2, area);
|
||||
frame->clear();
|
||||
frame->reserve(hg.size() * wg.size() * 2);
|
||||
for (const double& r : hg)
|
||||
for (const double& c : wg) { frame->push_back(r); frame->push_back(c); }
|
||||
*w_grid = std::move(wg);
|
||||
}
|
||||
|
||||
/* The time n latent frames of video span. */
|
||||
static double video_t_span_sum(int n) {
|
||||
double s = 0.0;
|
||||
for (int k = 0; k < n; ++k) s += kFrameRescale * (double)kFramePerToken[k % 5];
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Each latent frame's time: where the frames before it end. */
|
||||
static std::vector<double> video_t_grid(int n, double origin) {
|
||||
std::vector<double> g((size_t)n);
|
||||
double t = origin;
|
||||
for (int k = 0; k < n; ++k) {
|
||||
g[(size_t)k] = t;
|
||||
t += kFrameRescale * (double)kFramePerToken[k % 5];
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
/* The time a reference spans: a picture 1, a soundtrack its length, a video the longer of its two
|
||||
* streams. */
|
||||
static double ref_t_span(const Ref2VARef& r) {
|
||||
if (r.kind == kR2VRefImage) return 1.0;
|
||||
if (r.kind == kR2VRefAudioOnly) return (double)r.audio_t;
|
||||
return std::max((double)r.audio_t, video_t_span_sum(r.latent_t));
|
||||
}
|
||||
|
||||
/* A soundtrack's rows, the first channel's then the second's, a latent each at `cursor` onwards;
|
||||
* the channels sit at the two ends of the width axis, row 0. */
|
||||
static void audio_grid(double cursor, int t, double w_low, double w_high, std::vector<float>* pos) {
|
||||
if (!pos) return;
|
||||
for (int ch = 0; ch < 2; ++ch) {
|
||||
const double w = ch == 0 ? w_low : w_high;
|
||||
for (int i = 0; i < t; ++i) {
|
||||
pos->push_back((float)(cursor + (double)i));
|
||||
pos->push_back(0.0f);
|
||||
pos->push_back((float)w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* A video's rows: each latent frame's patches at its time. */
|
||||
static void video_grid(int vt, const std::vector<double>& frame, double origin,
|
||||
std::vector<float>* pos) {
|
||||
if (!pos) return;
|
||||
const std::vector<double> tg = video_t_grid(vt, origin);
|
||||
for (int k = 0; k < vt; ++k)
|
||||
for (size_t j = 0; j < frame.size(); j += 2) {
|
||||
pos->push_back((float)tg[(size_t)k]);
|
||||
pos->push_back((float)frame[j]);
|
||||
pos->push_back((float)frame[j + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
int ref2va_build(int text_len, const Ref2VAGeom& g, const std::vector<Ref2VAKeyframe>& keyframes,
|
||||
const std::vector<Ref2VARef>& refs, Ref2VAPack* out, bool positions) {
|
||||
if (text_len < 0 || g.latent_t < 0 || g.latent_h < 0 || g.latent_w < 0 || g.audio_t < 0)
|
||||
return -1;
|
||||
for (const Ref2VAKeyframe& kf : keyframes)
|
||||
if (kf.frame < 0 || kf.video_t < 0 || kf.audio_t < 0) return -1;
|
||||
for (const Ref2VARef& r : refs) {
|
||||
if (r.kind < kR2VRefImage || r.kind > kR2VRefVideoAudio) return -1;
|
||||
if (r.lat_h < 0 || r.lat_w < 0 || r.latent_t < 0 || r.audio_t < 0) return -1;
|
||||
}
|
||||
|
||||
Ref2VAPack p;
|
||||
std::vector<double> frame, w_grid;
|
||||
frame_grid(g.latent_h, g.latent_w, &frame, &w_grid);
|
||||
const size_t frame_rows = frame.size() / 2;
|
||||
const double w_low = w_grid.empty() ? 0.0 : w_grid.front();
|
||||
const double w_high = w_grid.empty() ? 0.0 : w_grid.back();
|
||||
|
||||
/* The prompt: its token positions on the time axis. */
|
||||
p.segs.push_back({ kR2VText, 0, (int64_t)text_len, 0 });
|
||||
std::vector<float>* pos = positions ? &p.pos : nullptr;
|
||||
for (int i = 0; i < text_len && pos; ++i) {
|
||||
p.pos.push_back((float)i);
|
||||
p.pos.push_back(0.0f);
|
||||
p.pos.push_back(0.0f);
|
||||
}
|
||||
int64_t row = text_len;
|
||||
|
||||
/* The video's clock, and the keyframes on it, starts after every reference's span. */
|
||||
double cursor = (double)text_len;
|
||||
for (const Ref2VARef& r : refs) cursor += ref_t_span(r);
|
||||
|
||||
/* A keyframe is on the video's grid, at its frame's time. */
|
||||
for (const Ref2VAKeyframe& kf : keyframes) {
|
||||
const double cond_t = cursor + kFrameRescale * (double)kf.frame;
|
||||
if (kf.video_t > 0) {
|
||||
const int64_t n = (int64_t)kf.video_t * (int64_t)frame_rows;
|
||||
video_grid(kf.video_t, frame, cond_t, pos);
|
||||
p.segs.push_back({ kR2VCond, row, row + n, 0 });
|
||||
row += n;
|
||||
}
|
||||
if (kf.audio_t > 0) {
|
||||
const int64_t n = (int64_t)kf.audio_t * 2;
|
||||
audio_grid(cond_t, kf.audio_t, w_low, w_high, pos);
|
||||
p.segs.push_back({ kR2VCondAudio, row, row + n, 0 });
|
||||
row += n;
|
||||
}
|
||||
}
|
||||
|
||||
/* The references in request order, each after the last. */
|
||||
cursor = (double)text_len;
|
||||
for (const Ref2VARef& r : refs) {
|
||||
if (r.kind == kR2VRefImage) {
|
||||
std::vector<double> rf, rw;
|
||||
frame_grid(r.lat_h, r.lat_w, &rf, &rw);
|
||||
const int64_t n = (int64_t)rf.size() / 2;
|
||||
for (int64_t i = 0; i < n && pos; ++i) {
|
||||
p.pos.push_back((float)cursor);
|
||||
p.pos.push_back((float)rf[(size_t)i * 2]);
|
||||
p.pos.push_back((float)rf[(size_t)i * 2 + 1]);
|
||||
}
|
||||
p.segs.push_back({ kR2VRefImg, row, row + n, 0 });
|
||||
row += n;
|
||||
cursor += 1.0;
|
||||
} else if (r.kind == kR2VRefAudioOnly) {
|
||||
if (r.audio_t > 0) {
|
||||
const int64_t n = (int64_t)r.audio_t * 2;
|
||||
audio_grid(cursor, r.audio_t, w_low, w_high, pos);
|
||||
p.segs.push_back({ kR2VRefAudio, row, row + n, 0 });
|
||||
row += n;
|
||||
}
|
||||
cursor += (double)r.audio_t;
|
||||
} else {
|
||||
/* A video's soundtrack, at the video's time and the ends of the video's own width
|
||||
* axis, comes right before it. */
|
||||
std::vector<double> rf, rw;
|
||||
frame_grid(r.lat_h, r.lat_w, &rf, &rw);
|
||||
if (r.audio_t > 0) {
|
||||
const int64_t n = (int64_t)r.audio_t * 2;
|
||||
audio_grid(cursor, r.audio_t, rw.empty() ? 0.0 : rw.front(),
|
||||
rw.empty() ? 0.0 : rw.back(), pos);
|
||||
p.segs.push_back({ kR2VRefAudio, row, row + n, 0 });
|
||||
row += n;
|
||||
}
|
||||
const int64_t n = (int64_t)r.latent_t * (int64_t)(rf.size() / 2);
|
||||
video_grid(r.latent_t, rf, cursor, pos);
|
||||
p.segs.push_back({ kR2VRefImg, row, row + n, 0 });
|
||||
row += n;
|
||||
cursor += std::max((double)r.audio_t, video_t_span_sum(r.latent_t));
|
||||
}
|
||||
}
|
||||
|
||||
/* The soundtrack and the video the sampler steps, last. */
|
||||
{
|
||||
const int64_t n = (int64_t)g.audio_t * 2;
|
||||
audio_grid(cursor, g.audio_t, w_low, w_high, pos);
|
||||
p.segs.push_back({ kR2VAudio, row, row + n, 1 });
|
||||
row += n;
|
||||
}
|
||||
{
|
||||
const int64_t n = (int64_t)g.latent_t * (int64_t)frame_rows;
|
||||
video_grid(g.latent_t, frame, cursor, pos);
|
||||
p.segs.push_back({ kR2VVideo, row, row + n, 1 });
|
||||
row += n;
|
||||
}
|
||||
|
||||
p.rows = row;
|
||||
if (positions) {
|
||||
/* From (t, h, w) triples to [3, rows]. */
|
||||
std::vector<float> tri = std::move(p.pos);
|
||||
p.pos.assign((size_t)row * 3, 0.0f);
|
||||
for (int64_t r = 0; r < row; ++r) {
|
||||
p.pos[(size_t)r] = tri[(size_t)r * 3];
|
||||
p.pos[(size_t)row + r] = tri[(size_t)r * 3 + 1];
|
||||
p.pos[2 * (size_t)row + r] = tri[(size_t)r * 3 + 2];
|
||||
}
|
||||
}
|
||||
*out = std::move(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A kind's modulation cell (rad_ref2va_pack.h): the latents and the prompt read their schedule's
|
||||
* embeddings, a keyframe or reference its stream's pinned ones. */
|
||||
static void cell_of_kind(int kind, int64_t S, int* md, int64_t* r0) {
|
||||
switch (kind) {
|
||||
case kR2VAudio: *md = 2; *r0 = S; break;
|
||||
case kR2VCondAudio:
|
||||
case kR2VRefAudio: *md = 2; *r0 = 3 * S; break;
|
||||
case kR2VText: *md = 1; *r0 = 0; break;
|
||||
case kR2VCond:
|
||||
case kR2VRefImg: *md = 0; *r0 = 2 * S; break;
|
||||
default: *md = 0; *r0 = 0; break;
|
||||
}
|
||||
}
|
||||
|
||||
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, const std::vector<Ref2VATagRun>& runs,
|
||||
Ref2VAModGroups* out) {
|
||||
out->bound.clear(); out->col.clear(); out->md.clear(); out->r0.clear();
|
||||
std::vector<Ref2VATagRun> sorted;
|
||||
for (const Ref2VATagRun& r : runs)
|
||||
if (r.end > r.start) sorted.push_back(r);
|
||||
std::sort(sorted.begin(), sorted.end(),
|
||||
[](const Ref2VATagRun& a, const Ref2VATagRun& b) { return a.start < b.start; });
|
||||
|
||||
/* The rows in pieces of one cell each: a segment is one, except the prompt, which the runs cut
|
||||
* into text and pad pieces, every one on the text's block. */
|
||||
struct Piece { int64_t start, end; int md; int64_t r0; };
|
||||
std::vector<Piece> pieces;
|
||||
for (const Ref2VASeg& s : p.segs) {
|
||||
if (s.end <= s.start) continue;
|
||||
if (s.kind != kR2VText) {
|
||||
Piece pc{ s.start, s.end, 0, 0 };
|
||||
cell_of_kind(s.kind, S, &pc.md, &pc.r0);
|
||||
pieces.push_back(pc);
|
||||
continue;
|
||||
}
|
||||
int64_t at = s.start;
|
||||
for (const Ref2VATagRun& r : sorted) {
|
||||
const int64_t a = std::max(r.start, at), b = std::min(r.end, s.end);
|
||||
if (a >= s.end) break;
|
||||
if (b <= a) continue;
|
||||
if (a > at) pieces.push_back({ at, a, 1, 0 });
|
||||
pieces.push_back({ a, b, r.tag, 0 });
|
||||
at = b;
|
||||
}
|
||||
if (at < s.end) pieces.push_back({ at, s.end, 1, 0 });
|
||||
}
|
||||
|
||||
/* A group opens where the cell changes; cells are numbered in their first group's order. */
|
||||
auto column_of = [&](int md, int64_t r0) {
|
||||
for (size_t c = 0; c < out->md.size(); ++c)
|
||||
if (out->md[c] == md && out->r0[c] == r0) return (int)c;
|
||||
out->md.push_back(md);
|
||||
out->r0.push_back(r0);
|
||||
return (int)out->md.size() - 1;
|
||||
};
|
||||
int cur = -1;
|
||||
bool open = false;
|
||||
int64_t prev_end = 0;
|
||||
for (const Piece& pc : pieces) {
|
||||
const int col = column_of(pc.md, pc.r0);
|
||||
if (!open || col != cur || pc.start != prev_end) {
|
||||
out->bound.push_back(open ? pc.start : 0);
|
||||
cur = col;
|
||||
open = true;
|
||||
out->col.push_back(col);
|
||||
}
|
||||
prev_end = pc.end;
|
||||
}
|
||||
if (open) out->bound.push_back(p.rows);
|
||||
}
|
||||
|
||||
} /* namespace minimaxh3 */
|
||||
@@ -0,0 +1,107 @@
|
||||
/* rad_ref2va_pack.h -- MiniMax-H3's packed sequence with keyframes and reference media, on the
|
||||
* host: ComfyUI's PackedLayout (comfy/ldm/minimax/model.py), tested against that code's own numbers
|
||||
* (tests/data/ref2va).
|
||||
*
|
||||
* The sequence is [text | keyframes | references in request order | soundtrack | video]. The
|
||||
* video's clock starts after every reference's time span; a keyframe sits on it at 5/3 a pixel
|
||||
* frame; a reference clip's soundtrack rows come right before its video rows, at the same time
|
||||
* origin. Keyframes and references keep a near-clean timestep; the sampler steps the last two
|
||||
* segments only.
|
||||
*/
|
||||
|
||||
#ifndef RAD_ARCH_MINIMAXH3_REF2VA_PACK_H
|
||||
#define RAD_ARCH_MINIMAXH3_REF2VA_PACK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace minimaxh3 {
|
||||
|
||||
/* Segment kinds, named as the reference implementation names them. */
|
||||
enum Ref2VAKind {
|
||||
kR2VText = 0, /* the prompt's hidden states */
|
||||
kR2VCond, /* a keyframe's video latent rows */
|
||||
kR2VCondAudio, /* a keyframe's soundtrack latent rows */
|
||||
kR2VRefImg, /* a reference photo, or a reference clip's video */
|
||||
kR2VRefAudio, /* a reference clip's (or standalone audio's) soundtrack */
|
||||
kR2VAudio, /* the target soundtrack -- sampler-owned */
|
||||
kR2VVideo, /* the target video -- sampler-owned */
|
||||
kR2VKinds
|
||||
};
|
||||
|
||||
/* A reference's kind; a video with a soundtrack of its own is either of the last two. */
|
||||
enum Ref2VARefKind { kR2VRefImage = 0, kR2VRefAudioOnly = 1, kR2VRefVideo = 2, kR2VRefVideoAudio = 3 };
|
||||
|
||||
/* A keyframe: the frame of the video it is pinned at and its latent frames of each stream. */
|
||||
struct Ref2VAKeyframe {
|
||||
int frame; /* >= 0 */
|
||||
int video_t; /* 0: none */
|
||||
int audio_t; /* 0: none */
|
||||
};
|
||||
|
||||
/* A reference, in latents: its own grid and frames for a picture or video, its soundtrack's
|
||||
* length for one that has sound. */
|
||||
struct Ref2VARef {
|
||||
int kind; /* Ref2VARefKind */
|
||||
int lat_h, lat_w;
|
||||
int latent_t;
|
||||
int audio_t;
|
||||
};
|
||||
|
||||
/* The target, in latent units. */
|
||||
struct Ref2VAGeom {
|
||||
int latent_t, latent_h, latent_w, audio_t;
|
||||
};
|
||||
|
||||
struct Ref2VASeg {
|
||||
int kind;
|
||||
int64_t start, end; /* rows [start, end) */
|
||||
int update; /* 1 for the soundtrack and the video the sampler steps */
|
||||
};
|
||||
|
||||
struct Ref2VAPack {
|
||||
std::vector<Ref2VASeg> segs;
|
||||
int64_t rows = 0;
|
||||
/* The rotary positions, [3, rows]: every row's time, then row, then column. */
|
||||
std::vector<float> pos;
|
||||
};
|
||||
|
||||
/* A kind's modality in the modulation (ComfyUI's seg_tag): 0 video, 1 text, 2 sound. */
|
||||
int ref2va_seg_tag(int kind);
|
||||
/* Whether a kind's rows are video latents or soundtrack latents; text is neither. */
|
||||
int ref2va_is_img(int kind);
|
||||
int ref2va_is_audio(int kind);
|
||||
/* A keyframe's or reference's timestep is the larger of its stream's and these. */
|
||||
constexpr double kR2VVisualPin = 0.999, kR2VAudioPin = 1.0;
|
||||
|
||||
/* The modulation groups: runs of consecutive rows that read the same modulation cell, which the
|
||||
* segment's kind fixes (`md` its modality's projection, `r0` its block of timestep embeddings) --
|
||||
* except inside the prompt, where a picture's vision pads read the video projection on the text's
|
||||
* block, as ComfyUI tags them (`runs`). The modulated norm takes the group boundaries, the attention
|
||||
* the segments'. Groups that share a cell read one column of the modulation table (`col`), so the
|
||||
* table grows with the distinct cells, not with the references or the pads: nine pictures add one
|
||||
* cell. The groups cover the sequence; an empty segment opens none. */
|
||||
struct Ref2VATagRun {
|
||||
int64_t start, end; /* prompt rows [start, end) */
|
||||
int tag; /* the projection they read: 0 video for vision pads */
|
||||
};
|
||||
struct Ref2VAModGroups {
|
||||
std::vector<int64_t> bound; /* [groups + 1], from 0 to the rows */
|
||||
std::vector<int> col; /* [groups]: the cell the group reads */
|
||||
std::vector<int> md; /* [cells]: 0 video, 1 text, 2 sound */
|
||||
std::vector<int64_t> r0; /* [cells] */
|
||||
};
|
||||
/* `S` is the steps a schedule has, and the embeddings are [0, S) the video's, [S, 2S) the
|
||||
* soundtrack's, then each again with its pin, [2S, 3S) and [3S, 4S). The boundaries do not depend
|
||||
* on S. `runs` may come in any order; the parts outside the prompt are ignored. Without runs every
|
||||
* group has a cell of its own. */
|
||||
void ref2va_mod_groups(const Ref2VAPack& p, int64_t S, const std::vector<Ref2VATagRun>& runs,
|
||||
Ref2VAModGroups* out);
|
||||
|
||||
/* The sequence, and its positions when `positions`; -1 for a negative size or an unknown kind. */
|
||||
int ref2va_build(int text_len, const Ref2VAGeom& g, const std::vector<Ref2VAKeyframe>& keyframes,
|
||||
const std::vector<Ref2VARef>& refs, Ref2VAPack* out, bool positions = true);
|
||||
|
||||
} /* namespace minimaxh3 */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/* rad_vae_geom.cpp -- see rad_vae_geom.h. */
|
||||
|
||||
#include "rad_vae_geom.h"
|
||||
|
||||
namespace minimaxh3 {
|
||||
|
||||
/* vae.py's encode_temporal for more than one frame, its plain encode for one. */
|
||||
int64_t vae_latent_frames(int64_t frames) {
|
||||
if (frames <= 0) return -1;
|
||||
if (frames == 1) return 1;
|
||||
const int64_t clips = (frames + kVaeClipLength - 1) / kVaeClipLength;
|
||||
return clips * kVaeClipLatents - kVaeTokenDrop;
|
||||
}
|
||||
|
||||
int64_t vae_clip_latents(int64_t frames) {
|
||||
if (frames <= 0) return -1;
|
||||
if (frames == 1) return 1;
|
||||
return (frames + 3) / 4; /* ceil(ceil(T / 2) / 2) */
|
||||
}
|
||||
|
||||
/* Every strided convolution (k = 2 s, pad ceil(s / 2)) divides a padded length exactly. */
|
||||
int64_t vae_audio_latents(int64_t samples) {
|
||||
if (samples < 0) return -1;
|
||||
return (samples + kAudioHop - 1) / kAudioHop;
|
||||
}
|
||||
|
||||
const double kVaeLatentsMean[24] = {
|
||||
0.858090341091156, -0.9606591463088989, 1.0661640167236328, -0.5090325474739075,
|
||||
-0.2727581858634949, -1.3675414323806763, -0.2553254961967468, -0.26907554268836975,
|
||||
-0.5376840829849243, -0.0464097298681736, 0.6657370328903198, 0.19690127670764923,
|
||||
-0.5460608005523682, -0.4035342037677765, -0.23683024942874908, 0.25928452610969543,
|
||||
-0.30133944749832153, 0.211341992020607, -1.1206848621368408, 0.3581933379173279,
|
||||
-0.04225143790245056, 0.2604829967021942, 0.22864092886447906, 0.7056031823158264,
|
||||
};
|
||||
|
||||
const double kVaePixelMean[3] = { 0.485, 0.456, 0.406 };
|
||||
const double kVaePixelStd[3] = { 0.229, 0.224, 0.225 };
|
||||
|
||||
const double kVaeLatentsStd[24] = {
|
||||
1.2223774194717407, 1.2767263650894165, 1.68317747116088865, 1.7549455165863037,
|
||||
1.5636216402053833, 2.194143533706665, 0.96531379222869875, 1.05698859691619875,
|
||||
0.841948926448822, 0.7729952931404114, 1.8955937623977661, 0.946841835975647,
|
||||
0.7996809482574463, 0.44988900423049925, 0.7197399735450745, 0.69362932443618775,
|
||||
2.961095094680786, 2.7694199085235595, 3.0496184825897215, 2.1088054180145265,
|
||||
3.276226282119751, 3.1627357006073, 2.28168129920959475, 2.6127843856811525,
|
||||
};
|
||||
|
||||
} /* namespace minimaxh3 */
|
||||
@@ -0,0 +1,43 @@
|
||||
/* rad_vae_geom.h -- the latents MiniMax-H3's VAE encoders make of a media's frames or samples,
|
||||
* and their normalisation constants, on the host. ComfyUI's comfy/ldm/minimax/vae.py and
|
||||
* audio_vae.py, tested against those encoders' own outputs (tests/data/vae_geom). */
|
||||
|
||||
#ifndef RADIANCE_ARCH_MINIMAXH3_RAD_VAE_GEOM_H
|
||||
#define RADIANCE_ARCH_MINIMAXH3_RAD_VAE_GEOM_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace minimaxh3 {
|
||||
|
||||
/* The video VAE: 16 pixels a latent side, and in time clips of 17 frames to 5 latent frames
|
||||
* (17 -> 9 -> 5), of which an encode of more than one frame drops the last 3. */
|
||||
constexpr int kVaeRatio = 16;
|
||||
constexpr int kVaeClipLength = 17;
|
||||
constexpr int kVaeClipLatents = 5;
|
||||
constexpr int kVaeTokenDrop = 3;
|
||||
|
||||
/* The audio VAE: strides 2 4 4 5 5, a latent per 800 samples (40 a second at 32 kHz), the samples
|
||||
* padded with zeros to a whole latent. */
|
||||
constexpr int kAudioHop = 800;
|
||||
|
||||
/* The latent frames of `frames` pixel frames: 1 for a picture, else 5 a clip of 17 (the last
|
||||
* padded by repeating its last frame) less 3. -1 for no frames. */
|
||||
int64_t vae_latent_frames(int64_t frames);
|
||||
|
||||
/* The latent frames one clip of `frames` encodes to, ceil(T / 4) (one frame stays one). */
|
||||
int64_t vae_clip_latents(int64_t frames);
|
||||
|
||||
/* The latents of `samples` samples; -1 for a negative count. */
|
||||
int64_t vae_audio_latents(int64_t samples);
|
||||
|
||||
/* A video latent is normalised as (moments - mean) / std, vae.py's LATENTS_MEAN and LATENTS_STD. */
|
||||
extern const double kVaeLatentsMean[24];
|
||||
extern const double kVaeLatentsStd[24];
|
||||
|
||||
/* A pixel x in [0, 1] goes in as (x - mean) / std, ImageNet's. */
|
||||
extern const double kVaePixelMean[3];
|
||||
extern const double kVaePixelStd[3];
|
||||
|
||||
} /* namespace minimaxh3 */
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user