datapipe.pyi 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # This base template ("datapipe.pyi.in") is generated from mypy stubgen with minimal editing for code injection
  2. # The output file will be "datapipe.pyi". This is executed as part of torch/CMakeLists.txt
  3. # Note that, for mypy, .pyi file takes precedent over .py file, such that we must define the interface for other
  4. # classes/objects here, even though we are not injecting extra code into them at the moment.
  5. from torch.utils.data.datapipes._typing import _DataPipeMeta, _IterDataPipeMeta
  6. from torch.utils.data.datapipes._hook_iterator import _SnapshotState
  7. from typing import Any, Callable, Dict, Generic, Iterator, List, Optional, TypeVar, Union
  8. from torch.utils.data import Dataset, IterableDataset, default_collate
  9. T_co = TypeVar('T_co', covariant=True)
  10. T = TypeVar('T')
  11. UNTRACABLE_DATAFRAME_PIPES: Any
  12. class MapDataPipe(Dataset[T_co], metaclass=_DataPipeMeta):
  13. functions: Dict[str, Callable] = ...
  14. reduce_ex_hook: Optional[Callable] = ...
  15. getstate_hook: Optional[Callable] = ...
  16. str_hook: Optional[Callable] = ...
  17. repr_hook: Optional[Callable] = ...
  18. def __getattr__(self, attribute_name: Any): ...
  19. @classmethod
  20. def register_function(cls, function_name: Any, function: Any) -> None: ...
  21. @classmethod
  22. def register_datapipe_as_function(cls, function_name: Any, cls_to_register: Any): ...
  23. def __getstate__(self): ...
  24. def __reduce_ex__(self, *args: Any, **kwargs: Any): ...
  25. @classmethod
  26. def set_getstate_hook(cls, hook_fn: Any) -> None: ...
  27. @classmethod
  28. def set_reduce_ex_hook(cls, hook_fn: Any) -> None: ...
  29. # Functional form of 'BatcherMapDataPipe'
  30. def batch(self, batch_size: int, drop_last: bool = False, wrapper_class=DataChunk) -> MapDataPipe: ...
  31. # Functional form of 'ConcaterMapDataPipe'
  32. def concat(self, *datapipes: MapDataPipe) -> MapDataPipe: ...
  33. # Functional form of 'MapperMapDataPipe'
  34. def map(self, fn: Callable= ...) -> MapDataPipe: ...
  35. # Functional form of 'ShufflerIterDataPipe'
  36. def shuffle(self, *, indices: Optional[List] = None) -> IterDataPipe: ...
  37. # Functional form of 'ZipperMapDataPipe'
  38. def zip(self, *datapipes: MapDataPipe[T_co]) -> MapDataPipe: ...
  39. class IterDataPipe(IterableDataset[T_co], metaclass=_IterDataPipeMeta):
  40. functions: Dict[str, Callable] = ...
  41. reduce_ex_hook: Optional[Callable] = ...
  42. getstate_hook: Optional[Callable] = ...
  43. str_hook: Optional[Callable] = ...
  44. repr_hook: Optional[Callable] = ...
  45. _number_of_samples_yielded: int = ...
  46. _snapshot_state: _SnapshotState = _SnapshotState.Iterating
  47. _fast_forward_iterator: Optional[Iterator] = ...
  48. def __getattr__(self, attribute_name: Any): ...
  49. @classmethod
  50. def register_function(cls, function_name: Any, function: Any) -> None: ...
  51. @classmethod
  52. def register_datapipe_as_function(cls, function_name: Any, cls_to_register: Any, enable_df_api_tracing: bool = ...): ...
  53. def __getstate__(self): ...
  54. def __reduce_ex__(self, *args: Any, **kwargs: Any): ...
  55. @classmethod
  56. def set_getstate_hook(cls, hook_fn: Any) -> None: ...
  57. @classmethod
  58. def set_reduce_ex_hook(cls, hook_fn: Any) -> None: ...
  59. # Functional form of 'BatcherIterDataPipe'
  60. def batch(self, batch_size: int, drop_last: bool = False, wrapper_class=DataChunk) -> IterDataPipe: ...
  61. # Functional form of 'CollatorIterDataPipe'
  62. def collate(self, conversion: Optional[Union[Callable[..., Any],Dict[Union[str, Any], Union[Callable, Any]],]] = default_collate, collate_fn: Optional[Callable] = None) -> IterDataPipe: ...
  63. # Functional form of 'ConcaterIterDataPipe'
  64. def concat(self, *datapipes: IterDataPipe) -> IterDataPipe: ...
  65. # Functional form of 'DemultiplexerIterDataPipe'
  66. def demux(self, num_instances: int, classifier_fn: Callable[[T_co], Optional[int]], drop_none: bool = False, buffer_size: int = 1000) -> List[IterDataPipe]: ...
  67. # Functional form of 'FilterIterDataPipe'
  68. def filter(self, filter_fn: Callable, input_col=None) -> IterDataPipe: ...
  69. # Functional form of 'ForkerIterDataPipe'
  70. def fork(self, num_instances: int, buffer_size: int = 1000) -> List[IterDataPipe]: ...
  71. # Functional form of 'GrouperIterDataPipe'
  72. def groupby(self, group_key_fn: Callable[[T_co], Any], *, keep_key: bool = False, buffer_size: int = 10000, group_size: Optional[int] = None, guaranteed_group_size: Optional[int] = None, drop_remaining: bool = False) -> IterDataPipe: ...
  73. # Functional form of 'FileListerIterDataPipe'
  74. def list_files(self, masks: Union[str, List[str]] = '', *, recursive: bool = False, abspath: bool = False, non_deterministic: bool = False, length: int = -1) -> IterDataPipe: ...
  75. # Functional form of 'MapperIterDataPipe'
  76. def map(self, fn: Callable, input_col=None, output_col=None) -> IterDataPipe: ...
  77. # Functional form of 'MultiplexerIterDataPipe'
  78. def mux(self, *datapipes) -> IterDataPipe: ...
  79. # Functional form of 'FileOpenerIterDataPipe'
  80. def open_files(self, mode: str = 'r', encoding: Optional[str] = None, length: int = -1) -> IterDataPipe: ...
  81. # Functional form of 'StreamReaderIterDataPipe'
  82. def read_from_stream(self, chunk=None) -> IterDataPipe: ...
  83. # Functional form of 'RoutedDecoderIterDataPipe'
  84. def routed_decode(self, *handlers: Callable, key_fn: Callable= ...) -> IterDataPipe: ...
  85. # Functional form of 'ShardingFilterIterDataPipe'
  86. def sharding_filter(self, sharding_group_filter=None) -> IterDataPipe: ...
  87. # Functional form of 'ShufflerIterDataPipe'
  88. def shuffle(self, *, buffer_size: int = 10000, unbatch_level: int = 0) -> IterDataPipe: ...
  89. # Functional form of 'UnBatcherIterDataPipe'
  90. def unbatch(self, unbatch_level: int = 1) -> IterDataPipe: ...
  91. # Functional form of 'ZipperIterDataPipe'
  92. def zip(self, *datapipes: IterDataPipe) -> IterDataPipe: ...
  93. class DFIterDataPipe(IterDataPipe):
  94. def _is_dfpipe(self): ...
  95. class _DataPipeSerializationWrapper:
  96. def __init__(self, datapipe): ...
  97. def __getstate__(self): ...
  98. def __setstate__(self, state): ...
  99. def __len__(self): ...
  100. class _IterDataPipeSerializationWrapper(_DataPipeSerializationWrapper, IterDataPipe):
  101. def __iter__(self): ...
  102. class _MapDataPipeSerializationWrapper(_DataPipeSerializationWrapper, MapDataPipe):
  103. def __getitem__(self, idx): ...
  104. class DataChunk(list, Generic[T]):
  105. def __init__(self, items):
  106. super().__init__(items)
  107. self.items = items
  108. def as_str(self, indent=''):
  109. res = indent + "[" + ", ".join(str(i) for i in iter(self)) + "]"
  110. return res
  111. def __iter__(self) -> Iterator[T]:
  112. for i in super().__iter__():
  113. yield i
  114. def raw_iterator(self) -> T: # type: ignore[misc]
  115. for i in self.items:
  116. yield i