[CI] Allow single file tests to run as fast tests by DN6 · Pull Request #14324 · huggingface/diffusers · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/pr_tests.yml
18 changes: 14 additions & 4 deletions src/diffusers/loaders/single_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
"net.pos_embedder.dim_spatial_range",
],
"flux2": ["model.diffusion_model.single_stream_modulation.lin.weight", "single_stream_modulation.lin.weight"],
"chroma": [
"model.diffusion_model.distilled_guidance_layer.in_proj.bias",
"distilled_guidance_layer.in_proj.bias",
],
"ltx2": [
"model.diffusion_model.av_ca_a2v_gate_adaln_single.emb.timestep_embedder.linear_1.weight",
"vae.per_channel_statistics.mean-of-means",
Expand Down Expand Up @@ -204,6 +208,7 @@
"flux-depth": {"pretrained_model_name_or_path": "black-forest-labs/FLUX.1-Depth-dev"},
"flux-schnell": {"pretrained_model_name_or_path": "black-forest-labs/FLUX.1-schnell"},
"flux-2-dev": {"pretrained_model_name_or_path": "black-forest-labs/FLUX.2-dev"},
"chroma": {"pretrained_model_name_or_path": "lodestones/Chroma1-HD"},
"ltx-video": {"pretrained_model_name_or_path": "diffusers/LTX-Video-0.9.0"},
"ltx-video-0.9.1": {"pretrained_model_name_or_path": "diffusers/LTX-Video-0.9.1"},
"ltx-video-0.9.5": {"pretrained_model_name_or_path": "Lightricks/LTX-Video-0.9.5"},
Expand Down Expand Up @@ -683,6 +688,9 @@ def infer_diffusers_model_type(checkpoint):
elif any(key in checkpoint for key in CHECKPOINT_KEY_NAMES["flux2"]):
model_type = "flux-2-dev"

elif any(key in checkpoint for key in CHECKPOINT_KEY_NAMES["chroma"]):
model_type = "chroma"

elif any(key in checkpoint for key in CHECKPOINT_KEY_NAMES["flux"]):
if any(
g in checkpoint for g in ["guidance_in.in_layer.bias", "model.diffusion_model.guidance_in.in_layer.bias"]
Expand Down Expand Up @@ -754,17 +762,19 @@ def infer_diffusers_model_type(checkpoint):

elif any(key in checkpoint for key in CHECKPOINT_KEY_NAMES["wan"]):
if "model.diffusion_model.patch_embedding.weight" in checkpoint:
target_key = "model.diffusion_model.patch_embedding.weight"
prefix = "model.diffusion_model."
else:
target_key = "patch_embedding.weight"
prefix = ""

target_key = f"{prefix}patch_embedding.weight"

if CHECKPOINT_KEY_NAMES["wan_vace"] in checkpoint:
if f"{prefix}{CHECKPOINT_KEY_NAMES['wan_vace']}" in checkpoint:
Comment on lines -757 to +771

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did these come about during writing the tests being added in this PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. VACE auto config loading wasn't working for models with keys prefixed with model.diffusion_model.

if checkpoint[target_key].shape[0] == 1536:
model_type = "wan-vace-1.3B"
elif checkpoint[target_key].shape[0] == 5120:
model_type = "wan-vace-14B"

if CHECKPOINT_KEY_NAMES["wan_animate"] in checkpoint:
elif f"{prefix}{CHECKPOINT_KEY_NAMES['wan_animate']}" in checkpoint:
model_type = "wan-animate-14B"

elif checkpoint[target_key].shape[0] == 1536:
Expand Down
18 changes: 17 additions & 1 deletion tests/models/autoencoders/test_models_autoencoder_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
from diffusers.utils.torch_utils import randn_tensor

from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, torch_device
from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin
from ..testing_utils import (
BaseModelTesterConfig,
MemoryTesterMixin,
ModelTesterMixin,
SingleFileTesterMixin,
TrainingTesterMixin,
)
from .testing_utils import NewAutoencoderTesterMixin


Expand Down Expand Up @@ -102,3 +108,13 @@ def test_layerwise_casting_memory(self):

class TestAutoencoderDCSlicingTiling(AutoencoderDCTesterConfig, NewAutoencoderTesterMixin):
"""Slicing and tiling tests for AutoencoderDC."""


class TestAutoencoderDCSingleFile(AutoencoderDCTesterConfig, SingleFileTesterMixin):
@property
def ckpt_path(self):
return "https://huggingface.co/mit-han-lab/dc-ae-f32c32-sana-1.0/blob/main/model.safetensors"

@property
def pretrained_model_name_or_path(self):
return "mit-han-lab/dc-ae-f32c32-sana-1.0-diffusers"
24 changes: 23 additions & 1 deletion tests/models/autoencoders/test_models_autoencoder_kl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
torch_all_close,
torch_device,
)
from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin
from ..testing_utils import (
BaseModelTesterConfig,
MemoryTesterMixin,
ModelTesterMixin,
SingleFileTesterMixin,
TrainingTesterMixin,
)
from .testing_utils import NewAutoencoderTesterMixin


Expand Down Expand Up @@ -428,3 +434,19 @@ def test_stable_diffusion_encode_sample(self, seed, expected_slice):

tolerance = 3e-3 if torch_device != "mps" else 1e-2
assert torch_all_close(output_slice, expected_output_slice, atol=tolerance)


class TestAutoencoderKLSingleFile(AutoencoderKLTesterConfig, SingleFileTesterMixin):
@property
def ckpt_path(self):
return "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"

@property
def pretrained_model_name_or_path(self):
# `from_single_file` resolves a bare VAE checkpoint against the SD 1.5 repo, so compare against that
# rather than against `stabilityai/sd-vae-ft-mse`, whose own config differs (sample_size 256 vs 512).
return "stable-diffusion-v1-5/stable-diffusion-v1-5"

@property
def pretrained_model_kwargs(self):
return {"subfolder": "vae"}
22 changes: 21 additions & 1 deletion tests/models/autoencoders/test_models_autoencoder_ltx_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
from diffusers.utils.torch_utils import randn_tensor

from ...testing_utils import enable_full_determinism, torch_device
from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin
from ..testing_utils import (
BaseModelTesterConfig,
MemoryTesterMixin,
ModelTesterMixin,
SingleFileTesterMixin,
TrainingTesterMixin,
)
from .testing_utils import NewAutoencoderTesterMixin


Expand Down Expand Up @@ -179,3 +185,17 @@ def test_gradient_checkpointing_is_applied(self):

class TestAutoencoderKLLTXVideo091Memory(AutoencoderKLLTXVideo091TesterConfig, MemoryTesterMixin):
"""Memory optimization tests for AutoencoderKLLTXVideo (0.9.1 config)."""


class TestAutoencoderKLLTXVideoSingleFile(AutoencoderKLLTXVideo090TesterConfig, SingleFileTesterMixin):
@property
def ckpt_path(self):
return "https://huggingface.co/Lightricks/LTX-Video/blob/main/ltx-video-2b-v0.9.safetensors"

@property
def pretrained_model_name_or_path(self):
return "diffusers/LTX-Video-0.9.0"

@property
def pretrained_model_kwargs(self):
return {"subfolder": "vae"}
22 changes: 21 additions & 1 deletion tests/models/autoencoders/test_models_autoencoder_wan.py
Loading
Loading