Fix the type hint of step() with default value (#153367)

Summary: Because the default value of `closure` is `None`, this fixes the situation when `step()`. The previous typing (https://github.com/pytorch/pytorch/pull/102593) could only be used as `step(closure=None)` and `step(None)`.

Test Plan: contbuild & OSS CI

Differential Revision: D74560785

Pull Request resolved: https://github.com/pytorch/pytorch/pull/153367
Approved by: https://github.com/cyyever, https://github.com/Skylion007, https://github.com/janeyx99
This commit is contained in:
Tsung-Hsien Lee
2025-05-12 15:52:56 +00:00
committed by PyTorch MergeBot
parent de5c5f4fb7
commit ea4b65ab60

View File

@ -1004,7 +1004,7 @@ class Optimizer:
torch._foreach_zero_(grads)
@overload
def step(self, closure: None = ...) -> None:
def step(self, closure: None = None) -> None:
...
@overload