🎬 MiniMax H3 — ComfyUI 实操完整文档

2026-08-04 · 数据来源: HF 官方 README + Prompt Guide + 源码 nodes_minimax_h3.py + 官方 workflow templates + SGLang cookbook
所有信息均为 实读原文/源码,非推测

📑 目录

一、ComfyUI 原生节点详解(源码级)

源码: comfy_extras/nodes_minimax_h3.py(ComfyUI ≥ v0.30.0 内置,无需第三方插件)

节点 1: EmptyMiniMaxH3LatentAV

功能: 创建空的视频+音频联合 latent

参数类型默认说明
widthINT1344必须 32 的倍数
heightINT768必须 32 的倍数
lengthINT124帧数@24fps。snap 到 17k+5 网格 (124≈5s, 362≈15s)。训练范围 124-362,超出未测试

输出: LATENT (NestedTensor: video[B,24,T,H/16,W/16] + audio[B,32,2,T40])

节点 2: MiniMaxH3ImageToVideo(T2V/I2V/FL2VA)

功能: T2VA + FL2VA 的条件构建 + latent 创建一步完成

参数类型默认说明
clipCLIP—CLIPLoader(type="minimax")
vaeVAE—Video VAE (fp16)
promptSTRING—多行文本,支持 dynamic prompts
widthINT134432 的倍数
heightINT76832 的倍数
lengthINT12417k+5 网格
first_frameIMAGEoptional首帧:lanczos 拉伸到画布("disabled" crop)
last_frameIMAGEoptional尾帧:aspect-preserving cover-crop("center" crop)

输出: CONDITIONING(positive) + LATENT

📐 首尾帧处理差异(源码细节)

首帧和尾帧的 resize 策略不同:

  • 首帧: _resize(first_frame, width, height, "disabled") — 纯拉伸,不做裁剪
  • 尾帧: _resize(last_frame, width, height, "center") — 保持比例 center-crop

关键帧 latent 通过 VAE encode 后注入 conditioning 的 minimax_keyframes 字段,每步采样时重新注入(不参与去噪)。

节点 3: MiniMaxH3ReferenceToVideo(Ref2VA)

功能: 参考图/视频/音频驱动的生成

参数类型说明
clipCLIPCLIPLoader(type="minimax")
vaeVAEVideo VAE
audio_vaeVAEAudio VAE (fp32) — R2V 必须额外加载 audio VAE
promptSTRING多行文本
width / heightINT1344×768 默认
lengthINT帧数(17k+5 网格)
ref_image_sizeCOMBO"match"(缩到生成分辨率,快)或 "max"(保持 2048px 短边,身份保真但慢数倍)
ref_imagesAUTOGROW[IMAGE]≤9 张参考图。自动按 index 编号 → <Picture 1>~<Picture 9>
ref_videosAUTOGROW[IMAGE]≤3 个参考视频帧(24fps,2-15s)
ref_video_audiosAUTOGROW[AUDIO]对应编号视频的音轨
ref_audiosAUTOGROW[AUDIO]≤3 个独立参考音频
📐 参考输入排序逻辑(源码细节)

参考内容按固定顺序进入 tokenizer:

  1. 先图片(<Picture 1>~<Picture N>)
  2. 再视频+配对音轨(音轨的 <Audio j> 标签在对应 <Video k> 之前)
  3. 最后独立音频

视频参考经过 adapt_canvas() 缩放,帧数 snap 到 17k+5。Qwen 编码器以 2fps 采样视频帧并附带时间戳。

节点 4: MiniMaxH3SigmaShift

功能: 设置视频/音频的 flow shift 值。作用于 Model 对象。

参数默认说明
model—UNETLoader 输出的 model
shift_video12.0视频噪声调度偏移。⚠️ 不要降低!
shift_audio3.0音频噪声调度偏移

机制: 创建 ModelSamplingAdvanced(继承 DiscreteFlow + CONST),patch 到 model 的 model_sampling。 同时通过 transformer_options 把 shift 值传给 DiT,DiT 内部用 video schedule 反推 audio schedule。

二、三种工作流拓扑(官方模板)

2.1 T2V / I2V 工作流(打包节点版)

官方模板用打包节点 4c314f31-...(一键节点),内部封装了 CLIPLoader + UNETLoader + VAELoader×2 + MiniMaxH3ImageToVideo + KSampler + VAEDecode + CreateVideo 的完整链路。

ResolutionSelector["16:9"] ──┐ ├──► PackedNode ──► SaveVideo LoadImage (可选 first_frame) ──┘ (prompt, 1344×768, 5s, seed, fl2va_pruned_int8, nvfp4_awq, video_vae_fp16, audio_vae_fp32)

打包节点的 widget 参数:

#参数示例值
0prompt"Cinematic, action movie trailer..."
1width1344
2height768
3duration_seconds5
4seed556589502035082
5dit_modelminimax_h3_fl2va_pruned_int8_convrot.safetensors
6text_encqwen3vl_32b_minimax_h3_nvfp4_awq.safetensors
7video_vaeminimax_h3_video_vae_fp16.safetensors
8audio_vaeminimax_h3_audio_vae_fp32.safetensors

2.2 R2V 工作流(底级节点版)

R2V 模板不用打包节点,而是完整的底级节点拓扑,给用户最大控制力:

UNETLoader(ref2va_pruned_int8) ─────┬──► BasicScheduler(simple, 20步, 1.0) └──► BasicGuider │ CLIPLoader(nvfp4_awq, "minimax") ──┐ │ VAELoader(video_vae_fp16) ─────────┤ │ VAELoader(audio_vae_fp32) ─────────┤ │ LoadImage(ref_image_0) ────────────┤ │ LoadImage(ref_image_1) ────────────┤ │ PrimitiveStringMultiline(prompt) ──┤ │ ResolutionSelector(16:9) ──────────┤ │ ComfyMathExpression(frame_count) ──┘ │ ↓ │ MiniMaxH3ReferenceToVideo ──── conditioning + latent │ ↓ SamplerCustomAdvanced ◄── RandomNoise + KSamplerSelect(res_multistep) │ ┌──────┴──────┐ ↓ ↓ VAEDecode VAEDecodeAudio │ │ └──────┬──────┘ ↓ CreateVideo(24fps, 8质量) ↓ SaveVideo

帧数计算公式(ComfyMathExpression 节点):

max(5, round(a * 24)) + (5 - (max(5, round(a * 24)) % 17)) % 17

# a = duration_seconds (PrimitiveFloat)
# 效果:将秒数转为帧数后 snap 到 17k+5 网格
# 例: 5s → round(5*24)=120 → (5-(120%17))%17 = (5-1)%17=4 → 120+4=124

R2V 采样器选择:res_multistep(不是 euler!)+ simple scheduler + 20步

三、API 提交格式(编程驱动 ComfyUI)

3.1 ComfyUI API JSON 格式(通过 /prompt 端点)

从工作流模板逆向得到的实际 API 参数映射:

T2V 提交格式

{
  "task": "t2va",
  "prompt": "integrated_multimodal_description: [Shot 1]...\noverall_soundscape:...\nnon_diegetic_music:...",
  "conditions": [],
  "target": {
    "short_edge": 768,
    "aspect_ratio": "16:9",
    "duration_seconds": 10
  },
  "seed": 0
}

I2V / FL2VA 提交格式

{
  "task": "fl2va",
  "prompt": "For the target video, at 0.00 seconds...\n\nintegrated_multimodal_description:...",
  "conditions": [
    {
      "type": "image",
      "uri": "file:///data/image.png",
      "role": "keyframe",
      "frame_index": 0     // 0=首帧; duration末=尾帧
    }
  ],
  "target": {
    "short_edge": 768,
    "aspect_ratio": "auto",   // auto = 跟随输入图比例
    "duration_seconds": 8
  },
  "seed": 0
}

Ref2VA 提交格式

{
  "task": "ref2va",
  "prompt": "subject_definitions:\n<Subject 1> is...\n\nsummary:\n[reference generation]...\n\nretention_analysis:\n...\n\ndetailed_description:\n...",
  "conditions": [
    {"type": "image", "uri": "file:///ref1.png", "role": "reference"},
    {"type": "video", "uri": "file:///ref.mp4", "role": "reference"},
    {"type": "audio", "uri": "file:///voice.mp3", "role": "reference"}
  ],
  "target": {
    "short_edge": 768,
    "aspect_ratio": "auto",
    "duration_seconds": 5
  },
  "seed": 0
}

3.2 SGLang API 额外参数

SGLang 支持更丰富的采样控制:

参数说明
num_outputs_per_prompt1-10,同 prompt 多输出。seed 自动 +index
quality"lossless"(默认) 或 "high"(Cache-DiT 加速)
conditions[].start_time_seconds视频参考的非负偏移量
flow_shift / audio_flow_shift可覆盖默认 12.0/3.0
num_inference_steps默认 50

四、采样参数与分辨率规则

4.1 官方推荐参数

参数T2V/FL2VARef2VA说明
steps5020T2V 用 50 步;R2V 模板用 20 步
flow_shift (video)12.012.0⚠️ 不要手动降低!
audio_flow_shift3.03.0
CFG1.01.0CFG-distilled 模型
samplereulerres_multistepR2V 用 res_multistep + beta/simple
schedulersimplesimple/betaref 多时 beta 更优

4.2 分辨率规则(源码 adapt_canvas)

  1. 短边 = 768px(BASE_SHORT_EDGE)
  2. 面积上限 = 768 × 1344 = 1,032,192 px²(MAX_PIXELS)
  3. 如果面积超限,等比缩小到上限内
  4. 宽高各自 round 到 32 的倍数(CANVAS_MULTIPLE)
  5. 最小值 32px

常用分辨率:

比例输出尺寸说明
16:91344×768横屏标准
9:16768×1344竖屏标准(上限)
1:1768×768方形
21:91344×576超宽
4:31024×768传统

4.3 帧数 / 时长规则(源码 temporal_shape)

帧数必须满足 n % 17 == 5(17k+5 网格):

秒数帧数video latent Taudio latent T
~5s12437200
~6s14142240
~8s17552320
~10s22967400
~15s362107600

video_latent_t = 2 if frames ≤ 5 else ((frames-5)//17)*5 + 2
audio_latent_t = round(duration * 40)(40Hz 音频)

4.4 Quality Profile(4×H200 基准)

Quality等效步数延迟SSIM vs lossless
lossless5075s1.000
high (Cache-DiT)~3654s (1.4×)0.931 / PSNR 28.16dB
medium~2030s0.818
low~1726s0.794

五、Prompt 结构化编写指南

5.1 总体结构:指令行 + 三字段

指令行(按模式不同)

模式指令行
T2VA无指令行,直接开始
I2VAFor the target video, at 0.00 seconds into the target video, <Picture 1> (from [Shot 1]) is fully referenced.
FL2VAHow the reference pictures align with the target video — Picture 1 (from Shot 1) aligns with the 0.00-second mark of the target video; Picture 2 (from Shot N) aligns with the S.SS-second mark of the target video.
L2VAHow the reference pictures align with the target video — <Picture 1> (from [Shot N]) aligns with the S.SS-second mark of the target video.

三核心字段

字段描述字数建议
integrated_multimodal_description主描述体:视觉+动作+镜头+对话+场景音无限制
overall_soundscape环境音摘要(风/雨/脚步/撞击/呼吸等非语言声)1-4 句
non_diegetic_music非叙事 BGM(角色听不到,观众听到)1-3 句。无则 N/A

5.2 镜头/运镜/对话格式

镜头切换

运镜三维度表

维度可用值
运动类型Zoom In/Out · Push In/Pull Out · Pan L/R · Truck L/R · Tilt Up/Down · Pedestal Up/Down · Arc Shot · Tracking Shot · Static Shot · Shake Slightly/Strongly · POV · Roll CW/CCW
幅度with small amplitude · with large amplitude(中等省略)
速度at slow speed · at fast speed(正常省略)

写法示例: The camera pushes in with small amplitude at slow speed toward the folded letter.

对话标记

The young woman with a quiet, breathy voice (S1) says: <d>[English] I get off at the next station.</d>
The two children (S1,S2) shout together, <d>[English] Wait for us!</d>

屏幕文字

画面可见文字(招牌/字幕/霓虹灯)用英文双引号:A red neon sign reading "营业中" glows above the doorway.

5.3 完整 T2VA 示例

integrated_multimodal_description: [Shot 1] Live-action, cinematic, a medium-wide 
shot frames a baker opening the shutters of a small street bakery before sunrise. 
The camera pushes in with small amplitude at slow speed as the middle-aged baker 
with a calm, slightly raspy voice (S1) places a fresh loaf on the wooden counter 
and says: <d>[English] First batch of the morning.</d> 
[Shot 2] At 00:05.000, the camera cuts to a close-up of steam rising from the 
sliced bread while the baker's final words carry over from the previous shot.

overall_soundscape: Wooden shutters scrape open over a quiet street as trays clink 
softly inside the bakery. The doorbell rings once, followed by light footsteps and 
the crisp sound of bread being sliced.

non_diegetic_music: A soft acoustic-guitar pattern at a moderate tempo, joined by 
sparse upright-bass notes and a gentle fade at the end.

六、Ref2VA 全参考模式 Prompt(6 节结构)

段落用途
subject_definitions定义 <Subject N> / <Picture N> / <Video N> / <Audio N>
summary带任务类型前缀概述,如 [video editing + audio reuse]
retention_analysis保留程度:fully_preserved / partially_preserved / attribute_transfer / weak_reference;音频:fully_copy / partially_copy / reference
detailed_description主描述体(350-500词),比 T2V 的 integrated_multimodal_description 更详细
overall_soundscape环境音
non_diegetic_music非叙事 BGM

六种任务类型(summary 前缀)

类型适用
keyframe completion图片=首帧/关键帧/尾帧
reference generation图/视频/音频提供生成指导
video editing直接修改已有视频
video continuation从已有视频续拍
audio reuse音频完整/部分复用
audio reference仅参考音色/节奏/风格

七、显存分析与量化选型

7.1 模型架构参数(config.json 源码)

组件参数详情
H3-Omni-Transformer33B (推理 ~20B)50 层 × 56 头 × 128 dim = 5376 hidden。~13B AdaLN 推理可跳过
H3-EncoderQwen3-VL-32B64 层 text + 27 层 vision。5120 hidden。RoPE theta=5000000
VisualVAEf16t4d24空间 16× / 时间 4× / 24 latent ch。ViT 解码器 36 层
AudioVAE32kHz → 40Hz latent32 latent ch。encoder_rates=[2,4,4,5,5] → 800× 压缩
patch_size[1,2,2](time,height,width) → 空间有效下采样 32×

7.2 量化版本对比

文件量化大小3090 推荐
Diffusion Model (fl2va)
minimax_h3_fl2va_bf16bf1661.7 GB❌
minimax_h3_fl2va_int8_convrotint831.7 GB❌ VRAM 不够
minimax_h3_fl2va_pruned_int8_convrotint8 剪枝19.5 GB★ 推荐
minimax_h3_fl2va_pruned_fp8_scaledfp8 剪枝—? 待测
Text Encoder
qwen3vl_32b_minimax_h3_bf16bf1648.0 GB❌
qwen3vl_32b_minimax_h3_int8_convrotint825.3 GB❌
qwen3vl_32b_minimax_h3_nvfp4_awqNVFP4+AWQ14.6 GB★ 推荐(3090 软件模拟)

7.3 3090 24GB 逐阶段 VRAM

阶段VRAM 需求3090判定
Text Encoding (Qwen3-VL-32B)~15.6 GB24 GB✓
Diffusion (fl2va int8 pruned)~22.5 GB24 GB⚠️ 勉强 (1.5GB headroom)
VAE Decode (video+audio)~7.5 GB24 GB✓

八、SGLang 官方基准数据

8.1 B300 12 组合扫描(单请求延迟)

工作负载: 1344×768, 124帧, 50步, 5s T2VA

权重精度编码器延迟峰值/GPU
FL2VABF16auto19.0s83.6 GB
FL2VAFP8auto18.0s51.9 GB
Ref2VABF16auto29.1s84.0 GB
Ref2VAFP8auto27.1s52.8 GB

8.2 多 GPU 拓扑对比

GPU拓扑延迟峰值/GPU
4×H200Ulysses474.4s94.3 GB
4×H200TP2+Ulysses278.3s63.5 GB
4×H100TP2+Ulysses213.3s66.0 GB
4×H100FSDP+Ulysses413.4s57.0 GB
2×RTX5090TP2+layerwise559.7s (50步)26.3 GB
8×MI355XUlysses8~65s97.4 GB

8.3 Quality 对比(Cache-DiT)

quality延迟加速SSIMPSNR
lossless75.1s1.0×1.000—
high53.7s1.4×0.93128.16 dB

注: quality="high" 目前仅限 4×H200 + 1344×768 + 50步 的特定配置

九、已知陷阱与解决方案

⚠️ 陷阱 1: shift_video 降低导致水流波动

根因: H3 是 Flow Matching 模型,shift 控制噪声调度曲线偏移。值太低 → 高噪声阶段被压缩 → 帧间像素微漂移 → 水流波动。

解决: 永远用 shift_video=12.0(默认值),不要手动降低。

⚠️ 陷阱 2: CFG 并行无效

根因: H3 是 CFG-distilled 单分支模型。

解决: 不要启用 --enable-cfg-parallel 或 --cfg-parallel-size > 1,会被拒绝。CFG=1.0 即可。

⚠️ 陷阱 3: VAE parallel-decode-mode spatial 不兼容

根因: SGLang 验证发现 spatial 和 spatial_shard 模式有输出不匹配。

解决: 用默认的 tiled decode recipe(overlapping tiles)。

⚠️ 陷阱 4: torch.compile 改变数值输出

根因: 当前 torch.compile 路径会改变模型数值输出。

解决: 不要用于生成 CI 一致性 ground truth。推荐用 eager BF16/FP32。

⚠️ 陷阱 5: ComfyUI docker compose up 重建容器

根因: compose 检测配置变化会 Recreate → 文件系统从镜像恢复。

解决: 修改容器后用 docker restart,永远不用 docker compose up。

⚠️ 陷阱 6: R2V 参考 token 每步重注入

根因: 参考 latent(keyframes + refs)在每个采样步骤都重新注入 DiT(never denoised),所以 ref_image_size="max" 会比 "match" 慢数倍。

解决: 速度优先用 "match",身份保真优先用 "max"(2048px 短边)。

⚠️ 陷阱 7: 尾帧 resize 策略与首帧不同

源码差异: 首帧 "disabled" crop(纯拉伸),尾帧 "center" crop(保持比例居中裁剪)。

影响: 首尾帧的宽高比不同时,尾帧会被裁剪而不是拉伸。输入图需提前调整到目标比例。

十、对我们管线的启示

✅ 核心可操作项

  1. Prompt 结构化: H3 的 prompt 必须用三字段格式(integrated_multimodal_description + overall_soundscape + non_diegetic_music),不是自由文本。管线 P09 shot-list 的 prompt 应按此格式输出。
  2. 原生音频管线简化: H3 一个 forward pass 出视频+音频,理论上可以替代 LTX-MSR + TTS + Foley + BGM 的多步管线。但需实测对话清晰度。
  3. Ref2VA 角色锁定: 最多 9 图 + 3 视频 + 3 音频参考。可用 turnaround sheet + 声音样本做角色一致性。但 3090 上 R2V 需要 ref2va 模型(额外 19.5GB)。
  4. 对话标记 <d>: 直接控制视频中的角色对话时间点和内容。可用 [Chinese] 语言标签。
  5. 帧数计算: max(5, round(sec*24)) + (5-(max(5,round(sec*24))%17))%17。管线需要按此 snap。
  6. 分辨率限制: 竖屏 9:16 上限 768×1344。我们的短剧是 9:16,刚好在上限。

⚠️ 限制

  • Context-IR 未开源: 官方说它"对输出质量至关重要"。我们直接用 H3-Base 跳过了它。可以考虑自建简化版(按 Prompt Guide 格式化)或调用官方 API。
  • Regenerate-2K 未开源: 768p 是开源上限。2K 需要 API。
  • 3090 速度: 实测 ~9-11min/次(15步),远慢于 LTX-MSR 的 2-5min。不适合管线批量渲染。
  • 许可证排除了 EU/UK/KR/US: 产品出海需注意。中国境内不受影响。
  • 稀疏注意力未发布: 首版只有 full attention,未来版本可能有显著提速。

— 全部信息来自实读官方源码/文档,非推测 —