_autograd.pyi 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # mypy: allow-untyped-defs
  2. from enum import Enum
  3. from typing import Any, Callable
  4. import torch
  5. from torch._C._profiler import (
  6. _ProfilerEvent,
  7. ActiveProfilerType,
  8. ProfilerActivity,
  9. ProfilerConfig,
  10. )
  11. # Defined in torch/csrc/autograd/init.cpp
  12. class DeviceType(Enum):
  13. CPU = ...
  14. CUDA = ...
  15. XPU = ...
  16. MKLDNN = ...
  17. OPENGL = ...
  18. OPENCL = ...
  19. IDEEP = ...
  20. HIP = ...
  21. FPGA = ...
  22. MAIA = ...
  23. XLA = ...
  24. MTIA = ...
  25. MPS = ...
  26. HPU = ...
  27. Meta = ...
  28. Vulkan = ...
  29. Metal = ...
  30. PrivateUse1 = ...
  31. class ProfilerEvent:
  32. def cpu_elapsed_us(self, other: ProfilerEvent) -> float: ...
  33. def cpu_memory_usage(self) -> int: ...
  34. def cuda_elapsed_us(self, other: ProfilerEvent) -> float: ...
  35. def privateuse1_elapsed_us(self, other: ProfilerEvent) -> float: ...
  36. def cuda_memory_usage(self) -> int: ...
  37. def device(self) -> int: ...
  38. def handle(self) -> int: ...
  39. def has_cuda(self) -> bool: ...
  40. def is_remote(self) -> bool: ...
  41. def kind(self) -> int: ...
  42. def name(self) -> str: ...
  43. def node_id(self) -> int: ...
  44. def sequence_nr(self) -> int: ...
  45. def shapes(self) -> list[list[int]]: ...
  46. def thread_id(self) -> int: ...
  47. def flops(self) -> float: ...
  48. def is_async(self) -> bool: ...
  49. class _KinetoEvent:
  50. def name(self) -> str: ...
  51. def overload_name(self) -> str: ...
  52. def device_index(self) -> int: ...
  53. def device_resource_id(self) -> int: ...
  54. def start_ns(self) -> int: ...
  55. def end_ns(self) -> int: ...
  56. def duration_ns(self) -> int: ...
  57. def is_async(self) -> bool: ...
  58. def linked_correlation_id(self) -> int: ...
  59. def shapes(self) -> list[list[int]]: ...
  60. def dtypes(self) -> list[str]: ...
  61. def concrete_inputs(self) -> list[Any]: ...
  62. def kwinputs(self) -> dict[str, Any]: ...
  63. def device_type(self) -> DeviceType: ...
  64. def start_thread_id(self) -> int: ...
  65. def end_thread_id(self) -> int: ...
  66. def correlation_id(self) -> int: ...
  67. def fwd_thread_id(self) -> int: ...
  68. def stack(self) -> list[str]: ...
  69. def scope(self) -> int: ...
  70. def sequence_nr(self) -> int: ...
  71. def flops(self) -> int: ...
  72. def cuda_elapsed_us(self) -> int: ...
  73. def privateuse1_elapsed_us(self) -> int: ...
  74. def is_user_annotation(self) -> bool: ...
  75. def is_hidden_event(self) -> bool: ...
  76. class _ProfilerResult:
  77. def events(self) -> list[_KinetoEvent]: ...
  78. def legacy_events(self) -> list[list[ProfilerEvent]]: ...
  79. def save(self, path: str) -> None: ...
  80. def experimental_event_tree(self) -> list[_ProfilerEvent]: ...
  81. def trace_start_ns(self) -> int: ...
  82. class SavedTensor: ...
  83. def _enable_profiler(
  84. config: ProfilerConfig,
  85. activities: set[ProfilerActivity],
  86. ) -> None: ...
  87. def _prepare_profiler(
  88. config: ProfilerConfig,
  89. activities: set[ProfilerActivity],
  90. ) -> None: ...
  91. def _toggle_collection_dynamic(
  92. enable: bool,
  93. activities: set[ProfilerActivity],
  94. ) -> None: ...
  95. def _disable_profiler() -> _ProfilerResult: ...
  96. def _profiler_enabled() -> bool: ...
  97. def _add_metadata_json(key: str, value: str) -> None: ...
  98. def _kineto_step() -> None: ...
  99. def _get_current_graph_task_keep_graph() -> bool: ...
  100. def _get_sequence_nr() -> int: ...
  101. def kineto_available() -> bool: ...
  102. def _record_function_with_args_enter(name: str, *args) -> torch.Tensor: ...
  103. def _record_function_with_args_exit(handle: torch.Tensor) -> None: ...
  104. def _supported_activities() -> set[ProfilerActivity]: ...
  105. def _enable_record_function(enable: bool) -> None: ...
  106. def _set_empty_test_observer(is_global: bool, sampling_prob: float) -> None: ...
  107. def _push_saved_tensors_default_hooks(
  108. pack_hook: Callable[[torch.Tensor], Any],
  109. unpack_hook: Callable[[Any], torch.Tensor],
  110. ) -> None: ...
  111. def _pop_saved_tensors_default_hooks() -> None: ...
  112. def _top_saved_tensors_default_hooks(
  113. ignore_is_tracing: bool,
  114. ) -> tuple[Callable[[torch.Tensor], Any], Callable[[Any], torch.Tensor]]: ...
  115. def _unsafe_set_version_counter(
  116. t: tuple[torch.Tensor, ...], prev_version: tuple[int, ...]
  117. ) -> None: ...
  118. def _enable_profiler_legacy(config: ProfilerConfig) -> None: ...
  119. def _disable_profiler_legacy() -> list[list[ProfilerEvent]]: ...
  120. def _profiler_type() -> ActiveProfilerType: ...
  121. def _saved_tensors_hooks_enable() -> None: ...
  122. def _saved_tensors_hooks_disable(message: str, fail_if_non_empty=True) -> None: ...
  123. def _saved_tensors_hooks_get_disabled_error_message() -> str | None: ...
  124. def _saved_tensors_hooks_set_tracing(is_tracing: bool) -> bool: ...
  125. class CreationMeta(Enum):
  126. DEFAULT = ...
  127. IN_CUSTOM_FUNCTION = ...
  128. MULTI_OUTPUT_NODE = ...
  129. NO_GRAD_MODE = ...
  130. INFERENCE_MODE = ...
  131. def _set_creation_meta(t: torch.Tensor, creation_meta: CreationMeta) -> None: ...
  132. def _get_creation_meta(t: torch.Tensor) -> CreationMeta: ...