Skip to content

Commit

Permalink
Fix other Ruff complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jul 26, 2023
1 parent 114afa2 commit f85b1e8
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,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:
group_name = nowname
default_logger_cfg["params"]["group"] = group_name
init_wandb(
Expand Down Expand Up @@ -838,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
Expand Down
2 changes: 1 addition & 1 deletion scripts/demo/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def decode(self, cv2Image, method="dwtDct", **configs):
bits = embed.decode(cv2Image)
return self.reconstruct(bits)

except:
except Exception:
raise e


Expand Down
2 changes: 1 addition & 1 deletion sgm/inference/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def do_sample(
if isinstance(batch[key], torch.Tensor):
print(key, batch[key].shape)
elif isinstance(batch[key], list):
print(key, [len(l) for l in batch[key]])
print(key, [len(lst) for lst in batch[key]])
else:
print(key, batch[key])
c, uc = model.conditioner.get_unconditional_conditioning(
Expand Down
6 changes: 3 additions & 3 deletions sgm/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from packaging import version
from torch import nn

from .diffusionmodules.util import checkpoint

if version.parse(torch.__version__) >= version.parse("2.0.0"):
SDP_IS_AVAILABLE = True
from torch.backends.cuda import SDPBackend, sdp_kernel
Expand Down Expand Up @@ -46,12 +48,10 @@
import xformers.ops

XFORMERS_IS_AVAILABLE = True
except:
except Exception:
XFORMERS_IS_AVAILABLE = False
print("no module 'xformers'. Processing without...")

from .diffusionmodules.util import checkpoint


def exists(val):
return val is not None
Expand Down
2 changes: 1 addition & 1 deletion sgm/modules/autoencoding/lpips/loss/lpips.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def forward(self, input, target):
for kk in range(len(self.chns))
]
val = res[0]
for l in range(1, len(self.chns)):
for l in range(1, len(self.chns)): # noqa: E741
val += res[l]
return val

Expand Down
6 changes: 3 additions & 3 deletions sgm/modules/diffusionmodules/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from einops import rearrange
from packaging import version

from ...modules.attention import LinearAttention, MemoryEfficientCrossAttention

try:
import xformers
import xformers.ops

XFORMERS_IS_AVAILABLE = True
except:
except Exception:
XFORMERS_IS_AVAILABLE = False
print("no module 'xformers'. Processing without...")

from ...modules.attention import LinearAttention, MemoryEfficientCrossAttention


def get_timestep_embedding(timesteps, embedding_dim):
"""
Expand Down
3 changes: 2 additions & 1 deletion sgm/modules/diffusionmodules/openaimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ def __init__(

self.use_fairscale_checkpoint = False
checkpoint_wrapper_fn = (
partial(checkpoint_wrapper, offload_to_cpu=offload_to_cpu)
# TODO: this can't work since `checkpoint_wrapper` is not defined
partial(checkpoint_wrapper, offload_to_cpu=offload_to_cpu) # noqa: F821
if self.use_fairscale_checkpoint
else lambda x: x
)
Expand Down
2 changes: 1 addition & 1 deletion sgm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_string_from_tuple(s):
return t[0]
else:
pass
except:
except Exception:
pass
return s

Expand Down

0 comments on commit f85b1e8

Please sign in to comment.