





# 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.

from pathlib import Path

from .config_args import default_config_file, load_config_from_file
from .config_utils import SubcommandHelpFormatter


__A    :   int          =       "Update an existing config file with the latest defaults while maintaining the old configuration."





def 						__SCREAMING_SNAKE_CASE  (    UpperCamelCase__			)  ->    Optional[int]:







   '''simple docstring'''

   UpperCAmelCase       		=    args.config_file
   if config_file is None and Path(UpperCamelCase__			).exists():
      UpperCAmelCase       		=    default_config_file
   elif not Path(UpperCamelCase__			).exists():
      raise ValueError(F"""The passed config file located at {config_file} doesn't exist."""			)
   UpperCAmelCase       		=    load_config_from_file(UpperCamelCase__			)

   if config_file.endswith('''.json'''			):
      config.to_json_file(UpperCamelCase__			)
   else:
      config.to_yaml_file(UpperCamelCase__			)
   return config_file





def 						__SCREAMING_SNAKE_CASE  (    UpperCamelCase__      ,      UpperCamelCase__			)  ->    Dict:







   '''simple docstring'''

   UpperCAmelCase       		=    parser.add_parser('''update'''      ,      parents=UpperCamelCase__      ,      help=UpperCamelCase__      ,      formatter_class=UpperCamelCase__			)
   parser.add_argument(
       '''--config_file'''      ,      default=UpperCamelCase__      ,      help=(
           '''The path to the config file to update. 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\'.'''
       )      ,      )

   parser.set_defaults(func=UpperCamelCase__			)
   return parser






def 						__SCREAMING_SNAKE_CASE  (    UpperCamelCase__			)  ->    Any:







   '''simple docstring'''

   UpperCAmelCase       		=    update_config(UpperCamelCase__			)
   print(F"""Sucessfully updated the configuration file at {config_file}."""			)










import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


__A    :   Optional[int]          =       logging.get_logger(__name__)

class      A_	(a_      ):
	UpperCAmelCase__ =      '''speech-encoder-decoder'''
	UpperCAmelCase__ =      True
	def __init__(   self							, **_A		):






				'''simple docstring'''







				super().__init__(**_A		)
				if "encoder" not in kwargs or "decoder" not in kwargs:
							raise ValueError(
							    F"""A configuraton of type {self.model_type} cannot be instantiated because not both `encoder` and"""
							    F""" `decoder` sub-configurations are passed, but only {kwargs}"""		)

				UpperCAmelCase       		=    kwargs.pop('''encoder'''		)
				UpperCAmelCase       		=    encoder_config.pop('''model_type'''		)
				UpperCAmelCase       		=    kwargs.pop('''decoder'''		)
				UpperCAmelCase       		=    decoder_config.pop('''model_type'''		)

				UpperCAmelCase       		=    AutoConfig.for_model(_A							, **_A		)
				UpperCAmelCase       		=    AutoConfig.for_model(_A							, **_A		)
				UpperCAmelCase       		=    True
	@classmethod
	def 					_lowercase    (   cls							, _A							, _A							, **_A		):






				'''simple docstring'''







				logger.info('''Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config'''		)
				UpperCAmelCase       		=    True
				UpperCAmelCase       		=    True

				return cls(encoder=encoder_config.to_dict()							, decoder=decoder_config.to_dict()							, **_A		)







	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    copy.deepcopy(self.__dict__		)
				UpperCAmelCase       		=    self.encoder.to_dict()
				UpperCAmelCase       		=    self.decoder.to_dict()
				UpperCAmelCase       		=    self.__class__.model_type
				return output



