hooks.py 894 B

12345678910111213141516171819202122232425
  1. """Hook system for Dynamo's guard functionality.
  2. This module provides a way to register callback functions that are triggered during
  3. guard-related operations.
  4. The Hooks class manages two types of hook functions:
  5. - guard_export_fn: Called when guards need to be exported, taking a GuardsSet as input
  6. - guard_fail_fn: Called when a guard check fails, taking a GuardFail object as input
  7. These hooks enable customization of guard export and failure handling behaviors.
  8. """
  9. import dataclasses
  10. from collections.abc import Callable
  11. from typing import Optional
  12. from torch._guards import GuardsSet
  13. from .types import GuardFail, GuardFilterEntry
  14. @dataclasses.dataclass
  15. class Hooks:
  16. guard_export_fn: Optional[Callable[[GuardsSet], None]] = None
  17. guard_fail_fn: Optional[Callable[[GuardFail], None]] = None
  18. guard_filter_fn: Optional[Callable[[list[GuardFilterEntry]], list[bool]]] = None