_profiler.pyi 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. from enum import Enum
  2. from typing import Literal
  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. HPU = ...
  39. PrivateUse1 = ...
  40. class _EventType(Enum):
  41. TorchOp = ...
  42. Backend = ...
  43. Allocation = ...
  44. OutOfMemory = ...
  45. PyCall = ...
  46. PyCCall = ...
  47. Kineto = ...
  48. class _ExperimentalConfig:
  49. def __init__(
  50. self,
  51. profiler_metrics: list[str] = ...,
  52. profiler_measure_per_kernel: bool = ...,
  53. verbose: bool = ...,
  54. performance_events: list[str] = ...,
  55. enable_cuda_sync_events: bool = ...,
  56. ) -> None: ...
  57. class ProfilerConfig:
  58. def __init__(
  59. self,
  60. state: ProfilerState,
  61. report_input_shapes: bool,
  62. profile_memory: bool,
  63. with_stack: bool,
  64. with_flops: bool,
  65. with_modules: bool,
  66. experimental_config: _ExperimentalConfig,
  67. trace_id: str | None = None,
  68. ) -> None: ...
  69. class _ProfilerEvent:
  70. start_tid: int
  71. start_time_ns: int
  72. children: list[_ProfilerEvent]
  73. # TODO(robieta): remove in favor of `self.typed`
  74. extra_fields: (
  75. _ExtraFields_TorchOp
  76. | _ExtraFields_Backend
  77. | _ExtraFields_Allocation
  78. | _ExtraFields_OutOfMemory
  79. | _ExtraFields_PyCall
  80. | _ExtraFields_PyCCall
  81. | _ExtraFields_Kineto
  82. )
  83. @property
  84. def typed(
  85. self,
  86. ) -> (
  87. tuple[Literal[_EventType.TorchOp], _ExtraFields_TorchOp]
  88. | tuple[Literal[_EventType.Backend], _ExtraFields_Backend]
  89. | tuple[Literal[_EventType.Allocation], _ExtraFields_Allocation]
  90. | tuple[Literal[_EventType.OutOfMemory], _ExtraFields_OutOfMemory]
  91. | tuple[Literal[_EventType.PyCall], _ExtraFields_PyCall]
  92. | tuple[Literal[_EventType.PyCCall], _ExtraFields_PyCCall]
  93. | tuple[Literal[_EventType.Kineto], _ExtraFields_Kineto]
  94. ): ...
  95. @property
  96. def name(self) -> str: ...
  97. @property
  98. def tag(self) -> _EventType: ...
  99. @property
  100. def id(self) -> int: ...
  101. @property
  102. def parent(self) -> _ProfilerEvent | None: ...
  103. @property
  104. def correlation_id(self) -> int: ...
  105. @property
  106. def end_time_ns(self) -> int: ...
  107. @property
  108. def duration_time_ns(self) -> int: ...
  109. class _TensorMetadata:
  110. impl_ptr: int | None
  111. storage_data_ptr: int | None
  112. id: int | None
  113. @property
  114. def allocation_id(self) -> int | None: ...
  115. @property
  116. def layout(self) -> layout: ...
  117. @property
  118. def device(self) -> device: ...
  119. @property
  120. def dtype(self) -> dtype: ...
  121. @property
  122. def sizes(self) -> list[int]: ...
  123. @property
  124. def strides(self) -> list[int]: ...
  125. Scalar: TypeAlias = int | float | bool | complex
  126. Input: TypeAlias = _TensorMetadata | list[_TensorMetadata] | Scalar | None
  127. class _ExtraFields_TorchOp:
  128. name: str
  129. sequence_number: int
  130. allow_tf32_cublas: bool
  131. @property
  132. def inputs(self) -> list[Input]: ...
  133. @property
  134. def scope(self) -> RecordScope: ...
  135. class _ExtraFields_Backend: ...
  136. class _ExtraFields_Allocation:
  137. ptr: int
  138. id: int | None
  139. alloc_size: int
  140. total_allocated: int
  141. total_reserved: int
  142. @property
  143. def allocation_id(self) -> int | None: ...
  144. @property
  145. def device(self) -> device: ...
  146. class _ExtraFields_OutOfMemory: ...
  147. class _PyFrameState:
  148. line_number: int
  149. function_name: str
  150. @property
  151. def file_name(self) -> str: ...
  152. class _NNModuleInfo:
  153. @property
  154. def self_ptr(self) -> int: ...
  155. @property
  156. def cls_ptr(self) -> int: ...
  157. @property
  158. def cls_name(self) -> str: ...
  159. @property
  160. def parameters(
  161. self,
  162. ) -> list[tuple[str, _TensorMetadata, _TensorMetadata | None]]: ...
  163. class _OptimizerInfo:
  164. @property
  165. def parameters(
  166. self,
  167. ) -> list[
  168. tuple[
  169. # Parameter
  170. _TensorMetadata,
  171. #
  172. # Gradient (if present during optimizer.step())
  173. _TensorMetadata | None,
  174. #
  175. # Optimizer state for Parameter as (name, tensor) pairs
  176. list[tuple[str, _TensorMetadata]],
  177. ]
  178. ]: ...
  179. class _ExtraFields_PyCCall:
  180. @property
  181. def caller(self) -> _PyFrameState: ...
  182. class _ExtraFields_PyCall:
  183. @property
  184. def callsite(self) -> _PyFrameState: ...
  185. @property
  186. def caller(self) -> _PyFrameState: ...
  187. @property
  188. def module(self) -> _NNModuleInfo | None: ...
  189. @property
  190. def optimizer(self) -> _OptimizerInfo | None: ...
  191. class _ExtraFields_Kineto: ...
  192. def _add_execution_trace_observer(output_file_path: str) -> bool: ...
  193. def _remove_execution_trace_observer() -> None: ...
  194. def _enable_execution_trace_observer() -> None: ...
  195. def _disable_execution_trace_observer() -> None: ...
  196. def _set_record_concrete_inputs_enabled_val(val: bool) -> None: ...
  197. def _set_fwd_bwd_enabled_val(val: bool) -> None: ...
  198. def _set_cuda_sync_enabled_val(val: bool) -> None: ...
  199. class CapturedTraceback: ...
  200. def gather_traceback(python: bool, script: bool, cpp: bool) -> CapturedTraceback: ...
  201. # The Dict has name, filename, line
  202. def symbolize_tracebacks(
  203. to_symbolize: list[CapturedTraceback],
  204. ) -> list[list[dict[str, str]]]: ...
  205. class _RecordFunctionFast:
  206. def __init__(
  207. self,
  208. name: str,
  209. input_values: list | tuple | None = None,
  210. keyword_values: dict | None = None,
  211. ) -> None: ...
  212. def __enter__(self) -> None: ...
  213. def __exit__(self, *exc_info: object) -> None: ...