scatter_gather.pyi 989 B

123456789101112131415161718192021222324
  1. from typing import Any, Dict, List, Tuple, overload, TypeVar
  2. from ... import Tensor
  3. from .common_types import _device_t, _devices_t
  4. T = TypeVar('T', Dict, List, Tuple)
  5. # For some reason, 'scatter' returns a tuple when given a single Tensor input but a list otherwise.
  6. @overload
  7. def scatter(inputs: Tensor, target_gpus: _devices_t, dim: int = ...) -> Tuple[Tensor, ...]: ...
  8. # flake8 will raise a spurious error here since `torch/__init__.pyi` has not been generated yet
  9. # so mypy will interpret `Tensor` as `Any` since it is an import from what it believes to be an
  10. # untyped module. Thus to mypy, the first definition of `scatter` looks strictly more general
  11. # than this overload.
  12. @overload
  13. def scatter(inputs: T, target_gpus: _devices_t, dim: int = ...) -> List[T]: ...
  14. # TODO More precise types here.
  15. def scatter_kwargs(inputs: Any, kwargs: Any, target_gpus: _devices_t, dim: int = ...) -> Any: ...
  16. def gather(outputs: Any, target_device: _device_t, dim: int = ...) -> Any: ...