Files
pytorch/torch/_C/_distributed_rpc_testing.pyi
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

40 lines
1.0 KiB
Python

from typing import Dict, List
import torch
from ._distributed_c10d import ProcessGroup, Store
from ._distributed_rpc import (
_TensorPipeRpcBackendOptionsBase,
TensorPipeAgent,
WorkerInfo,
)
# This module is defined in torch/csrc/distributed/rpc/testing/init.cpp
class FaultyTensorPipeRpcBackendOptions(_TensorPipeRpcBackendOptionsBase):
def __init__(
self,
num_worker_threads: int,
rpc_timeout: float,
init_method: str,
messages_to_fail: List[str],
messages_to_delay: Dict[str, float],
num_fail_sends: int,
): ...
num_send_recv_threads: int
messages_to_fail: List[str]
messages_to_delay: Dict[str, float]
num_fail_sends: int
class FaultyTensorPipeAgent(TensorPipeAgent):
def __init__(
self,
store: Store,
name: str,
rank: int,
world_size: int,
options: FaultyTensorPipeRpcBackendOptions,
reverse_device_maps: Dict[str, Dict[torch.device, torch.device]],
devices: List[torch.device],
): ...