_profiler.pyi 6.2 KB

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