Ruff: apply same rules as in transformers (#2827) · zzmjohn/diffusers@1d7b4b6 · GitHub
Skip to content

Commit 1d7b4b6

Browse files
pcuencaSkylion007
andauthored
Ruff: apply same rules as in transformers (huggingface#2827)
* Apply same ruff settings as in transformers See https://github.com/huggingface/transformers/blob/main/pyproject.toml Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> * Apply new style rules * Style Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com> * style * remove list, ruff wouldn't auto fix. --------- Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
1 parent abb22b4 commit 1d7b4b6

45 files changed

Lines changed: 209 additions & 213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎examples/community/checkpoint_merger.py‎

Lines changed: 8 additions & 12 deletions

‎examples/community/imagic_stable_diffusion.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
def preprocess(image):
5050
w, h = image.size
51-
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
51+
w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
5252
image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
5353
image = np.array(image).astype(np.float32) / 255.0
5454
image = image[None].transpose(0, 3, 1, 2)

‎examples/community/lpw_stable_diffusion.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def get_weighted_text_embeddings(
376376

377377
def preprocess_image(image):
378378
w, h = image.size
379-
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
379+
w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
380380
image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
381381
image = np.array(image).astype(np.float32) / 255.0
382382
image = image[None].transpose(0, 3, 1, 2)
@@ -387,7 +387,7 @@ def preprocess_image(image):
387387
def preprocess_mask(mask, scale_factor=8):
388388
mask = mask.convert("L")
389389
w, h = mask.size
390-
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
390+
w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
391391
mask = mask.resize((w // scale_factor, h // scale_factor), resample=PIL_INTERPOLATION["nearest"])
392392
mask = np.array(mask).astype(np.float32) / 255.0
393393
mask = np.tile(mask, (4, 1, 1))

‎examples/community/lpw_stable_diffusion_onnx.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def get_weighted_text_embeddings(
403403

404404
def preprocess_image(image):
405405
w, h = image.size
406-
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
406+
w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
407407
image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
408408
image = np.array(image).astype(np.float32) / 255.0
409409
image = image[None].transpose(0, 3, 1, 2)
@@ -413,7 +413,7 @@ def preprocess_image(image):
413413
def preprocess_mask(mask, scale_factor=8):
414414
mask = mask.convert("L")
415415
w, h = mask.size
416-
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32
416+
w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32
417417
mask = mask.resize((w // scale_factor, h // scale_factor), resample=PIL_INTERPOLATION["nearest"])
418418
mask = np.array(mask).astype(np.float32) / 255.0
419419
mask = np.tile(mask, (4, 1, 1))

‎examples/community/stable_unclip.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
):
4747
super().__init__()
4848

49-
decoder_pipe_kwargs = dict(image_encoder=None) if decoder_pipe_kwargs is None else decoder_pipe_kwargs
49+
decoder_pipe_kwargs = {"image_encoder": None} if decoder_pipe_kwargs is None else decoder_pipe_kwargs
5050

5151
decoder_pipe_kwargs["torch_dtype"] = decoder_pipe_kwargs.get("torch_dtype", None) or prior.dtype
5252

‎examples/instruct_pix2pix/train_instruct_pix2pix.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def preprocess_train(examples):
673673
examples["edited_pixel_values"] = edited_images
674674

675675
# Preprocess the captions.
676-
captions = [caption for caption in examples[edit_prompt_column]]
676+
captions = list(examples[edit_prompt_column])
677677
examples["input_ids"] = tokenize_captions(captions)
678678
return examples
679679

‎examples/rl/run_diffuser_locomotion.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
from diffusers.experimental import ValueGuidedRLPipeline
55

66

7-
config = dict(
8-
n_samples=64,
9-
horizon=32,
10-
num_inference_steps=20,
11-
n_guide_steps=2, # can set to 0 for faster sampling, does not use value network
12-
scale_grad_by_std=True,
13-
scale=0.1,
14-
eta=0.0,
15-
t_grad_cutoff=2,
16-
device="cpu",
17-
)
7+
config = {
8+
"n_samples": 64,
9+
"horizon": 32,
10+
"num_inference_steps": 20,
11+
"n_guide_steps": 2, # can set to 0 for faster sampling, does not use value network
12+
"scale_grad_by_std": True,
13+
"scale": 0.1,
14+
"eta": 0.0,
15+
"t_grad_cutoff": 2,
16+
"device": "cpu",
17+
}
1818

1919

2020
if __name__ == "__main__":

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ target-version = ['py37']
44

55
[tool.ruff]
66
# Never enforce `E501` (line length violations).
7-
ignore = ["E501", "E741", "W605"]
8-
select = ["E", "F", "I", "W"]
7+
ignore = ["C901", "E501", "E741", "W605"]
8+
select = ["C", "E", "F", "I", "W"]
99
line-length = 119
1010

1111
# Ignore import violations in all `__init__.py` files.

‎scripts/convert_ddpm_original_checkpoint_to_diffusers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def convert_vq_autoenc_checkpoint(checkpoint, config):
404404
config = json.loads(f.read())
405405

406406
# unet case
407-
key_prefix_set = set(key.split(".")[0] for key in checkpoint.keys())
407+
key_prefix_set = {key.split(".")[0] for key in checkpoint.keys()}
408408
if "encoder" in key_prefix_set and "decoder" in key_prefix_set:
409409
converted_checkpoint = convert_vq_autoenc_checkpoint(checkpoint, config)
410410
else:

‎scripts/convert_models_diffuser_to_diffusers.py‎

Lines changed: 40 additions & 40 deletions

0 commit comments

Comments
 (0)