mirror of
https://github.com/Comfy-Org/ComfyUI.git
synced 2026-08-17 23:08:53 +08:00
Allow regular single image Empty Latent Image node to be used with H3. (#15677)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user