(package_list, success_status=True)
| 63 | |
| 64 | |
| 65 | def check_packages(package_list, success_status=True): |
| 66 | def print_success(package, version=None): |
| 67 | if version: |
| 68 | print(f"\033[92m[SUCCESS]\033[0m {package} found (v{version})") |
| 69 | else: |
| 70 | print(f"\033[92m[SUCCESS]\033[0m {package} found") |
| 71 | |
| 72 | def print_error(message): |
| 73 | print(f"\033[91m[ERROR]\033[0m {message}") |
| 74 | |
| 75 | for package in package_list: |
| 76 | if isinstance(package, tuple): |
| 77 | found = False |
| 78 | for alt_package in package: |
| 79 | try: |
| 80 | module = importlib.import_module(alt_package) |
| 81 | version = getattr(module, "__version__", None) |
| 82 | print_success(alt_package, version) |
| 83 | found = True |
| 84 | break |
| 85 | except ImportError: |
| 86 | continue |
| 87 | if not found: |
| 88 | print_error(f"None of the alternative packages found: \033[93m{', '.join(package)}\033[0m") |
| 89 | success_status = False |
| 90 | elif package == "apex": |
| 91 | try: |
| 92 | module = importlib.import_module(package) |
| 93 | version = getattr(module, "__version__", None) |
| 94 | print_success(package, version) |
| 95 | try: |
| 96 | from apex import multi_tensor_apply # noqa: F401 |
| 97 | |
| 98 | print_success("apex.multi_tensor_apply") |
| 99 | except ImportError: |
| 100 | print_error("apex.multi_tensor_apply not found") |
| 101 | success_status = False |
| 102 | except ImportError: |
| 103 | print_error("apex not found") |
| 104 | success_status = False |
| 105 | elif package == "transformer_engine": |
| 106 | try: |
| 107 | module = importlib.import_module(package) |
| 108 | version = getattr(module, "__version__", None) |
| 109 | print_success(package, version) |
| 110 | try: |
| 111 | import transformer_engine.pytorch # noqa: F401 |
| 112 | |
| 113 | print_success("transformer_engine.pytorch") |
| 114 | except ImportError: |
| 115 | print_error("transformer_engine.pytorch not found") |
| 116 | success_status = False |
| 117 | except ImportError: |
| 118 | print_error("transformer_engine not found") |
| 119 | success_status = False |
| 120 | else: |
| 121 | try: |
| 122 | module = importlib.import_module(package) |
no test coverage detected