File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 3030 SafeFP16Optimizer ,
3131 Shampoo ,
3232)
33- from pytorch_optimizer .base .exception import ZeroParameterSizeError
33+ from pytorch_optimizer .base .exception import ZeroParameterSizeError , NoClosureError
3434from 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 )
369379def test_reset (optimizer_config ):
370380 _ , model , _ = build_environment ()
You can’t perform that action at this time.
0 commit comments