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:
Deadcode committed 2026-10-27 16:47:35 +01:00
198 files changed
+20904 -3240

No files matched your search

@@ -0,0 +1,68 @@
# ComfyUI-Radiance-MiniMax
One ComfyUI node, **Radiance MiniMax**, that renders a clip on a radiance server serving
MiniMax-H3 (`POST /v1/videos`) and returns it. The node is an HTTP client: the model runs in the
radiance server process, on the same machine or another one, and ComfyUI holds no model and no
VRAM for it. Several nodes can drive several servers from one ComfyUI.
Install it by copying this folder into `ComfyUI/custom_nodes/` and restarting ComfyUI. The node's
description (the **?** in its header) documents every input.
## The server
radiance --model minimax-h3-fp8.rad --radiance-home ... --tp 2 \
--host 0.0.0.0 --port 8133 --lora-dir /path/to/loras
`--host 0.0.0.0` makes the server reachable from other machines. The node sends no API key, so
it drives a server without `--api-key`, which takes any request: keep that server on a trusted
network. The node fetches the adapter lists from the browser, which needs the server's CORS
headers (on unless `--no-cors`).
`--lora-dir` lets a request name any `NAME.safetensors` under the directory; the node's two
adapter lists show them (`GET /v1/loras`). Pointing it at ComfyUI's `models/loras` serves the
same files ComfyUI shows. ComfyUI's Load LoRA node does not apply to this node, since the server
applies adapters to the weights it serves.
The server reserves every adapter slot in VRAM at startup and logs what a slot costs. With
`--lora-dir` alone it reserves two (`--max-loras`). On two 32 GB cards serving MiniMax-H3 a
rank-16 slot costs about 265 MiB a card, and the second one fits only when nothing else holds
VRAM on those cards. When it does not, startup stops with `vram_kv resolved to 0 MiB`: serve
with `--max-loras 1` and leave the node's second adapter at `none`, or run ComfyUI on other
cards.
## Media
| task | media used |
|---|---|
| `t2va` | none |
| `i2va` | `image_1`: the first frame |
| `l2va` | `image_1`: the last frame |
| `fl2va` | `image_1`: the first frame, `image_2`: the last frame |
| `ref2va` | `image_1..9`, `video_1..3`, `video_audio_1..3`, `audio_1..3` |
A task ignores media it does not use, with a warning on the console. For `ref2va`,
`video_audio_N` is the soundtrack of `video_N`, and `audio_N` is standalone reference audio such
as a voice. Each kind is filled in order, since the input's number is the reference's number in
the request. Pictures are sent as PNG, audio as WAV and clips as MP4.
## Sizes
The resolution tier is the short side and the aspect gives the long side (480p 16:9 is
864x480); the node's title shows the size. MiniMax-H3 takes sides that are multiples of 32 px
and at least 256, an aspect of at most 4:1 and an area of at most 1344x768, so 720p 16:9 is
1312x736. A `custom` size is adjusted to the nearest size the model takes, with a note on the
console. Every task takes every size.
`latent_upscale` (advanced) runs the early steps at half or a quarter of the size and the rest
at full size, with a container converted with the latent upscaler. The keyframe tasks do not take
it.
## Outputs
The clip is saved under `radiance/` in ComfyUI's output folder and returned as a `VIDEO`, with
its path and the server's job id (`GET /v1/videos/<id>`). While the job runs, the node drives
the progress bar and prints a console line for each finished step:
[RadianceMiniMax] video_x: 45%, step 12/26, 5.2 s/step, eta ~1m 07s and the decode, elapsed 55s
A refused or failed job raises with the server's message; `timeout` (advanced) bounds the wait.
@@ -0,0 +1,10 @@
from .radiance_node import RadianceMiniMax
# web/ holds the frontend extension: the request's size in the node's title, and the adapter
# lists fetched from the server.
WEB_DIRECTORY = "./web"
NODE_CLASS_MAPPINGS = {"RadianceMiniMax": RadianceMiniMax}
NODE_DISPLAY_NAME_MAPPINGS = {"RadianceMiniMax": "Radiance MiniMax (server)"}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
@@ -0,0 +1,495 @@
"""Radiance MiniMax: a ComfyUI node that renders a clip on a radiance server serving MiniMax-H3.
The node is an HTTP client of POST /v1/videos: the model runs in the radiance server process, on
this machine or another, and the node holds no model and no VRAM. The node's description (its ?
pane) documents every input; README.md documents the server side.
"""
import io as _io
import json
import logging
import os
import re
import tempfile
import time
import wave
import requests
import folder_paths
from comfy_api.latest import io, ui, Types
from comfy_api.input_impl import VideoFromFile
POLL_SECONDS = 3.0
KEEPALIVE_SECONDS = 30.0
LOG = "RadianceMiniMax"
# The size law the minimaxh3 plugin declares (arch/minimaxh3/minimaxh3.cpp): sides multiples of
# 32 px and at least 256, an aspect of at most 4:1, an area of at most 1344 x 768. The server
# enforces it; the node applies it first so the title can show the size a request will carry.
SIZE_MULT, MIN_SIDE = 32, 256
MAX_AREA, MAX_ASPECT = 1344 * 768, 4.0
# A tier is the short side; the aspect gives the long side. 720p is the last tier whose canvas
# fits the area at 16:9.
TIERS = {"144p": 144, "240p": 240, "360p": 360, "480p": 480, "540p": 540,
"576p": 576, "720p": 720}
ASPECTS = ["5:4", "4:3", "3:2", "16:9", "2:1", "1:1", "1:2", "9:16", "2:3", "3:4", "4:5"]
# The keyframe tasks and the form field each of their images goes in.
KEYFRAMES = {"i2va": ["first_frame"], "l2va": ["last_frame"],
"fl2va": ["first_frame", "last_frame"]}
DESCRIPTION = """Renders video and audio on a **radiance server serving MiniMax-H3**
(`POST /v1/videos`). The node is an HTTP client: the model runs in the server process and the
node holds no VRAM.
## Media by task
| task | media used |
|---|---|
| `t2va` | none |
| `i2va` | `image_1`: the first frame |
| `l2va` | `image_1`: the last frame |
| `fl2va` | `image_1`: the first frame, `image_2`: the last frame |
| `ref2va` | every media input |
A task ignores the media it does not use, with a warning on the console. For `ref2va`:
- **image_1..image_9**: reference pictures (subjects, settings, style).
- **video_1..video_3**: reference clips (motion, camera).
- **video_audio_1..video_audio_3**: the soundtrack of `video_N`; `video_N` must be connected.
- **audio_1..audio_3**: standalone reference audio, such as a voice.
Fill each kind in order, without gaps: the input's number is the reference's number in the
request (`<Picture 2>`, `<Video 1>`).
## Inputs
- **prompt**: a widget and an input; a connected string replaces the typed text. The model is
trained on MiniMax's structured prompt (`subject_definitions`, `summary`,
`retention_analysis`, `detailed_description`, `<Picture N>` and similar tags, timed shots,
`<d>[English] ...</d>` dialogue); a one-line prompt makes poor audio.
- There is **no negative prompt**: MiniMax-H3 is guidance-distilled, one forward pass a step,
and the server refuses a `negative_prompt`.
- **lora 1, lora 2**: adapters the server offers (`GET /v1/loras`, files under its
`--lora-dir`), each with its own strength; `none` is off. The lists are fetched when the
node is created or loaded, when `server_url` changes, and by **refresh lora list**. ComfyUI's
Load LoRA node does not apply here: the server applies adapters to the weights it serves.
- **resolution, aspect**: the tier is the short side and the aspect gives the long side,
480p 16:9 is 864x480; the node's title shows the result. Sides are multiples of 32 px, at
least 256, within an area of 1344x768, so 720p 16:9 is 1312x736. `custom` takes any WxH and
adjusts it to the nearest size the model takes, with a note on the console.
- **seconds, seed, num_inference_steps, sampler, shift, audio_shift**: as the server takes
them; `sampler` is `euler` or `res_multistep`. The server reads the seed as a double, so the
seed stops at 2^53 - 1, the largest it holds exactly.
- **latent_upscale** (advanced): with a container that has the latent upscaler, the early steps
run at half or a quarter of the size and the rest at full size. The keyframe tasks do not
take it, since a keyframe is pinned on the full-size grid.
- **server_url, model**: the server (`http://<host>:8133`) and the model id it serves
(`GET /v1/models`).
## Outputs
The clip is saved under `radiance/` in the output folder and returned as a `VIDEO`, with its
path and the server's job id. While the job runs, the node drives the progress bar and prints a
line to the console for each finished step, with the measured seconds a step and an estimate of
the time left; `timeout` (advanced) bounds the wait."""
def _image_png(image):
"""The first image of a ComfyUI IMAGE batch ([B, H, W, C] in 0..1) as PNG bytes."""
import torch
from PIL import Image
arr = image[0].cpu().clamp(0.0, 1.0).mul(255.0).to(dtype=torch.uint8).numpy()
buf = _io.BytesIO()
Image.fromarray(arr, "RGB").save(buf, format="PNG")
return "image.png", buf.getvalue(), "image/png"
def _audio_wav(audio):
"""The first clip of a ComfyUI AUDIO ({'waveform': [B, C, N] in -1..1, 'sample_rate'}) as
16-bit WAV bytes."""
import torch
pcm = (audio["waveform"][0].transpose(0, 1).clamp(-1.0, 1.0) * 32767.0).cpu().to(
dtype=torch.int16).contiguous().numpy()
buf = _io.BytesIO()
with wave.open(buf, "wb") as w:
w.setnchannels(pcm.shape[1])
w.setsampwidth(2)
w.setframerate(int(audio["sample_rate"]))
w.writeframes(pcm.reshape(-1).tobytes())
return "audio.wav", buf.getvalue(), "audio/wav"
def _video_mp4(video):
"""A ComfyUI VIDEO as MP4 bytes, through its own save_to (a stream copy when the source is
an MP4 already)."""
fd, path = tempfile.mkstemp(suffix=".mp4")
os.close(fd)
try:
video.save_to(path, format=Types.VideoContainer.MP4)
with open(path, "rb") as f:
return "video.mp4", f.read(), "video/mp4"
finally:
os.unlink(path)
def _leading(items, prefix):
"""The number of connected inputs at the front of `items`; a gap is refused, since the
input's number is the reference's number in the request."""
n = 0
while n < len(items) and items[n] is not None:
n += 1
for i in range(n, len(items)):
if items[i] is not None:
raise ValueError(f"{prefix}_{i + 1} is connected but {prefix}_{n + 1} is not: "
"fill the inputs in order")
return n
def _fit(w, h):
"""The largest size at about the w:h ratio within the size law, sides rounded down to the
size multiple."""
s = (MAX_AREA / float(w * h)) ** 0.5
fw = max(MIN_SIDE, int(w * s) // SIZE_MULT * SIZE_MULT)
fh = max(MIN_SIDE, int(h * s) // SIZE_MULT * SIZE_MULT)
while fw * fh > MAX_AREA: # the 256 floor can lift a narrow ratio over the area
if fw >= fh and fw > MIN_SIDE:
fw -= SIZE_MULT
elif fh > MIN_SIDE:
fh -= SIZE_MULT
else:
break
if max(fw, fh) > MAX_ASPECT * min(fw, fh): # the rounding can tip a 4:1 ratio over
if fw >= fh:
fw = int(MAX_ASPECT * fh) // SIZE_MULT * SIZE_MULT
else:
fh = int(MAX_ASPECT * fw) // SIZE_MULT * SIZE_MULT
return fw, fh
def _snap(v):
"""The nearest multiple of the size multiple, halves up, at least the smallest side."""
return max(MIN_SIDE, (v + SIZE_MULT // 2) // SIZE_MULT * SIZE_MULT)
def _custom_size(text):
"""A typed WxH adjusted to the size law: each side to the nearest multiple, then scaled back
at the same ratio when the aspect or the area is over."""
m = re.match(r"(\d+)\s*[xX×*]\s*(\d+)", text.strip())
if not m:
raise ValueError(f'"{text}" is not a size: give WIDTHxHEIGHT, such as 512x512')
w, h = int(m.group(1)), int(m.group(2))
lw, lh = _snap(w), _snap(h)
if lw * lh > MAX_AREA or max(lw, lh) > MAX_ASPECT * min(lw, lh):
lw, lh = _fit(lw, lh)
if (lw, lh) != (w, h):
logging.warning(f"[{LOG}] size {w}x{h} adjusted to {lw}x{lh}: sides multiples of "
f"{SIZE_MULT} px and at least {MIN_SIDE}, an aspect of at most "
f"{MAX_ASPECT:.0f}:1, an area of at most {MAX_AREA} px")
return f"{lw}x{lh}"
def _tier_size(tier, aspect):
"""The tier's short side and the aspect's long side, both snapped, the pair scaled back when
the area is over; WxH in the aspect's orientation."""
a, b = (int(x) for x in aspect.split(":"))
hi, lo = max(a, b), min(a, b)
short = _snap(TIERS[tier])
long_ = max(short, _snap(int(short * hi / lo)))
if long_ * short > MAX_AREA:
long_, short = _fit(long_, short)
return f"{long_}x{short}" if a >= b else f"{short}x{long_}"
def _resolve_size(resolution, aspect, custom=""):
"""The request's size. ComfyUI hands a DynamicCombo over as a dict of the chosen option and
its own inputs."""
if isinstance(resolution, dict):
custom = resolution.get("custom_size", custom)
resolution = resolution.get("resolution", "")
if resolution == "custom":
return _custom_size(custom)
if resolution not in TIERS:
raise ValueError(f"unknown resolution {resolution!r}: one of {', '.join(TIERS)} or custom")
return _tier_size(resolution, aspect)
def _fmt_secs(s):
"""Whole seconds, or minutes and seconds from 90 s up."""
s = int(max(0.0, float(s)) + 0.5)
return f"{s}s" if s < 90 else f"{s // 60}m {s % 60:02d}s"
class _Pace:
"""Seconds a step, measured from the job's steps_done between polls. A poll every 3 s sees a
longer step as a single increment, so the time between two polls is not a step's time: the
rate is taken over at least two steps, then smoothed so it follows a change of pace, such as
a latent-upscaled job moving to the full-size grid."""
def __init__(self):
self.t = None
self.done = None
self.sps = None
def update(self, job, now):
done = job.get("steps_done")
if not isinstance(done, int):
return self.sps
if self.t is None:
if done > 0: # from the first finished step, so the encoders' time is not a step's
self.t, self.done = now, done
elif done - self.done >= 2:
rate = (now - self.t) / (done - self.done)
if rate > 0:
self.sps = rate if self.sps is None else 0.4 * rate + 0.6 * self.sps
self.t, self.done = now, done
return self.sps
def _progress_line(job, elapsed, sps):
"""The console line for a poll: progress, steps, pace, time left and time taken."""
if job.get("status") == "queued":
return f"queued, elapsed {_fmt_secs(elapsed)}"
p = job.get("progress")
p = float(p) if isinstance(p, (int, float)) else 0.0
parts = [f"{p:.0f}%"]
done, total = job.get("steps_done"), job.get("steps_total")
steps = isinstance(done, int) and isinstance(total, int) and total > 0
if steps:
parts.append(f"step {done}/{total}")
if sps:
parts.append(f"{sps:.1f} s/step")
if steps and sps and 0 < done < total:
parts.append(f"eta ~{_fmt_secs((total - done) * sps)} and the decode")
elif steps and done == total:
parts.append("decoding")
parts.append(f"elapsed {_fmt_secs(elapsed)}")
return ", ".join(parts)
def _progress_bar(node_cls):
"""ComfyUI's progress bar for this node over 0..100, or None outside ComfyUI's executor."""
uid = getattr(getattr(node_cls, "hidden", None), "unique_id", None)
try:
from comfy.utils import ProgressBar
return ProgressBar(100.0, node_id=uid)
except Exception:
return None
class RadianceMiniMax(io.ComfyNode):
@classmethod
def define_schema(cls):
images = [io.Image.Input(f"image_{i}", optional=True) for i in range(1, 10)]
videos = [io.Video.Input(f"video_{i}", optional=True) for i in range(1, 4)]
tracks = [io.Audio.Input(f"video_audio_{i}", optional=True) for i in range(1, 4)]
audios = [io.Audio.Input(f"audio_{i}", optional=True) for i in range(1, 4)]
images[0].tooltip = ("ref2va: reference picture 1; i2va and fl2va: the first frame; "
"l2va: the last frame")
images[1].tooltip = "ref2va: reference picture 2; fl2va: the last frame"
for im in images[2:]:
im.tooltip = "ref2va: a reference picture"
for i, v in enumerate(videos):
v.tooltip = (f"ref2va: reference clip {i + 1}; its soundtrack goes in "
f"video_audio_{i + 1}")
for i, a in enumerate(tracks):
a.tooltip = f"ref2va: the soundtrack of video_{i + 1}"
for i, a in enumerate(audios):
a.tooltip = f"ref2va: standalone reference audio {i + 1}, such as a voice"
return io.Schema(
node_id="RadianceMiniMax",
display_name="Radiance MiniMax",
category="video/radiance",
description=DESCRIPTION,
inputs=[
io.String.Input("server_url", default="http://127.0.0.1:8133",
tooltip="the radiance server, http://<host>:<port>"),
io.String.Input("model", default="minimax-h3",
tooltip="the model id the server serves (GET /v1/models)"),
io.Combo.Input("loras", options=["none"], default="none", display_name="lora 1",
tooltip="an adapter the server offers (GET /v1/loras); 'none' "
"is off"),
io.Float.Input("lora_strength", default=1.0, min=0.0, max=2.0, step=0.05,
display_name="lora 1 strength"),
io.Combo.Input("lora2", options=["none"], default="none", display_name="lora 2",
tooltip="a second adapter; the server needs --max-loras 2, "
"its default with --lora-dir"),
io.Float.Input("lora2_strength", default=1.0, min=0.0, max=2.0, step=0.05,
display_name="lora 2 strength"),
io.Combo.Input("task", options=["t2va", "i2va", "l2va", "fl2va", "ref2va"],
tooltip="which media inputs are used: see the node's description"),
io.String.Input("prompt", multiline=True, default="",
tooltip="a connected string replaces the typed text"),
# DynamicCombo.Input takes no default; web/radiance_size.js sets new nodes to 480p.
io.DynamicCombo.Input(
"resolution",
options=[
*(io.DynamicCombo.Option(t, []) for t in TIERS),
io.DynamicCombo.Option("custom", [
io.String.Input("custom_size", display_name="WIDTHxHEIGHT",
default="512x512"),
]),
],
tooltip="the short side; the aspect gives the long side, and the node's "
"title shows the size. custom takes any WxH and adjusts it to the "
"model's sizes"),
io.Combo.Input("aspect", options=ASPECTS, default="16:9",
tooltip="width:height for a tier; a custom size ignores it"),
io.Int.Input("seconds", default=12, min=1, max=120, step=1),
io.Int.Input("seed", default=1234, min=0, max=2**53 - 1, step=1,
tooltip="up to 2^53 - 1, the largest seed the server holds exactly"),
io.Int.Input("num_inference_steps", default=25, min=1, max=200, step=1),
io.Combo.Input("sampler", options=["euler", "res_multistep"]),
io.Float.Input("shift", default=12.0, min=0.0, max=100.0, step=0.5),
io.Float.Input("audio_shift", default=3.0, min=0.0, max=100.0, step=0.5),
io.Combo.Input("latent_upscale", options=["off", "2", "4"], default="off",
advanced=True,
tooltip="run the early steps at 1/2 or 1/4 of the size, with a "
"container that has the latent upscaler; not with "
"keyframes"),
*images, *videos, *tracks, *audios,
io.Int.Input("timeout", default=1800, min=30, max=7200, step=30, advanced=True,
tooltip="seconds to wait for the job"),
],
hidden=[io.Hidden.unique_id],
outputs=[
io.Video.Output("video"),
io.String.Output("file", display_name="file",
tooltip="the saved clip's path in the output folder"),
io.String.Output("job_id", display_name="job id"),
],
)
@classmethod
def validate_inputs(cls, loras, lora2):
"""The adapter lists are the server's, filled in by the frontend, so a chosen adapter is
not among the schema's options. ComfyUI checks an input against its options only when
validate_inputs does not take it; the server checks the names."""
return True
@classmethod
def execute(cls, server_url, model, task, prompt, resolution, aspect, seconds, seed,
num_inference_steps, sampler, shift, audio_shift, timeout=1800,
latent_upscale="off", loras="none", lora_strength=1.0, lora2="none",
lora2_strength=1.0, **media):
size = _resolve_size(resolution, aspect, media.pop("custom_size", ""))
prompt = (prompt or "").strip()
if not prompt:
raise ValueError("the prompt is empty")
images = [media.get(f"image_{i}") for i in range(1, 10)]
videos = [media.get(f"video_{i}") for i in range(1, 4)]
tracks = [media.get(f"video_audio_{i}") for i in range(1, 4)]
audios = [media.get(f"audio_{i}") for i in range(1, 4)]
parts = [] # (form field, (file name, bytes, media type))
if task == "ref2va":
n_img = _leading(images, "image")
n_vid = _leading(videos, "video")
n_aud = _leading(audios, "audio")
for i, a in enumerate(tracks):
if a is not None and videos[i] is None:
raise ValueError(f"video_audio_{i + 1} is the soundtrack of video_{i + 1}, "
"which is not connected")
parts += [(f"ref_image_{i + 1}", _image_png(images[i])) for i in range(n_img)]
parts += [(f"ref_video_{i + 1}", _video_mp4(videos[i])) for i in range(n_vid)]
parts += [(f"ref_video_audio_{i + 1}", _audio_wav(a))
for i, a in enumerate(tracks) if a is not None]
parts += [(f"ref_audio_{i + 1}", _audio_wav(audios[i])) for i in range(n_aud)]
if not parts:
raise ValueError("ref2va needs at least one picture, clip or audio")
else:
fields = KEYFRAMES.get(task, [])
unused = [f"image_{i + 1}" for i, x in enumerate(images)
if x is not None and i >= len(fields)]
unused += [f"{k}_{i + 1}" for k, xs in (("video", videos), ("video_audio", tracks),
("audio", audios))
for i, x in enumerate(xs) if x is not None]
if unused:
logging.warning(f"[{LOG}] {task} does not use {', '.join(unused)}")
parts += [(f, _image_png(images[i])) for i, f in enumerate(fields)
if images[i] is not None]
data = {
"model": model, "task": task, "prompt": prompt, "size": size,
"seconds": str(seconds), "seed": str(seed),
"num_inference_steps": str(num_inference_steps), "sampler": sampler,
"shift": str(shift), "audio_shift": str(audio_shift),
}
if latent_upscale != "off":
data["latent_upscale"] = latent_upscale
adapters = [(name, strength) for name, strength in ((loras, lora_strength),
(lora2, lora2_strength))
if name and name != "none"]
if len(adapters) == 2 and adapters[0][0] == adapters[1][0]:
raise ValueError(f"lora 1 and lora 2 are both {adapters[0][0]}")
if adapters:
data["loras"] = [name if strength == 1.0 else f"{name}:{strength:g}"
for name, strength in adapters]
# Media go as a multipart form, whose list fields are JSON text; without media, JSON.
base = server_url.rstrip("/")
s = requests.Session()
try:
if parts:
form = {k: json.dumps(v) if isinstance(v, list) else v for k, v in data.items()}
r = s.post(f"{base}/v1/videos", data=form, files=parts, timeout=300)
else:
r = s.post(f"{base}/v1/videos", json=data, timeout=300)
except requests.ConnectionError as e:
raise RuntimeError(f"cannot reach the radiance server at {base}: {e}") from e
if r.status_code >= 400:
try:
msg = r.json().get("error", {}).get("message") or r.text[:400]
except ValueError:
msg = r.text[:400]
raise RuntimeError(f"the server refused the job ({r.status_code}): {msg}")
job_id = r.json()["id"]
bar = _progress_bar(cls)
t0 = time.time()
pace = _Pace()
last_key, last_line = None, 0.0
while True:
jr = s.get(f"{base}/v1/videos/{job_id}", timeout=60)
jr.raise_for_status()
j = jr.json()
status = j.get("status")
if status == "completed":
break
if status in ("failed", "cancelled"):
err = j.get("error")
err = err.get("message", "") if isinstance(err, dict) else str(err or "")
raise RuntimeError(f"job {job_id} {status}: {err or 'no reason given'}")
p = j.get("progress")
if isinstance(p, (int, float)) and bar is not None:
bar.update_absolute(min(max(float(p), 0.0), 100.0))
# A line when a step finishes or the status changes, and every 30 s otherwise.
now = time.time()
sps = pace.update(j, now)
key = (status, j.get("steps_done"))
if key != last_key or now - last_line >= KEEPALIVE_SECONDS:
logging.info(f"[{LOG}] {job_id}: {_progress_line(j, now - t0, sps)}")
last_key, last_line = key, now
if now - t0 > timeout:
raise RuntimeError(f"job {job_id} still {status} after {timeout} s")
time.sleep(POLL_SECONDS)
cr = s.get(f"{base}/v1/videos/{job_id}/content", timeout=600)
cr.raise_for_status()
folder, name, counter, subfolder, _ = folder_paths.get_save_image_path(
"radiance/Radiance", folder_paths.get_output_directory(), 0, 0)
file = f"{name}_{counter:05}_.mp4"
path = os.path.join(folder, file)
with open(path, "wb") as f:
f.write(cr.content)
if bar is not None:
bar.update_absolute(100.0)
return io.NodeOutput(
VideoFromFile(path),
os.path.join(subfolder, file) if subfolder else file,
job_id,
ui=ui.PreviewVideo([ui.SavedResult(file, subfolder, io.FolderType.output)]),
)
@@ -0,0 +1,157 @@
// The Radiance MiniMax node's frontend: the size a request will carry in the node's title
// ("480p 16:9 -> 864x480"), computed as radiance_node.py's _tier_size and _custom_size compute it
// at execute(), and the adapter lists, fetched from the server.
import { app } from "../../scripts/app.js";
const TIERS = { "144p": 144, "240p": 240, "360p": 360, "480p": 480, "540p": 540, "576p": 576,
"720p": 720 };
const SIZE_MULT = 32, MIN_SIDE = 256, MAX_AREA = 1344 * 768, MAX_ASPECT = 4.0;
const snapUp = (v) => Math.max(MIN_SIDE, Math.floor((v + SIZE_MULT / 2) / SIZE_MULT) * SIZE_MULT);
function fit(w, h, cap) {
const s = Math.sqrt(cap / (w * h));
let fw = Math.max(MIN_SIDE, Math.floor((w * s) / SIZE_MULT) * SIZE_MULT);
let fh = Math.max(MIN_SIDE, Math.floor((h * s) / SIZE_MULT) * SIZE_MULT);
while (fw * fh > cap) {
if (fw >= fh && fw > MIN_SIDE) fw -= SIZE_MULT;
else if (fh > MIN_SIDE) fh -= SIZE_MULT;
else break;
}
if (Math.max(fw, fh) > MAX_ASPECT * Math.min(fw, fh)) {
if (fw >= fh) fw = Math.floor((MAX_ASPECT * fh) / SIZE_MULT) * SIZE_MULT;
else fh = Math.floor((MAX_ASPECT * fw) / SIZE_MULT) * SIZE_MULT;
}
return [fw, fh];
}
function resolveSize(resolution, aspect, customText) {
if (resolution === "custom") {
const m = /^\s*(\d+)\s*[xX×*]\s*(\d+)/.exec(customText || "");
if (!m) return null;
let [lw, lh] = [snapUp(+m[1]), snapUp(+m[2])];
if (lw * lh > MAX_AREA || Math.max(lw, lh) > MAX_ASPECT * Math.min(lw, lh)) {
[lw, lh] = fit(lw, lh, MAX_AREA);
}
return `${lw}x${lh}`;
}
const tier = TIERS[resolution];
if (tier === undefined) return null;
const [a, b] = (aspect || "16:9").split(":").map(Number);
const [hi, lo] = [Math.max(a, b), Math.min(a, b)];
let short = snapUp(tier);
let long = Math.max(short, snapUp(Math.floor((short * hi) / lo)));
if (long * short > MAX_AREA) [long, short] = fit(long, short, MAX_AREA);
return a >= b ? `${long}x${short}` : `${short}x${long}`;
}
// The adapter lists are the server's (GET <server_url>/v1/loras, which needs the server's CORS
// headers), so the schema ships only "none". They are fetched when the node is created or
// loaded, when server_url changes, and by the "refresh lora list" button. A fetch replaces the
// options; a selection the server no longer offers goes back to "none".
function loraDropdown(node) {
if (!node.widgets) return;
const widget = (name) => node.widgets.find((w) => w.name === name);
const dropNames = ["loras", "lora2"];
const fetchLoras = (announce) => {
const base = (widget("server_url")?.value || "").trim().replace(/\/+$/, "");
if (!dropNames.some((n) => widget(n)) || !base) return;
fetch(`${base}/v1/loras`)
.then((r) => { if (!r.ok) throw new Error(`HTTP ${r.status}`); return r.json(); })
.then((j) => {
const names = (j.data || []).map((d) => d.id);
const values = ["none", ...names];
for (const w of dropNames.map(widget)) {
if (!w) continue;
// A combo keeps its options as an array or as { values }, by frontend version.
if (Array.isArray(w.options)) w.options.splice(0, w.options.length, ...values);
else (w.options ??= {}).values = values;
if (!values.includes(w.value)) w.value = "none";
}
node.setDirtyCanvas?.(true, true);
if (announce) {
alert(names.length
? `loras dropdown now lists ${names.length} adapter(s):\n\n${names.join("\n")}`
: "this radiance server lists no LoRAs\n(start it with --lora-dir)");
}
})
.catch((e) => {
console.warn(`[RadianceMiniMax] cannot list LoRAs from ${base}:`, e);
if (announce) {
alert(`cannot list LoRAs from ${base}: ${e}\n` +
"(the server must be reachable from this browser, and not run with --no-cors)");
}
});
};
node._radianceFetchLoras = () => fetchLoras(false);
if (!node.widgets.some((w) => w.name === "refresh lora list")) {
const w = node.addWidget("button", "refresh lora list", null, () => fetchLoras(true));
w.serialize = false; // not an input of the node
}
fetchLoras(false);
}
function refresh(node) {
const widget = (name) => node.widgets?.find((w) => w.name === name);
const res = widget("resolution")?.value;
const aspect = widget("aspect")?.value ?? "16:9";
if (!res) return;
const size = resolveSize(res, aspect, widget("custom_size")?.value ?? "");
node.title = size ? (res === "custom" ? `custom -> ${size}` : `${res} ${aspect} -> ${size}`)
: `${res} (not a size)`;
node.setDirtyCanvas?.(true, false);
}
app.registerExtension({
name: "Comfy.RadianceMiniMax.SizeDisplay",
beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== "RadianceMiniMax") return;
const wrap = (node, name, extra) => {
const w = node.widgets?.find((x) => x.name === name);
if (!w || w._radianceWrapped) return;
w._radianceWrapped = true;
const inner = w.callback;
w.callback = function (...args) {
const r = inner?.apply(this, args);
refresh(node);
extra?.(node);
return r;
};
};
const onCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const r = onCreated?.apply(this, arguments);
for (const name of ["resolution", "aspect", "custom_size"]) wrap(this, name);
wrap(this, "server_url", (n) => n._radianceFetchLoras?.());
loraDropdown(this);
// DynamicCombo.Input takes no default, so a new node would start on 144p. A loaded node
// gets its saved value back from onConfigure, which runs after this.
const resW = this.widgets?.find((w) => w.name === "resolution");
if (resW && resW.value !== "480p") {
resW.value = "480p";
try { resW.callback?.call(resW, "480p", undefined, this); } catch (e) { /* the title only */ }
}
if (!this._radianceWidgetHook) { // the DynamicCombo adds custom_size when it is chosen
this._radianceWidgetHook = true;
const added = this.onWidgetAdded;
this.onWidgetAdded = function (w) {
const r = added?.apply(this, arguments);
if (w && ["resolution", "aspect", "custom_size"].includes(w.name)) wrap(this, w.name);
refresh(this);
return r;
};
}
refresh(this);
return r;
};
const onConfigured = nodeType.prototype.onConfigure;
nodeType.prototype.onConfigure = function (d) {
const r = onConfigured?.apply(this, arguments);
for (const name of ["resolution", "aspect", "custom_size"]) wrap(this, name);
wrap(this, "server_url", (n) => n._radianceFetchLoras?.());
loraDropdown(this); // the button is not saved with the workflow, so it is added again
refresh(this);
return r;
};
},
});