|
| 1 | +# Copyright 2022 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 | + |
| 15 | +import platform |
| 16 | +from argparse import ArgumentParser |
| 17 | + |
| 18 | +import huggingface_hub |
| 19 | + |
| 20 | +from .. import __version__ as version |
| 21 | +from ..utils import is_torch_available, is_transformers_available |
| 22 | +from . import BaseDiffusersCLICommand |
| 23 | + |
| 24 | + |
| 25 | +def info_command_factory(_): |
| 26 | + return EnvironmentCommand() |
| 27 | + |
| 28 | + |
| 29 | +class EnvironmentCommand(BaseDiffusersCLICommand): |
| 30 | + @staticmethod |
| 31 | + def register_subcommand(parser: ArgumentParser): |
| 32 | + download_parser = parser.add_parser("env") |
| 33 | + download_parser.set_defaults(func=info_command_factory) |
| 34 | + |
| 35 | + def run(self): |
| 36 | + hub_version = huggingface_hub.__version__ |
| 37 | + |
| 38 | + pt_version = "not installed" |
| 39 | + pt_cuda_available = "NA" |
| 40 | + if is_torch_available(): |
| 41 | + import torch |
| 42 | + |
| 43 | + pt_version = torch.__version__ |
| 44 | + pt_cuda_available = torch.cuda.is_available() |
| 45 | + |
| 46 | + transformers_version = "not installed" |
| 47 | + if is_transformers_available: |
| 48 | + import transformers |
| 49 | + |
| 50 | + transformers_version = transformers.__version__ |
| 51 | + |
| 52 | + info = { |
| 53 | + "`diffusers` version": version, |
| 54 | + "Platform": platform.platform(), |
| 55 | + "Python version": platform.python_version(), |
| 56 | + "PyTorch version (GPU?)": f"{pt_version} ({pt_cuda_available})", |
| 57 | + "Huggingface_hub version": hub_version, |
| 58 | + "Transformers version": transformers_version, |
| 59 | + "Using GPU in script?": "<fill in>", |
| 60 | + "Using distributed or parallel set-up in script?": "<fill in>", |
| 61 | + } |
| 62 | + |
| 63 | + print("\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n") |
| 64 | + print(self.format_dict(info)) |
| 65 | + |
| 66 | + return info |
| 67 | + |
| 68 | + @staticmethod |
| 69 | + def format_dict(d): |
| 70 | + return "\n".join([f"- {prop}: {val}" for prop, val in d.items()]) + "\n" |
0 commit comments