From d5cfd61e50c2ea3984186ab50a0b1ddbdc24f89f Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 19 Mar 2025 10:49:45 -0400 Subject: [PATCH] fix sd35 with batch Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 4 +++- modules/processing_vae.py | 3 --- modules/video_models/hunyuan.py | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a12b6492..67745eacf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ ## Update for 2025-03-17 ### TODO - - Gemma3 requires `git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3` + - Gemma3 requires `transformers==git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3` - Remote VAE encode for SD15 and Flux.1: + - HunyuanVideo-I2V: ### Highlights for 2025-03-17 @@ -50,6 +51,7 @@ Support for [CogView 4](https://huggingface.co/THUDM/CogView4-6B), new CLiP mode - add quantization support to **CogView-3Plus** - update `diffusers` and other requirements - rename vae, unet and text-encoder settings *None* to *Default* to avoid confusion + - **CLI**: add `cli/api-grid.py` which can generate grids using params-from-file for x/y axis - **IPEX** - add `--upgrade` to torch_command when using `--use-nightly` - add xpu to profiler diff --git a/modules/processing_vae.py b/modules/processing_vae.py index be819d658..348bbc0c5 100644 --- a/modules/processing_vae.py +++ b/modules/processing_vae.py @@ -293,9 +293,6 @@ def vae_decode(latents, model, output_type='np', vae_type='Full', width=None, he latents = model._unpack_latents(latents, height, width, model.vae_scale_factor) # pylint: disable=protected-access if len(latents.shape) == 3: # lost a batch dim in hires latents = latents.unsqueeze(0) - if latents.shape[0] == 4 and latents.shape[1] != 4: # likely animatediff latent - latents = latents.permute(1, 0, 2, 3) - if latents.shape[-1] <= 4: # not a latent, likely an image decoded = latents.float().cpu().numpy() elif vae_type == 'Full' and hasattr(model, "vae"): diff --git a/modules/video_models/hunyuan.py b/modules/video_models/hunyuan.py index c95316329..2b83e6b63 100644 --- a/modules/video_models/hunyuan.py +++ b/modules/video_models/hunyuan.py @@ -63,6 +63,12 @@ def hijack_encode_prompt(*args, **kwargs): return res +def get_quant(args): + if args is not None and "quantization_config" in args: + return args['quantization_config'].__class__.__name__ + return None + + def load(selected): if selected is None: return @@ -75,7 +81,7 @@ def load(selected): quant_args = model_quant.create_config(module='Model') cls = diffusers.HunyuanVideoTransformer3DModel try: - debug(f'Video load: module=transofrmer repo="{selected.dit}" subfolder="{selected.subfolder}" cls={cls.__name__} quant={quant_args is not None}') + debug(f'Video load: module=transofrmer repo="{selected.dit}" subfolder="{selected.subfolder}" cls={cls.__name__} quant={get_quant(quant_args)}') transformer = cls.from_pretrained( pretrained_model_name_or_path=selected.dit, subfolder=selected.subfolder, @@ -92,7 +98,7 @@ def load(selected): else: cls = transformers.LlamaModel try: - debug(f'Video load: module=te repo="{selected.repo}" cls={cls.__name__} quant={quant_args is not None}') + debug(f'Video load: module=te repo="{selected.repo}" cls={cls.__name__} quant={get_quant(quant_args)}') text_encoder = cls.from_pretrained( pretrained_model_name_or_path=selected.repo, subfolder="text_encoder", @@ -107,7 +113,7 @@ def load(selected): cls = transformers.CLIPTextModel try: - debug(f'Video load: module=clip repo="{selected.repo}" cls={cls.__name__} quant=False') + debug(f'Video load: module=clip repo="{selected.repo}" cls={cls.__name__} quant=None') text_encoder_2 = transformers.CLIPTextModel.from_pretrained( pretrained_model_name_or_path=selected.repo, subfolder="text_encoder_2", @@ -119,7 +125,7 @@ def load(selected): cls = diffusers.AutoencoderKLHunyuanVideo try: - debug(f'Video load: module=vae repo="{selected.repo}" cls={cls.__name__} quant=False') + debug(f'Video load: module=vae repo="{selected.repo}" cls={cls.__name__} quant=None') vae = diffusers.AutoencoderKLHunyuanVideo.from_pretrained( pretrained_model_name_or_path=selected.repo, subfolder="vae", @@ -136,7 +142,7 @@ def load(selected): else: cls = diffusers.HunyuanVideoPipeline try: - debug(f'Video load: module=pipe repo="{selected.repo}" cls={cls.__name__} quant=False') + debug(f'Video load: module=pipe repo="{selected.repo}" cls={cls.__name__} quant=None') shared.sd_model = cls.from_pretrained( pretrained_model_name_or_path=selected.repo, transformer=transformer, @@ -205,6 +211,7 @@ def generate(*args, **kwargs): shared.log.error('Video: init image not set') return [], None, '', '', 'Error: init image not set' p.task_args['image'] = init_image + # from PIL import Image # p.task_args['image'] = init_image.resize((336, 336), Image.Resampling.LANCZOS) shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model)