dependency_versions_check.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright 2020 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from .dependency_versions_table import deps
  15. from .utils.versions import require_version, require_version_core
  16. # define which module versions we always want to check at run time
  17. # (usually the ones defined in `install_requires` in setup.py)
  18. #
  19. # order specific notes:
  20. # - tqdm must be checked before tokenizers
  21. pkgs_to_check_at_runtime = [
  22. "python",
  23. "tqdm",
  24. "regex",
  25. "packaging",
  26. "filelock",
  27. "numpy",
  28. "tokenizers",
  29. "huggingface-hub",
  30. "safetensors",
  31. "accelerate",
  32. "pyyaml",
  33. ]
  34. for pkg in pkgs_to_check_at_runtime:
  35. if pkg in deps:
  36. if pkg == "tokenizers":
  37. # must be loaded here, or else tqdm check may fail
  38. from .utils import is_tokenizers_available
  39. if not is_tokenizers_available():
  40. continue # not required, check version only if installed
  41. elif pkg == "accelerate":
  42. # must be loaded here, or else tqdm check may fail
  43. from .utils import is_accelerate_available
  44. # Maybe switch to is_torch_available in the future here so that Accelerate is hard dep of
  45. # Transformers with PyTorch
  46. if not is_accelerate_available():
  47. continue # not required, check version only if installed
  48. require_version_core(deps[pkg])
  49. else:
  50. raise ValueError(f"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")
  51. def dep_version_check(pkg, hint=None):
  52. require_version(deps[pkg], hint)