|
| 1 | +# Copyright 2024 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 | +import platform |
| 15 | +import subprocess |
| 16 | +from typing import Dict, List, Optional |
| 17 | + |
| 18 | +import huggingface_hub |
| 19 | +from pkg_resources import get_distribution |
| 20 | +from transformers import __version__ as transformers_version |
| 21 | +from transformers.utils import is_torch_available |
| 22 | + |
| 23 | +from ..neuron.utils import is_neuron_available, is_neuronx_available |
| 24 | +from ..neuron.version import __sdk_version__ as neuron_sdk_version |
| 25 | +from ..neuron.version import __version__ as optimum_neuron_version |
| 26 | +from ..version import __version__ as optimum_version |
| 27 | +from . import BaseOptimumCLICommand, CommandInfo |
| 28 | + |
| 29 | + |
| 30 | +class EnvironmentCommand(BaseOptimumCLICommand): |
| 31 | + COMMAND = CommandInfo(name="env", help="Get information about the environment used.") |
| 32 | + |
| 33 | + @staticmethod |
| 34 | + def format_dict(d): |
| 35 | + return "\n".join([f"- {prop}: {val}" for prop, val in d.items()]) + "\n" |
| 36 | + |
| 37 | + @staticmethod |
| 38 | + def get_pip_pkgs_version(pkg_list: Optional[List], info: Dict): |
| 39 | + if pkg_list is not None: |
| 40 | + for pkg in pkg_list: |
| 41 | + try: |
| 42 | + num_version = get_distribution(pkg).version |
| 43 | + except Exception: |
| 44 | + num_version = "NA" |
| 45 | + info[f"`{pkg}` version"] = num_version |
| 46 | + |
| 47 | + @staticmethod |
| 48 | + def print_apt_pkgs(): |
| 49 | + info = subprocess.run("apt list --installed | grep aws-neuron", capture_output=True, shell=True) |
| 50 | + pkgs_list = info.stdout.decode().split("\n") |
| 51 | + for pkg in pkgs_list: |
| 52 | + print(pkg) |
| 53 | + |
| 54 | + def run(self): |
| 55 | + pt_version = "not installed" |
| 56 | + if is_torch_available(): |
| 57 | + import torch |
| 58 | + |
| 59 | + pt_version = torch.__version__ |
| 60 | + |
| 61 | + platform_info = { |
| 62 | + "Platform": platform.platform(), |
| 63 | + "Python version": platform.python_version(), |
| 64 | + } |
| 65 | + info = { |
| 66 | + "`optimum-neuron` version": optimum_neuron_version, |
| 67 | + "`neuron-sdk` version": neuron_sdk_version, |
| 68 | + "`optimum` version": optimum_version, |
| 69 | + "`transformers` version": transformers_version, |
| 70 | + "`huggingface_hub` version": huggingface_hub.__version__, |
| 71 | + "`torch` version": f"{pt_version}", |
| 72 | + } |
| 73 | + |
| 74 | + if is_neuron_available(): |
| 75 | + neuron_python_pkgs = ["dmlc-tvm", "neuron-cc", "torch-neuron"] |
| 76 | + elif is_neuronx_available(): |
| 77 | + neuron_python_pkgs = [ |
| 78 | + "aws-neuronx-runtime-discovery", |
| 79 | + "libneuronxla", |
| 80 | + "neuronx-cc", |
| 81 | + "neuronx-distributed", |
| 82 | + "neuronx-hwm", |
| 83 | + "torch-neuronx", |
| 84 | + "torch-xla", |
| 85 | + "transformers-neuronx", |
| 86 | + ] |
| 87 | + else: |
| 88 | + neuron_python_pkgs = None |
| 89 | + |
| 90 | + self.get_pip_pkgs_version(neuron_python_pkgs, info) |
| 91 | + |
| 92 | + print("\nCopy-and-paste the text below in your GitHub issue:\n") |
| 93 | + print("\nPlatform:\n") |
| 94 | + print(self.format_dict(platform_info)) |
| 95 | + print("\nPython packages:\n") |
| 96 | + print(self.format_dict(info)) |
| 97 | + print("\nNeuron Driver:\n") |
| 98 | + self.print_apt_pkgs() |
0 commit comments