__init__.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # mypy: allow-untyped-defs
  2. r"""
  3. PyTorch Profiler is a tool that allows the collection of performance metrics during training and inference.
  4. Profiler's context manager API can be used to better understand what model operators are the most expensive,
  5. examine their input shapes and stack traces, study device kernel activity and visualize the execution trace.
  6. .. note::
  7. An earlier version of the API in :mod:`torch.autograd` module is considered legacy and will be deprecated.
  8. """
  9. import os
  10. from torch._C._autograd import _supported_activities, DeviceType, kineto_available
  11. from torch._C._profiler import _ExperimentalConfig, ProfilerActivity, RecordScope
  12. from torch.autograd.profiler import KinetoStepTracker, record_function
  13. from torch.optim.optimizer import register_optimizer_step_post_hook
  14. from .profiler import (
  15. _KinetoProfile,
  16. ExecutionTraceObserver,
  17. profile,
  18. ProfilerAction,
  19. schedule,
  20. supported_activities,
  21. tensorboard_trace_handler,
  22. )
  23. __all__ = [
  24. "profile",
  25. "schedule",
  26. "supported_activities",
  27. "tensorboard_trace_handler",
  28. "ProfilerAction",
  29. "ProfilerActivity",
  30. "kineto_available",
  31. "DeviceType",
  32. "record_function",
  33. "ExecutionTraceObserver",
  34. ]
  35. from . import itt
  36. def _optimizer_post_hook(optimizer, args, kwargs):
  37. KinetoStepTracker.increment_step("Optimizer")
  38. if os.environ.get("KINETO_USE_DAEMON", None):
  39. _ = register_optimizer_step_post_hook(_optimizer_post_hook)