__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from typing import Callable, Optional, Union
  2. from loguru import logger
  3. import aphrodite.common.envs as envs
  4. def load_general_plugins():
  5. """WARNING: plugins can be loaded for multiple times in different
  6. processes. They should be designed in a way that they can be loaded
  7. multiple times without causing issues.
  8. """
  9. import sys
  10. if sys.version_info < (3, 10):
  11. from importlib_metadata import entry_points
  12. else:
  13. from importlib.metadata import entry_points
  14. allowed_plugins = envs.APHRODITE_PLUGINS
  15. discovered_plugins = entry_points(group='aphrodite.general_plugins')
  16. for plugin in discovered_plugins:
  17. logger.info(f"Found general plugin: {plugin.name}")
  18. if allowed_plugins is None or plugin.name in allowed_plugins:
  19. try:
  20. func = plugin.load()
  21. func()
  22. logger.info(f"Loaded general plugin: {plugin.name}")
  23. except Exception:
  24. logger.exception("Failed to load general plugin: "
  25. f"{plugin.name}")
  26. _torch_compile_backend: Optional[Union[Callable, str]] = None
  27. def set_torch_compile_backend(backend: Union[Callable, str]):
  28. global _torch_compile_backend
  29. _torch_compile_backend = backend
  30. def get_torch_compile_backend() -> Optional[Union[Callable, str]]:
  31. return _torch_compile_backend