Skip to content

Commit 3deec57

Browse files
committed
update: test_closure
1 parent f0496a4 commit 3deec57

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

tests/test_optimizers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,16 @@ def test_pc_grad_optimizers(reduction, optimizer_pc_grad_config):
230230
def test_closure(optimizer):
231231
param = simple_parameter()
232232

233-
if optimizer.__name__ == 'Ranger21':
234-
optimizer = optimizer([param], num_iterations=1)
235-
else:
236-
optimizer = optimizer([param])
233+
optimizer_name: str = optimizer.__name__
237234

235+
optimizer = optimizer([param], num_iterations=1) if optimizer_name == 'Ranger21' else optimizer([param])
238236
optimizer.zero_grad()
239237

240-
try:
238+
if optimizer_name in ('Ranger21', 'Adai'):
239+
with pytest.raises(ZeroParameterSizeError):
240+
optimizer.step(closure=dummy_closure)
241+
else:
241242
optimizer.step(closure=dummy_closure)
242-
except ZeroParameterSizeError: # in case of Ranger21, Adai optimizers
243-
pass
244243

245244

246245
def test_no_closure():

0 commit comments

Comments
 (0)