|
| 1 | +""" |
| 2 | +Script used to generate environment information for the purpose of |
| 3 | +creating bug reports. See `.github/ISSUE_TEMPLATE/bug_report.md` |
| 4 | +""" |
| 5 | + |
| 6 | +import platform |
| 7 | +import sys |
| 8 | +import importlib |
| 9 | + |
| 10 | +def get_version(pkg_name): |
| 11 | + try: |
| 12 | + return importlib.metadata.version(pkg_name) |
| 13 | + except importlib.metadata.PackageNotFoundError: |
| 14 | + return "None" |
| 15 | + |
| 16 | +def get_torch_hardware_info(): |
| 17 | + try: |
| 18 | + import torch |
| 19 | + cuda_devices = [] |
| 20 | + amd_devices = [] |
| 21 | + if torch.cuda.is_available(): |
| 22 | + for i in range(torch.cuda.device_count()): |
| 23 | + name = torch.cuda.get_device_name(i) |
| 24 | + if "AMD" in name.upper(): |
| 25 | + amd_devices.append(name) |
| 26 | + else: |
| 27 | + cuda_devices.append(name) |
| 28 | + return cuda_devices, amd_devices |
| 29 | + except ImportError: |
| 30 | + return [], [] |
| 31 | + |
| 32 | +def collect_environment_info(): |
| 33 | + cuda_devices, amd_devices = get_torch_hardware_info() |
| 34 | + |
| 35 | + info = { |
| 36 | + "Operating System": platform.platform(), |
| 37 | + "Python Version": sys.version.replace("\n", " "), |
| 38 | + "llm-compressor Version": get_version("llmcompressor"), |
| 39 | + "compressed-tensors Version": get_version("compressed_tensors"), |
| 40 | + "transformers Version": get_version("transformers"), |
| 41 | + "torch Version": get_version("torch"), |
| 42 | + "CUDA Devices": cuda_devices if cuda_devices else "None", |
| 43 | + "AMD Devices": amd_devices if amd_devices else "None", |
| 44 | + } |
| 45 | + |
| 46 | + print("### Environment Information ###") |
| 47 | + for key, value in info.items(): |
| 48 | + print(f"{key}: `{value}`") |
| 49 | + |
| 50 | +if __name__ == "__main__": |
| 51 | + collect_environment_info() |
0 commit comments