Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/diffusers/guiders/auto_guidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
f"Expected `auto_guidance_layers` to be an int or a list of ints, but got {type(auto_guidance_layers)}."
)
auto_guidance_config = [
LayerSkipConfig(layer, fqn="auto", dropout=dropout) for layer in auto_guidance_layers
LayerSkipConfig(indices=[layer], fqn="auto", dropout=dropout) for layer in auto_guidance_layers
]

if isinstance(auto_guidance_config, dict):
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/guiders/skip_layer_guidance.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(
raise ValueError(
f"Expected `skip_layer_guidance_layers` to be an int or a list of ints, but got {type(skip_layer_guidance_layers)}."
)
skip_layer_config = [LayerSkipConfig(layer, fqn="auto") for layer in skip_layer_guidance_layers]
skip_layer_config = [LayerSkipConfig(indices=[layer], fqn="auto") for layer in skip_layer_guidance_layers]

if isinstance(skip_layer_config, dict):
skip_layer_config = LayerSkipConfig.from_dict(skip_layer_config)
Expand Down
40 changes: 40 additions & 0 deletions tests/guiders/test_skip_layer_guidance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2025 HuggingFace Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from diffusers.guiders.auto_guidance import AutoGuidance
from diffusers.guiders.skip_layer_guidance import SkipLayerGuidance


class TestSkipLayerGuidanceConfig:
def test_skip_layer_guidance_layers_shorthand_builds_list_indices(self):
guider = SkipLayerGuidance(
guidance_scale=7.0,
skip_layer_guidance_layers=[7, 8, 9],
skip_layer_guidance_scale=2.8,
)

assert [config.indices for config in guider.skip_layer_config] == [[7], [8], [9]]
for config in guider.skip_layer_config:
assert 7 in config.indices or 8 in config.indices or 9 in config.indices

def test_auto_guidance_layers_shorthand_builds_list_indices(self):
guider = AutoGuidance(
guidance_scale=7.0,
auto_guidance_layers=[3, 4],
dropout=1.0,
)

assert [config.indices for config in guider.auto_guidance_config] == [[3], [4]]
for config in guider.auto_guidance_config:
assert config.indices[0] in config.indices
3 changes: 2 additions & 1 deletion utils/check_copies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
import subprocess
import sys


# All paths are set with the intent you should run this script from the root of the repo with the command
Expand Down Expand Up @@ -94,7 +95,7 @@ def get_indent(code):


def run_ruff(code):
command = ["ruff", "format", "-", "--config", "pyproject.toml", "--silent"]
command = [sys.executable, "-m", "ruff", "format", "-", "--config", "pyproject.toml", "--silent"]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, _ = process.communicate(input=code.encode())
return stdout.decode()
Expand Down