Files
pytorch/torch/optim/optimizer.pyi
T
Xuehai Pan 1fd119948e [3/3] Update .pyi Python stub files and enable 'UFMT' linter (#95268)
Changes:

- #95200

1. Recognize `.py.in` and `.pyi.in` files as Python in VS Code for a better development experience.
2. Fix deep setting merge in `tools/vscode_settings.py`.

- #95267

3. Use `Namedtuple` rather than `namedtuple + __annotations__` for `torch.nn.utils.rnn.PackedSequence_`:

    `namedtuple + __annotations__`:

    ```python
    PackedSequence_ = namedtuple('PackedSequence_',
                                 ['data', 'batch_sizes', 'sorted_indices', 'unsorted_indices'])

    # type annotation for PackedSequence_ to make it compatible with TorchScript
    PackedSequence_.__annotations__ = {'data': torch.Tensor, 'batch_sizes': torch.Tensor,
                                       'sorted_indices': Optional[torch.Tensor],
                                       'unsorted_indices': Optional[torch.Tensor]}
    ```

    `Namedtuple`: Python 3.6+

    ```python
    class PackedSequence_(NamedTuple):
        data: torch.Tensor
        batch_sizes: torch.Tensor
        sorted_indices: Optional[torch.Tensor]
        unsorted_indices: Optional[torch.Tensor]
    ```

- => this PR: #95268

4. Sort import statements and remove unnecessary imports in `.pyi`, `.pyi.in` files.
5. Format `.pyi`, `.pyi.in` files and remove unnecessary ellipsis `...` in type stubs.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/95268
Approved by: https://github.com/huydhn
2023-03-01 23:50:56 +00:00

25 lines
1.1 KiB
Python

from typing import Any, Callable, Dict, Iterable, List, Optional, Union
from torch import Tensor
from torch.utils.hooks import RemovableHandle
_params_t = Union[Iterable[Tensor], Iterable[Dict[str, Any]]]
def register_optimizer_step_pre_hook(hook: Callable[..., None]) -> RemovableHandle: ...
def register_optimizer_step_post_hook(hook: Callable[..., None]) -> RemovableHandle: ...
class Optimizer:
defaults: Dict[str, Any]
state: Dict[str, Any]
param_groups: List[Dict[str, Any]]
def __init__(self, params: _params_t, defaults: Dict[str, Any]) -> None: ...
def __setstate__(self, state: Dict[str, Any]) -> None: ...
def register_step_pre_hook(self, hook: Callable[..., None]) -> RemovableHandle: ...
def register_step_post_hook(self, hook: Callable[..., None]) -> RemovableHandle: ...
def state_dict(self) -> Dict[str, Any]: ...
def load_state_dict(self, state_dict: Dict[str, Any]) -> None: ...
def zero_grad(self, set_to_none: bool = ...) -> None: ...
def step(self, closure: Optional[Callable[[], float]] = ...) -> Optional[float]: ...
def add_param_group(self, param_group: Dict[str, Any]) -> None: ...