






'''simple docstring'''





import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available

def      __lowercase					( snake_case=None ):







				"""simple docstring"""






				if subparsers is not None:
								__magic_name__		:Any        =      subparsers.add_parser('''env''' )
				else:
								__magic_name__		:Optional[Any]        =      argparse.ArgumentParser('''Accelerate env command''' )

				parser.add_argument(
				    '''--config_file''',  default=__UpperCamelCase,  help='''The config file to use for the default values in the launching script.''' )

				if subparsers is not None:
								parser.set_defaults(func=__UpperCamelCase )
				return parser

def      __lowercase					( snake_case ):







				"""simple docstring"""






				__magic_name__		:int        =      torch.__version__
				__magic_name__		:Tuple        =      torch.cuda.is_available()
				__magic_name__		:int        =      is_xpu_available()
				__magic_name__		:List[Any]        =      is_npu_available()

				__magic_name__		:Tuple        =      '''Not found'''
				# Get the default from the config file.
				if args.config_file is not None or os.path.isfile(__UpperCamelCase ):
								__magic_name__		:Dict        =      load_config_from_file(args.config_file ).to_dict()

				__magic_name__		:Union[str, Any]        =      {
				    '''`Accelerate` version''': version,
				    '''Platform''': platform.platform(),
				    '''Python version''': platform.python_version(),
				    '''Numpy version''': np.__version__,
				    '''PyTorch version (GPU?)''': f'''{pt_version} ({pt_cuda_available})''',
				    '''PyTorch XPU available''': str(__UpperCamelCase ),
				    '''PyTorch NPU available''': str(__UpperCamelCase ),
				    '''System RAM''': f'''{psutil.virtual_memory().total / 1_0_2_4 ** 3:.2f} GB''',
				}
				if pt_cuda_available:
								__magic_name__		:List[str]        =      torch.cuda.get_device_name()

				print('''\nCopy-and-paste the text below in your GitHub issue\n''' )
				print('''\n'''.join([f'''- {prop}: {val}''' for prop, val in info.items()] ) )

				print('''- `Accelerate` default config:''' if args.config_file is None else '''- `Accelerate` config passed:''' )
				__magic_name__		:List[Any]        =      (
				    '''\n'''.join([f'''\t- {prop}: {val}''' for prop, val in accelerate_config.items()] )
				    if isinstance(__UpperCamelCase,  __UpperCamelCase )
				    else f'''\t{accelerate_config}'''
				)
				print(__UpperCamelCase )

				__magic_name__		:Any        =      accelerate_config

				return info

def      __lowercase					( ):







				"""simple docstring"""






				__magic_name__		:str        =      env_command_parser()
				__magic_name__		:Any        =      parser.parse_args()
				env_command(__UpperCamelCase )
				return 0


if __name__ == "__main__":
					raise SystemExit(main())














from typing import List

from .keymap import KEYMAP, get_character

def      __lowercase					( snake_case ):







				"""simple docstring"""






				def decorator(snake_case ):
								__magic_name__		:int        =      getattr(snake_case,  '''handle_key''',  [] )
								handle += [key]
								setattr(snake_case,  '''handle_key''',  snake_case )
								return func

				return decorator

def      __lowercase					( *snake_case ):







				"""simple docstring"""






				def decorator(snake_case ):
								__magic_name__		:Union[str, Any]        =      getattr(snake_case,  '''handle_key''',  [] )
								handle += keys
								setattr(snake_case,  '''handle_key''',  snake_case )
								return func

				return decorator
class 						lowerCamelCase_				(      lowerCamelCase ):







				def __new__(						cls       ,					__lowerCAmelCase       ,					__lowerCAmelCase       ,					__lowerCAmelCase     ):
								"""simple docstring"""
								__magic_name__		:Optional[int]        =      super().__new__(cls       ,					__lowerCAmelCase       ,					__lowerCAmelCase       ,					__lowerCAmelCase     )
								if not hasattr(__lowerCAmelCase       ,					'''key_handler'''     ):
												setattr(__lowerCAmelCase       ,					'''key_handler'''       ,					{}     )
								setattr(__lowerCAmelCase       ,					'''handle_input'''       ,					KeyHandler.handle_input     )

								for value in attrs.values():
												__magic_name__		:Dict        =      getattr(__lowerCAmelCase       ,					'''handle_key'''       ,					[]     )
												for key in handled_keys:
																__magic_name__		:List[Any]        =      value
								return new_cls







				@staticmethod
				def 			A	(						cls     ):
								"""simple docstring"""
								__magic_name__		:Tuple        =      get_character()
								if char != KEYMAP["undefined"]:
												__magic_name__		:Dict        =      ord(__lowerCAmelCase     )
								__magic_name__		:str        =      cls.key_handler.get(__lowerCAmelCase     )
								if handler:
												__magic_name__		:Optional[Any]        =      char
												return handler(cls     )
								else:
												return None







def      __lowercase					( cls ):







				"""simple docstring"""






				return KeyHandler(cls.__name__,  cls.__bases__,  cls.__dict__.copy() )






