



# Copyright 2021 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

from accelerate.utils import ComputeEnvironment

from .cluster import get_cluster_input
from .config_args import cache_dir, default_config_file, default_yaml_config_file, load_config_from_file  # noqa: F401
from .config_utils import _ask_field, _ask_options, _convert_compute_environment  # noqa: F401
from .sagemaker import get_sagemaker_input


SCREAMING_SNAKE_CASE__       =      '''Launches a series of prompts to create and save a `default_config.yaml` configuration file for your training system. Should always be ran first on your machine'''


def A						(       )						->      Optional[Any]:
			A__       =    _ask_options(
			    'In which compute environment are you running?' ,	['This machine', 'AWS (Amazon SageMaker)'] ,	_convert_compute_environment ,	)
			if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
						A__       =    get_sagemaker_input()
			else:
						A__       =    get_cluster_input()
			return config


def A						(       __UpperCamelCase=None					)						->      Dict:
			if subparsers is not None:
						A__       =    subparsers.add_parser('config' ,	description=__UpperCamelCase					)
			else:
						A__       =    argparse.ArgumentParser('Accelerate config command' ,	description=__UpperCamelCase					)

			parser.add_argument(
			    '--config_file' ,	default=__UpperCamelCase ,	help=(
			        'The path to use to store the config file. Will default to a file named default_config.yaml in the cache '
			        'location, which is the content of the environment `HF_HOME` suffixed with \'accelerate\', or if you don\'t have '
			        'such an environment variable, your cache directory (\'~/.cache\' or the content of `XDG_CACHE_HOME`) suffixed '
			        'with \'huggingface\'.'
			    ) ,	)

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


def A						(       __UpperCamelCase					)						->      str:
			A__       =    get_user_input()
			if args.config_file is not None:
						A__       =    args.config_file
			else:
						if not os.path.isdir(__UpperCamelCase					):
									os.makedirs(__UpperCamelCase					)
						A__       =    default_yaml_config_file

			if config_file.endswith('.json'					):
						config.to_json_file(__UpperCamelCase					)
			else:
						config.to_yaml_file(__UpperCamelCase					)
			print(f'''accelerate configuration saved at {config_file}'''					)


def A						(       )						->      List[str]:
			A__       =    config_command_parser()
			A__       =    parser.parse_args()
			config_command(__UpperCamelCase					)


if __name__ == "__main__":
							main()









from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType


class      __lowerCAmelCase     (		UpperCAmelCase_      ):
					"""simple docstring"""






					A__				:		Union[str, Any]			       =    ["image_processor", "tokenizer"]
					A__				:		Optional[Any]			       =    "BridgeTowerImageProcessor"
					A__				:		List[Any]			       =    ("RobertaTokenizer", "RobertaTokenizerFast")



					def __init__(     self					:       List[Any]				,					_snake_case					:       Optional[Any]				,					_snake_case					:       Optional[int]					):






								"""simple docstring"""


								super().__init__(_snake_case				,					_snake_case					)



					def __call__(     self					:       List[Any]				,					_snake_case					:       int				,					_snake_case					:       Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None				,					_snake_case					:       bool = True				,					_snake_case					:       Union[bool, str, PaddingStrategy] = False				,					_snake_case					:       Union[bool, str, TruncationStrategy] = None				,					_snake_case					:       Optional[int] = None				,					_snake_case					:       int = 0				,					_snake_case					:       Optional[int] = None				,					_snake_case					:       Optional[bool] = None				,					_snake_case					:       Optional[bool] = None				,					_snake_case					:       bool = False				,					_snake_case					:       bool = False				,					_snake_case					:       bool = False				,					_snake_case					:       bool = False				,					_snake_case					:       bool = True				,					_snake_case					:       Optional[Union[str, TensorType]] = None				,					**_snake_case					:       Optional[int]				,					):






								"""simple docstring"""


								A__       =    self.tokenizer(
								    text=_snake_case				,					add_special_tokens=_snake_case				,					padding=_snake_case				,					truncation=_snake_case				,					max_length=_snake_case				,					stride=_snake_case				,					pad_to_multiple_of=_snake_case				,					return_token_type_ids=_snake_case				,					return_attention_mask=_snake_case				,					return_overflowing_tokens=_snake_case				,					return_special_tokens_mask=_snake_case				,					return_offsets_mapping=_snake_case				,					return_length=_snake_case				,					verbose=_snake_case				,					return_tensors=_snake_case				,					**_snake_case				,					)
								# add pixel_values + pixel_mask
								A__       =    self.image_processor(
								    _snake_case				,					return_tensors=_snake_case				,					do_normalize=_snake_case				,					do_center_crop=_snake_case				,					**_snake_case					)
								encoding.update(_snake_case					)

								return encoding



					def     _a							(     self					:       Any				,					*_snake_case					:       Tuple				,					**_snake_case					:       List[Any]					):






								"""simple docstring"""


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



					def     _a							(     self					:       Dict				,					*_snake_case					:       Dict				,					**_snake_case					:       List[str]					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       Tuple					):






								"""simple docstring"""


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




