
"""simple docstring"""






# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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 __magic_name__	(				_lowerCamelCase:		str=None			)					->						int:

	'''simple docstring'''




	if subparsers is not None:
		lowerCAmelCase												=  subparsers.add_parser('''env'''			)
	else:
		lowerCAmelCase												=  argparse.ArgumentParser('''Accelerate env command'''			)

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

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




def __magic_name__	(				_lowerCamelCase:		int			)					->						List[Any]:

	'''simple docstring'''




	lowerCAmelCase												=  torch.__version__
	lowerCAmelCase												=  torch.cuda.is_available()
	lowerCAmelCase												=  is_xpu_available()
	lowerCAmelCase												=  is_npu_available()

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

	lowerCAmelCase												=  {
	    '''`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(_lowerCamelCase			),
	    '''PyTorch NPU available''': str(_lowerCamelCase			),
	    '''System RAM''': F"""{psutil.virtual_memory().total / 1_024 ** 3:.2f} GB""",
	}
	if pt_cuda_available:
		lowerCAmelCase												=  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:'''			)
	lowerCAmelCase												=  (
	    '''\n'''.join([F"""\t- {prop}: {val}""" for prop, val in accelerate_config.items()]			)
	    if isinstance(_lowerCamelCase,					_lowerCamelCase			)
	    else F"""\t{accelerate_config}"""
	)
	print(_lowerCamelCase			)

	lowerCAmelCase												=  accelerate_config

	return info




def __magic_name__	(				)					->						int:

	'''simple docstring'''




	lowerCAmelCase												=  env_command_parser()
	lowerCAmelCase												=  parser.parse_args()
	env_command(_lowerCamelCase			)
	return 0


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




"""simple docstring"""






import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding



class 			lowercase					( lowercase__		):
			lowercase        =     ['''image_processor''', '''tokenizer''']
			lowercase        =     '''CLIPImageProcessor'''
			lowercase        =     ('''XLMRobertaTokenizer''', '''XLMRobertaTokenizerFast''')






			def __init__(self  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	int=None      ,SCREAMING_SNAKE_CASE_  :	str=None      ,**SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  None
				if "feature_extractor" in kwargs:
					warnings.warn(
					    '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
					    ''' instead.'''      ,SCREAMING_SNAKE_CASE_      ,)
					lowerCAmelCase												=  kwargs.pop('''feature_extractor'''			)

				lowerCAmelCase												=  image_processor if image_processor is not None else feature_extractor
				if image_processor is None:
					raise ValueError('''You need to specify an `image_processor`.'''			)
				if tokenizer is None:
					raise ValueError('''You need to specify a `tokenizer`.'''			)

				super().__init__(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)






			def __call__(self  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	List[str]=None      ,SCREAMING_SNAKE_CASE_  :	Optional[int]=None      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=None      ,**SCREAMING_SNAKE_CASE_  :	Any			)       ->	List[Any]:





				"""simple docstring"""


				if text is None and images is None:
					raise ValueError('''You have to specify either text or images. Both cannot be none.'''			)

				if text is not None:
					lowerCAmelCase												=  self.tokenizer(SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)

				if images is not None:
					lowerCAmelCase												=  self.image_processor(SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)

				if text is not None and images is not None:
					lowerCAmelCase												=  image_features.pixel_values
					return encoding
				elif text is not None:
					return encoding
				else:
					return BatchEncoding(data=dict(**SCREAMING_SNAKE_CASE_			)      ,tensor_type=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[str]      ,*SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,**SCREAMING_SNAKE_CASE_  :	Tuple			)       ->	Optional[Any]:





				"""simple docstring"""


				return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Union[str, Any]      ,*SCREAMING_SNAKE_CASE_  :	int      ,**SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	Any:





				"""simple docstring"""


				return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			@property
			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  self.tokenizer.model_input_names
				lowerCAmelCase												=  self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)


