dependency_versions_check.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. "requests",
  26. "packaging",
  27. "filelock",
  28. "numpy",
  29. "tokenizers",
  30. "huggingface-hub",
  31. "safetensors",
  32. "accelerate",
  33. "pyyaml",
  34. ]
  35. for pkg in pkgs_to_check_at_runtime:
  36. if pkg in deps:
  37. if pkg == "tokenizers":
  38. # must be loaded here, or else tqdm check may fail
  39. from .utils import is_tokenizers_available
  40. if not is_tokenizers_available():
  41. continue # not required, check version only if installed
  42. elif pkg == "accelerate":
  43. # must be loaded here, or else tqdm check may fail
  44. from .utils import is_accelerate_available
  45. # Maybe switch to is_torch_available in the future here so that Accelerate is hard dep of
  46. # Transformers with PyTorch
  47. if not is_accelerate_available():
  48. continue # not required, check version only if installed
  49. require_version_core(deps[pkg])
  50. else:
  51. raise ValueError(f"can't find {pkg} in {deps.keys()}, check dependency_versions_table.py")
  52. def dep_version_check(pkg, hint=None):
  53. require_version(deps[pkg], hint)