Skip to content

Commit 2845814

Browse files
haosenwang1018rwightman
authored andcommitted
fix: replace bare except clauses with except Exception
Bare `except:` catches BaseException including KeyboardInterrupt and SystemExit. Replaced 5 instances with `except Exception:`.
1 parent 9326ff2 commit 2845814

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

tests/test_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_model_forward(model_name, batch_size):
190190
# Test that grad-checkpointing, if supported, doesn't cause model failures or change in output
191191
try:
192192
model.set_grad_checkpointing()
193-
except:
193+
except Exception:
194194
# throws if not supported, that's fine
195195
pass
196196
else:
@@ -551,7 +551,7 @@ def test_model_forward_intermediates(model_name, batch_size):
551551
# Test that grad-checkpointing, if supported
552552
try:
553553
model.set_grad_checkpointing()
554-
except:
554+
except Exception:
555555
# throws if not supported, that's fine
556556
pass
557557
else:

timm/optim/adamw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def adamw(
205205
try:
206206
# cannot do foreach if this overload doesn't exist when caution enabled
207207
foreach = not caution or 'Scalar' in torch.ops.aten._foreach_maximum_.overloads()
208-
except:
208+
except Exception:
209209
foreach = False
210210

211211
if foreach and not torch.jit.is_scripting():

timm/optim/adan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def step(self, closure=None):
124124

125125
try:
126126
has_scalar_maximum = 'Scalar' in torch.ops.aten._foreach_maximum_.overloads()
127-
except:
127+
except Exception:
128128
has_scalar_maximum = False
129129

130130
for group in self.param_groups:

timm/optim/nadamw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def nadamw(
182182
try:
183183
# cannot do foreach if this overload doesn't exist when caution enabled
184184
foreach = not caution or 'Scalar' in torch.ops.aten._foreach_maximum_.overloads()
185-
except:
185+
except Exception:
186186
foreach = False
187187

188188
if foreach and not torch.jit.is_scripting():

0 commit comments

Comments
 (0)