declare-lab/tango2
92
1# Copyright 2023 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 at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# 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 and13# limitations under the License.14 15import platform16from argparse import ArgumentParser17 18import huggingface_hub19 20from .. import __version__ as version21from ..utils import is_accelerate_available, is_torch_available, is_transformers_available, is_xformers_available22from . import BaseDiffusersCLICommand23 24 25def info_command_factory(_):26 return EnvironmentCommand()27 28 29class EnvironmentCommand(BaseDiffusersCLICommand):30 @staticmethod31 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 torch42 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 transformers49 50 transformers_version = transformers.__version__51 52 accelerate_version = "not installed"53 if is_accelerate_available():54 import accelerate55 56 accelerate_version = accelerate.__version__57 58 xformers_version = "not installed"59 if is_xformers_available():60 import xformers61 62 xformers_version = xformers.__version__63 64 info = {65 "`diffusers` version": version,66 "Platform": platform.platform(),67 "Python version": platform.python_version(),68 "PyTorch version (GPU?)": f"{pt_version} ({pt_cuda_available})",69 "Huggingface_hub version": hub_version,70 "Transformers version": transformers_version,71 "Accelerate version": accelerate_version,72 "xFormers version": xformers_version,73 "Using GPU in script?": "<fill in>",74 "Using distributed or parallel set-up in script?": "<fill in>",75 }76 77 print("\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n")78 print(self.format_dict(info))79 80 return info81 82 @staticmethod83 def format_dict(d):84 return "\n".join([f"- {prop}: {val}" for prop, val in d.items()]) + "\n"85 