Skip to content

Commit e01a827

Browse files
committed
ci(test): test_no_closure case
1 parent 94bcd3a commit e01a827

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/test_optimizers.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
SafeFP16Optimizer,
3131
Shampoo,
3232
)
33-
from pytorch_optimizer.base.exception import ZeroParameterSizeError
33+
from pytorch_optimizer.base.exception import ZeroParameterSizeError, NoClosureError
3434
from tests.utils import (
3535
MultiHeadLogisticRegression,
3636
build_environment,
@@ -365,6 +365,16 @@ def test_closure(optimizer):
365365
pass
366366

367367

368+
def test_no_closure():
369+
_, model, _ = build_environment()
370+
371+
optimizer = SAM(model.parameters(), AdamP)
372+
optimizer.zero_grad()
373+
374+
with pytest.raises(NoClosureError):
375+
optimizer.step()
376+
377+
368378
@pytest.mark.parametrize('optimizer_config', OPTIMIZERS, ids=ids)
369379
def test_reset(optimizer_config):
370380
_, model, _ = build_environment()

0 commit comments

Comments
 (0)