hooks.py 867 B

123456789101112131415161718192021222324
  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 typing import Callable, Optional
  11. from torch._guards import GuardsSet
  12. from .types import GuardFail, GuardFilterEntry
  13. @dataclasses.dataclass
  14. class Hooks:
  15. guard_export_fn: Optional[Callable[[GuardsSet], None]] = None
  16. guard_fail_fn: Optional[Callable[[GuardFail], None]] = None
  17. guard_filter_fn: Optional[Callable[[list[GuardFilterEntry]], list[bool]]] = None