This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/data/ref2va/gen_golden.py
T
Deadcode 6645337f69 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.
2026-10-27 16:47:35 +01:00

127 lines
6.0 KiB
Python

#!/usr/bin/env python3
"""Regenerate golden.json -- the reference numbers arch/minimaxh3/rad_ref2va_pack.cpp is tested
against (tests/ref2va_pack_test.cpp).
gen_golden.py /path/to/ComfyUI/comfy/ldm/minimax/model.py [out.json]
The reference implementation lives in the ComfyUI tree; importing its package pulls the whole
device stack, so this extracts exactly the layout's source -- the four constants, the grid helpers
and the PackedLayout class -- with `ast`, execs them on torch alone, and runs the cases below.
Nothing here is a re-derivation: every number in golden.json is computed by the reference code
itself, at float64, from the file it is given. When a new version of the reference changes
golden.json, the port changes with it.
"""
import ast
import json
import sys
NEED = ["_axis_from_sqrt_area", "_frame_grid", "_video_t_spans", "_video_t_grid", "_ref_t_span",
"_audio_grid", "_video_grid", "PackedLayout"]
NEED_ASSIGN = ["FRAME_PER_TOKEN", "FRAME_RESCALE", "VISUAL_COND_TIMESTEP", "AUDIO_COND_TIMESTEP"]
def dump(v, f, ind=0):
"""JSON with an object a key a line and every list on one line, so a golden diffs by key."""
if isinstance(v, dict) and v:
pad = " " * (ind + 1)
items = list(v.items())
f.write("{\n")
for i, (k, x) in enumerate(items):
f.write(pad + json.dumps(k) + ": ")
dump(x, f, ind + 1)
f.write(",\n" if i + 1 < len(items) else "\n")
f.write(" " * ind + "}")
else:
f.write(json.dumps(v, separators=(", ", ": ")))
def extract(path):
"""The reference's layout source, exec'd with torch/math only."""
import math
import torch
with open(path) as f:
src = f.read()
tree = ast.parse(src)
picked, got = [], set()
for node in tree.body:
names = ([t.id for t in node.targets if isinstance(t, ast.Name)]
if isinstance(node, ast.Assign) else
[node.name] if isinstance(node, (ast.FunctionDef, ast.ClassDef)) else [])
if any(n in NEED or n in NEED_ASSIGN for n in names):
picked.append(ast.get_source_segment(src, node))
got.update(names)
missing = (set(NEED) | set(NEED_ASSIGN)) - got
if missing:
sys.exit(f"{path} does not define: {sorted(missing)} -- reference moved?")
ns = {"math": math, "torch": torch}
exec("\n\n".join(picked), ns)
return ns
CASES = {
# plain t2va: the pack keeps the three segments [text | audio | video] exactly
"t2va": dict(text_len=5, target=(3, 8, 10, 4), keyframes=[], refs=[]),
# fl2va keyframes at frame 0 (shares the target origin) and mid-timeline, video-only and both
"fl2va": dict(text_len=4, target=(3, 8, 8, 3),
keyframes=[dict(frame=0, video_t=1, audio_t=2), dict(frame=7, video_t=2, audio_t=0)],
refs=[]),
# every reference kind in one request: a photo, a standalone soundtrack, a silent clip, and a
# clip with sound (its audio packs before its video, at the clip's own width extremes); a
# second photo after them; audio_t=0 targets the silent-video edge
"ref2va_all": dict(text_len=6, target=(2, 8, 8, 0),
keyframes=[],
refs=[dict(kind="image", latent_h=6, latent_w=10, latent_t=0, ref_audio_t=0),
dict(kind="audio", latent_h=0, latent_w=0, latent_t=0, ref_audio_t=3),
dict(kind="video", latent_h=4, latent_w=6, latent_t=2, ref_audio_t=0),
dict(kind="video_audio", latent_h=5, latent_w=7, latent_t=3,
ref_audio_t=4),
dict(kind="image", latent_h=4, latent_w=4, latent_t=0, ref_audio_t=0)]),
# a request at plausible sizes: a keyframe, a large photo and a clip with sound
"chain": dict(text_len=32, target=(7, 16, 24, 6),
keyframes=[dict(frame=0, video_t=1, audio_t=2)],
refs=[dict(kind="image", latent_h=8, latent_w=12, latent_t=0, ref_audio_t=0),
dict(kind="video_audio", latent_h=4, latent_w=6, latent_t=5,
ref_audio_t=20)]),
# degenerate prompt: text_len 0, nothing but targets
"no_text": dict(text_len=0, target=(2, 4, 6, 1), keyframes=[], refs=[]),
}
def main():
import torch
model_py = sys.argv[1]
out = sys.argv[2] if len(sys.argv) > 2 else "golden.json"
ns = extract(model_py)
PackedLayout = ns["PackedLayout"]
golden = {}
for name, c in CASES.items():
t, ah, aw, at = c["target"]
refs = [dict(kind=r["kind"], latent_h=r["latent_h"], latent_w=r["latent_w"],
latent_t=r["latent_t"], ref_audio_t=r["ref_audio_t"]) for r in c["refs"]]
# the class reads only the latents' shapes (video .shape[2], audio .shape[-1]); zeros do
kfs = [dict(resolved_frame_index=k["frame"],
latent=torch.zeros(1, 24, k["video_t"], ah, aw) if k["video_t"] else None,
audio_latent=torch.zeros(1, 32, 2, k["audio_t"]) if k["audio_t"] else None)
for k in c["keyframes"]]
lay = PackedLayout(c["text_len"], t, ah, aw, at, keyframes=kfs or None, refs=refs or None)
golden[name] = {
"text_len": c["text_len"], "latent_t": t, "latent_h": ah, "latent_w": aw,
"audio_t": at,
"keyframes": c["keyframes"], "refs": c["refs"],
"seq_len": lay.seq_len,
"segments": [[s, e, k] for (s, e, k) in lay.segments],
"positions": [[float(x) for x in row] for row in lay.position_ids.tolist()],
"img_update": [bool(b) for b in lay.img_update.tolist()],
"audio_update": [bool(b) for b in lay.audio_update.tolist()],
"img_pos": [int(i) for i in lay.img_pos.tolist()],
"audio_pos": [int(i) for i in lay.audio_pos.tolist()],
}
with open(out, "w") as f:
dump(golden, f)
f.write("\n")
print(f"{out}: " + ", ".join(f"{n} {g['seq_len']} rows" for n, g in golden.items()))
main()