_profiler.pyi 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. from enum import Enum
  2. from typing import List, Literal, Optional, Tuple, Union
  3. from torch._C import device, dtype, layout
  4. # defined in torch/csrc/profiler/python/init.cpp
  5. class RecordScope(Enum):
  6. FUNCTION = ...
  7. BACKWARD_FUNCTION = ...
  8. TORCHSCRIPT_FUNCTION = ...
  9. KERNEL_FUNCTION_DTYPE = ...
  10. CUSTOM_CLASS = ...
  11. BUILD_FEATURE = ...
  12. LITE_INTERPRETER = ...
  13. USER_SCOPE = ...
  14. STATIC_RUNTIME_OP = ...
  15. STATIC_RUNTIME_MODEL = ...
  16. class ProfilerState(Enum):
  17. Disable = ...
  18. CPU = ...
  19. CUDA = ...
  20. NVTX = ...
  21. ITT = ...
  22. KINETO = ...
  23. KINETO_GPU_FALLBACK = ...
  24. class ActiveProfilerType(Enum):
  25. NONE = ...
  26. LEGACY = ...
  27. KINETO = ...
  28. NVTX = ...
  29. ITT = ...
  30. class ProfilerActivity(Enum):
  31. CPU = ...
  32. CUDA = ...
  33. class _EventType(Enum):
  34. TorchOp = ...
  35. Backend = ...
  36. Allocation = ...
  37. OutOfMemory = ...
  38. PyCall = ...
  39. PyCCall = ...
  40. Kineto = ...
  41. class _ExperimentalConfig:
  42. def __init__(
  43. self,
  44. profiler_metrics: List[str] = ...,
  45. profiler_measure_per_kernel: bool = ...,
  46. verbose: bool = ...,
  47. ) -> None: ...
  48. ...
  49. class ProfilerConfig:
  50. def __init__(
  51. self,
  52. state: ProfilerState,
  53. report_input_shapes: bool,
  54. profile_memory: bool,
  55. with_stack: bool,
  56. with_flops: bool,
  57. with_modules: bool,
  58. experimental_config: _ExperimentalConfig,
  59. ) -> None: ...
  60. ...
  61. class _ProfilerEvent:
  62. start_tid: int
  63. start_time_ns: int
  64. children: List[_ProfilerEvent]
  65. # TODO(robieta): remove in favor of `self.typed`
  66. extra_fields: Union[
  67. _ExtraFields_TorchOp,
  68. _ExtraFields_Backend,
  69. _ExtraFields_Allocation,
  70. _ExtraFields_OutOfMemory,
  71. _ExtraFields_PyCall,
  72. _ExtraFields_PyCCall,
  73. _ExtraFields_Kineto,
  74. ]
  75. @property
  76. def typed(
  77. self,
  78. ) -> Union[
  79. Tuple[Literal[_EventType.TorchOp], _ExtraFields_TorchOp],
  80. Tuple[Literal[_EventType.Backend], _ExtraFields_Backend],
  81. Tuple[Literal[_EventType.Allocation], _ExtraFields_Allocation],
  82. Tuple[Literal[_EventType.OutOfMemory], _ExtraFields_OutOfMemory],
  83. Tuple[Literal[_EventType.PyCall], _ExtraFields_PyCall],
  84. Tuple[Literal[_EventType.PyCCall], _ExtraFields_PyCCall],
  85. Tuple[Literal[_EventType.Kineto], _ExtraFields_Kineto],
  86. ]: ...
  87. @property
  88. def name(self) -> str: ...
  89. @property
  90. def tag(self) -> _EventType: ...
  91. @property
  92. def id(self) -> int: ...
  93. @property
  94. def parent(self) -> Optional[_ProfilerEvent]: ...
  95. @property
  96. def correlation_id(self) -> int: ...
  97. @property
  98. def end_time_ns(self) -> int: ...
  99. @property
  100. def duration_time_ns(self) -> int: ...
  101. class _TensorMetadata:
  102. impl_ptr: Optional[int]
  103. storage_data_ptr: Optional[int]
  104. id: Optional[int]
  105. @property
  106. def allocation_id(self) -> Optional[int]: ...
  107. @property
  108. def layout(self) -> layout: ...
  109. @property
  110. def device(self) -> device: ...
  111. @property
  112. def dtype(self) -> dtype: ...
  113. @property
  114. def sizes(self) -> List[int]: ...
  115. @property
  116. def strides(self) -> List[int]: ...
  117. Scalar = Union[int, float, bool, complex]
  118. Input = Optional[Union[_TensorMetadata, List[_TensorMetadata], Scalar]]
  119. class _ExtraFields_TorchOp:
  120. name: str
  121. sequence_number: int
  122. allow_tf32_cublas: bool
  123. @property
  124. def inputs(self) -> List[Input]: ...
  125. @property
  126. def scope(self) -> RecordScope: ...
  127. class _ExtraFields_Backend: ...
  128. class _ExtraFields_Allocation:
  129. ptr: int
  130. id: Optional[int]
  131. alloc_size: int
  132. total_allocated: int
  133. total_reserved: int
  134. @property
  135. def allocation_id(self) -> Optional[int]: ...
  136. @property
  137. def device(self) -> device: ...
  138. class _ExtraFields_OutOfMemory: ...
  139. class _PyFrameState:
  140. line_number: int
  141. function_name: str
  142. @property
  143. def file_name(self) -> str: ...
  144. class _NNModuleInfo:
  145. @property
  146. def self_ptr(self) -> int: ...
  147. @property
  148. def cls_ptr(self) -> int: ...
  149. @property
  150. def cls_name(self) -> str: ...
  151. @property
  152. def parameters(
  153. self,
  154. ) -> List[Tuple[str, _TensorMetadata, Optional[_TensorMetadata]]]: ...
  155. class _OptimizerInfo:
  156. @property
  157. def parameters(
  158. self,
  159. ) -> List[
  160. Tuple[
  161. # Parameter
  162. _TensorMetadata,
  163. #
  164. # Gradient (if present during optimizer.step())
  165. Optional[_TensorMetadata],
  166. #
  167. # Optimizer state for Parameter as (name, tensor) pairs
  168. List[Tuple[str, _TensorMetadata]],
  169. ]
  170. ]: ...
  171. class _ExtraFields_PyCCall:
  172. @property
  173. def caller(self) -> _PyFrameState: ...
  174. class _ExtraFields_PyCall:
  175. @property
  176. def callsite(self) -> _PyFrameState: ...
  177. @property
  178. def caller(self) -> _PyFrameState: ...
  179. @property
  180. def module(self) -> Optional[_NNModuleInfo]: ...
  181. @property
  182. def optimizer(self) -> Optional[_OptimizerInfo]: ...
  183. class _ExtraFields_Kineto: ...
  184. def _add_execution_graph_observer(output_file_path: str) -> bool: ...
  185. def _remove_execution_graph_observer() -> None: ...
  186. def _enable_execution_graph_observer() -> None: ...
  187. def _disable_execution_graph_observer() -> None: ...