From 0696f61dced6340086cdca64a96200c50f306c66 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Sun, 16 Aug 2026 18:34:39 -0700 Subject: [PATCH] Allow regular single image Empty Latent Image node to be used with H3. (#15677) --- comfy/latent_formats.py | 17 +++++++++++++++++ comfy/sample.py | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/comfy/latent_formats.py b/comfy/latent_formats.py index dc737fc7d..ed5167075 100644 --- a/comfy/latent_formats.py +++ b/comfy/latent_formats.py @@ -1,4 +1,5 @@ import torch +import comfy.nested_tensor class LatentFormat: scale_factor = 1.0 @@ -17,6 +18,9 @@ class LatentFormat: def process_out(self, latent): return latent / self.scale_factor + def fix_empty_latent(self, latent): + return latent + class SD15(LatentFormat): def __init__(self, scale_factor=0.18215): self.scale_factor = scale_factor @@ -606,6 +610,19 @@ class MiniMaxH3AV(MiniMaxH3Video): # max channels across the two streams (video 24, audio 32) so per-stream slices keep both streams whole latent_channels = 32 + def fix_empty_latent(self, latent): + video_latent_channels = MiniMaxH3Video.latent_channels + audio_latent_channels = 32 + audio_channels = 2 + frames_per_token = (1, 4, 4, 4, 4) + audio_frame_rescale = 5.0 / 3.0 + + video = latent[:, :video_latent_channels].clone() + frame_count = sum(frames_per_token[i % len(frames_per_token)] for i in range(video.shape[2])) + audio_t = round(frame_count * audio_frame_rescale) + audio = latent.new_zeros((latent.shape[0], audio_latent_channels, audio_channels, audio_t)) + return comfy.nested_tensor.NestedTensor((video, audio)) + class HunyuanVideo(LatentFormat): latent_channels = 16 latent_dimensions = 3 diff --git a/comfy/sample.py b/comfy/sample.py index 617816882..4ebad9666 100644 --- a/comfy/sample.py +++ b/comfy/sample.py @@ -45,7 +45,7 @@ def prepare_empty_noise(latent_image): def fix_empty_latent_channels(model, latent_image, downscale_ratio_spacial=None, downscale_ratio_temporal=None): if latent_image.is_nested: return latent_image - latent_format = model.get_model_object("latent_format") #Resize the empty latent image so it has the right number of channels + latent_format = model.get_model_object("latent_format") is_empty = torch.count_nonzero(latent_image) == 0 if is_empty: if latent_format.latent_channels != latent_image.shape[1]: @@ -64,6 +64,9 @@ def fix_empty_latent_channels(model, latent_image, downscale_ratio_spacial=None, new_t = max(1, round(latent_image.shape[2] * ratio)) latent_image = comfy.utils.repeat_to_batch_size(latent_image, new_t, dim=2) + if is_empty: + latent_image = latent_format.fix_empty_latent(latent_image) + return latent_image def prepare_sampling(model, noise_shape, positive, negative, noise_mask):