-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Configure ruff and black for linting #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d9e32c0
6379cb1
295787e
a770cd2
e0f746a
e4a7d36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| name: Lint | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| Lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-python@v3 | ||
| - uses: pre-commit/action@v3.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| minimum_pre_commit_version: 2.15.0 | ||
| ci: | ||
| autofix_prs: false | ||
| repos: | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.1.6 | ||
| hooks: | ||
| - id: ruff | ||
| args: [--fix, --exit-non-zero-on-fix] | ||
| - repo: https://github.com/psf/black | ||
| rev: 23.11.0 | ||
| hooks: | ||
| - id: black |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,7 +402,6 @@ def log_img(self, pl_module, batch, batch_idx, split="train"): | |
| # batch_idx > 5 and | ||
| self.max_images > 0 | ||
| ): | ||
| logger = type(pl_module.logger) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused local. |
||
| is_train = pl_module.training | ||
| if is_train: | ||
| pl_module.eval() | ||
|
|
@@ -648,7 +647,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str): | |
|
|
||
| ckpt_resume_path = opt.resume_from_checkpoint | ||
|
|
||
| if not "devices" in trainer_config and trainer_config["accelerator"] != "gpu": | ||
| if "devices" not in trainer_config and trainer_config["accelerator"] != "gpu": | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| del trainer_config["accelerator"] | ||
| cpu = True | ||
| else: | ||
|
|
@@ -691,7 +690,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str): | |
| # TODO change once leaving "swiffer" config directory | ||
| try: | ||
| group_name = nowname.split(now)[-1].split("-")[1] | ||
| except: | ||
| except Exception: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| group_name = nowname | ||
| default_logger_cfg["params"]["group"] = group_name | ||
| init_wandb( | ||
|
|
@@ -814,7 +813,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str): | |
| trainer_kwargs["callbacks"] = [ | ||
| instantiate_from_config(callbacks_cfg[k]) for k in callbacks_cfg | ||
| ] | ||
| if not "plugins" in trainer_kwargs: | ||
| if "plugins" not in trainer_kwargs: | ||
| trainer_kwargs["plugins"] = list() | ||
|
|
||
| # cmd line trainer args (which are in trainer_opt) have always priority over config-trainer-args (which are in trainer_kwargs) | ||
|
|
@@ -839,7 +838,7 @@ def init_wandb(save_dir, opt, config, group_name, name_str): | |
| print( | ||
| f"{k}, {data.datasets[k].__class__.__name__}, {len(data.datasets[k])}" | ||
| ) | ||
| except: | ||
| except Exception: | ||
| print("datasets not yet initialized.") | ||
|
|
||
| # configure learning rate | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,12 @@ def __init__(self, discretization: Discretization, strength: float = 1.0): | |
| def __call__(self, *args, **kwargs): | ||
| # sigmas start large first, and decrease then | ||
| sigmas = self.discretization(*args, **kwargs) | ||
| print(f"sigmas after discretization, before pruning img2img: ", sigmas) | ||
| print("sigmas after discretization, before pruning img2img: ", sigmas) | ||
| sigmas = torch.flip(sigmas, (0,)) | ||
| sigmas = sigmas[: max(int(self.strength * len(sigmas)), 1)] | ||
| print("prune index:", max(int(self.strength * len(sigmas)), 1)) | ||
| sigmas = torch.flip(sigmas, (0,)) | ||
| print(f"sigmas after pruning: ", sigmas) | ||
| print("sigmas after pruning: ", sigmas) | ||
|
Comment on lines
-21
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
| return sigmas | ||
|
|
||
|
|
||
|
|
@@ -45,7 +45,7 @@ def __init__( | |
| def __call__(self, *args, **kwargs): | ||
| # sigmas start large first, and decrease then | ||
| sigmas = self.discretization(*args, **kwargs) | ||
| print(f"sigmas after discretization, before pruning img2img: ", sigmas) | ||
| print("sigmas after discretization, before pruning img2img: ", sigmas) | ||
| sigmas = torch.flip(sigmas, (0,)) | ||
| if self.original_steps is None: | ||
| steps = len(sigmas) | ||
|
|
@@ -55,5 +55,5 @@ def __call__(self, *args, **kwargs): | |
| sigmas = sigmas[prune_index:] | ||
| print("prune index:", prune_index) | ||
| sigmas = torch.flip(sigmas, (0,)) | ||
| print(f"sigmas after pruning: ", sigmas) | ||
| print("sigmas after pruning: ", sigmas) | ||
| return sigmas | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,37 +8,37 @@ | |
| import numpy as np | ||
| import streamlit as st | ||
| import torch | ||
| import torch.nn as nn | ||
| import torchvision.transforms as TT | ||
| from einops import rearrange, repeat | ||
| from imwatermark import WatermarkEncoder | ||
| from omegaconf import ListConfig, OmegaConf | ||
| from PIL import Image | ||
| from safetensors.torch import load_file as load_safetensors | ||
| from torch import autocast | ||
| from torchvision import transforms | ||
| from torchvision.utils import make_grid, save_image | ||
|
|
||
| from scripts.demo.discretization import (Img2ImgDiscretizationWrapper, | ||
| Txt2NoisyDiscretizationWrapper) | ||
| from scripts.util.detection.nsfw_and_watermark_dectection import \ | ||
| DeepFloydDataFiltering | ||
| from scripts.demo.discretization import ( | ||
| Img2ImgDiscretizationWrapper, | ||
| Txt2NoisyDiscretizationWrapper, | ||
| ) | ||
| from scripts.util.detection.nsfw_and_watermark_dectection import DeepFloydDataFiltering | ||
| from sgm.inference.helpers import embed_watermark | ||
| from sgm.modules.diffusionmodules.guiders import (LinearPredictionGuider, | ||
| VanillaCFG) | ||
| from sgm.modules.diffusionmodules.sampling import (DPMPP2MSampler, | ||
| DPMPP2SAncestralSampler, | ||
| EulerAncestralSampler, | ||
| EulerEDMSampler, | ||
| HeunEDMSampler, | ||
| LinearMultistepSampler) | ||
| from sgm.modules.diffusionmodules.guiders import LinearPredictionGuider, VanillaCFG | ||
| from sgm.modules.diffusionmodules.sampling import ( | ||
| DPMPP2MSampler, | ||
| DPMPP2SAncestralSampler, | ||
| EulerAncestralSampler, | ||
| EulerEDMSampler, | ||
| HeunEDMSampler, | ||
| LinearMultistepSampler, | ||
| ) | ||
| from sgm.util import append_dims, default, instantiate_from_config | ||
|
|
||
|
|
||
| @st.cache_resource() | ||
| def init_st(version_dict, load_ckpt=True, load_filter=True): | ||
| state = dict() | ||
| if not "model" in state: | ||
| if "model" not in state: | ||
| config = version_dict["config"] | ||
| ckpt = version_dict["ckpt"] | ||
|
|
||
|
|
@@ -253,7 +253,7 @@ def get_guider(options, key): | |
| min_value=1.0, | ||
| ) | ||
| min_scale = st.number_input( | ||
| f"min guidance scale", | ||
| "min guidance scale", | ||
| value=options.get("min_cfg", 1.0), | ||
| min_value=1.0, | ||
| max_value=10.0, | ||
|
|
@@ -432,15 +432,6 @@ def get_sampler(sampler_name, steps, discretization_config, guider_config, key=1 | |
| return sampler | ||
|
|
||
|
|
||
| def get_interactive_image() -> Image.Image: | ||
| image = st.file_uploader("Input", type=["jpg", "JPEG", "png"]) | ||
| if image is not None: | ||
| image = Image.open(image) | ||
| if not image.mode == "RGB": | ||
| image = image.convert("RGB") | ||
| return image | ||
|
|
||
|
|
||
|
Comment on lines
-435
to
-443
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated function. |
||
| def load_img( | ||
| display: bool = True, | ||
| size: Union[None, int, Tuple[int, int]] = None, | ||
|
|
@@ -776,7 +767,7 @@ def denoiser(x, sigma, c): | |
| if filter is not None: | ||
| samples = filter(samples) | ||
|
|
||
| grid = rearrange(grid, "n b c h w -> (n h) (b w) c") | ||
| grid = rearrange(grid, "n b c h w -> (n h) (b w) c") # noqa: F821 | ||
| outputs.image(grid.cpu().numpy()) | ||
| if return_latents: | ||
| return samples, samples_z | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs): | |
| dtype=dtype, | ||
| ) | ||
|
|
||
| print(f"q/k/v shape:", query.shape, key.shape, value.shape) | ||
| print("q/k/v shape:", query.shape, key.shape, value.shape) | ||
|
|
||
| # Lets explore the speed of each of the 3 implementations | ||
| from torch.backends.cuda import SDPBackend, sdp_kernel | ||
|
|
@@ -87,7 +87,7 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs): | |
| ) as prof: | ||
| with record_function("Default detailed stats"): | ||
| for _ in range(25): | ||
| o = F.scaled_dot_product_attention(query, key, value) | ||
| _o = F.scaled_dot_product_attention(query, key, value) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused local, mark it as such. |
||
| print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) | ||
|
|
||
| print( | ||
|
|
@@ -99,7 +99,7 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs): | |
| ) as prof: | ||
| with record_function("Math implmentation stats"): | ||
| for _ in range(25): | ||
| o = F.scaled_dot_product_attention(query, key, value) | ||
| _o = F.scaled_dot_product_attention(query, key, value) | ||
| print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) | ||
|
|
||
| with sdp_kernel(**backend_map[SDPBackend.FLASH_ATTENTION]): | ||
|
|
@@ -114,7 +114,7 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs): | |
| ) as prof: | ||
| with record_function("FlashAttention stats"): | ||
| for _ in range(25): | ||
| o = F.scaled_dot_product_attention(query, key, value) | ||
| _o = F.scaled_dot_product_attention(query, key, value) | ||
| print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) | ||
|
|
||
| with sdp_kernel(**backend_map[SDPBackend.EFFICIENT_ATTENTION]): | ||
|
|
@@ -129,7 +129,7 @@ def benchmark_torch_function_in_microseconds(f, *args, **kwargs): | |
| ) as prof: | ||
| with record_function("EfficientAttention stats"): | ||
| for _ in range(25): | ||
| o = F.scaled_dot_product_attention(query, key, value) | ||
| _o = F.scaled_dot_product_attention(query, key, value) | ||
| print(prof.key_averages().table(sort_by="cuda_time_total", row_limit=10)) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.