hook-triton.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # ------------------------------------------------------------------
  2. # Copyright (c) 2023 PyInstaller Development Team.
  3. #
  4. # This file is distributed under the terms of the GNU General Public
  5. # License (version 2.0 or later).
  6. #
  7. # The full license is available in LICENSE, distributed with
  8. # this software.
  9. #
  10. # SPDX-License-Identifier: GPL-2.0-or-later
  11. # ---------------------------------------------------
  12. from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs, collect_submodules, is_module_satisfies
  13. hiddenimports = []
  14. datas = []
  15. # Ensure that triton/_C/libtriton.so is collected
  16. binaries = collect_dynamic_libs('triton')
  17. # triton has a JIT module that requires its source .py files. For some god-forsaken reason, this JIT module
  18. # (`triton.runtime.jit` attempts to directly read the contents of file pointed to by its `__file__` attribute (assuming
  19. # it is a source file). Therefore, `triton.runtime.jit` must not be collected into PYZ. Same goes for `compiler` and
  20. # `language` sub-packages.
  21. module_collection_mode = {
  22. 'triton': 'pyz+py',
  23. 'triton.runtime.jit': 'py',
  24. 'triton.compiler': 'py',
  25. 'triton.language': 'py',
  26. }
  27. # triton 3.0.0 introduced `triton.backends` sub-package with backend-specific files.
  28. if is_module_satisfies('triton >= 3.0.0'):
  29. # Collect backend sub-modules/packages.
  30. hiddenimports += collect_submodules('triton.backends')
  31. # At the time of writing (triton v3.1.0), `triton.backends.amd` is a namespace package, and is not captured by the
  32. # above `collect_submodules` call.
  33. hiddenimports += collect_submodules('triton.backends.amd')
  34. # Collect ptxas compiler files from `triton/backends/nvidia`, and the HIP/ROCm files from `triton/backends/amd`.
  35. datas += collect_data_files('triton.backends')
  36. else:
  37. # Collect ptxas compiler files from triton/third_party/cuda directory. Strictly speaking, the ptxas executable from
  38. # bin directory should be collected as a binary, but in this case, it makes no difference (plus, PyInstaller >= 6.0
  39. # has automatic binary-vs-data reclassification).
  40. datas += collect_data_files('triton.third_party.cuda')