





import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

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


if TYPE_CHECKING:
      from ... import PreTrainedTokenizerBase, TensorType

SCREAMING_SNAKE_CASE_						   =       logging.get_logger(__name__)

class 		UpperCamelCase__ (      lowerCAmelCase_   ):



     '''simple docstring'''

     __snake_case    :	Optional[int]			=			"vision-encoder-decoder"
     __snake_case    :	Union[str, Any]			=			True






     def __init__(							self						:    List[Any]						,**lowerCamelCase__						:    Dict       )     ->		Any:




           '''simple docstring'''


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

           SCREAMING_SNAKE_CASE		=						kwargs.pop("""encoder"""       )
           SCREAMING_SNAKE_CASE		=						encoder_config.pop("""model_type"""       )
           SCREAMING_SNAKE_CASE		=						kwargs.pop("""decoder"""       )
           SCREAMING_SNAKE_CASE		=						decoder_config.pop("""model_type"""       )

           SCREAMING_SNAKE_CASE		=						AutoConfig.for_model(lowerCamelCase__						,**lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						AutoConfig.for_model(lowerCamelCase__						,**lowerCamelCase__       )
           SCREAMING_SNAKE_CASE		=						True






     @classmethod
     def 				SCREAMING_SNAKE_CASE__  (							cls						:    Optional[Any]						,lowerCamelCase__						:    PretrainedConfig						,lowerCamelCase__						:    PretrainedConfig						,**lowerCamelCase__						:    Tuple       )     ->		PretrainedConfig:




           '''simple docstring'''


           logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""       )
           SCREAMING_SNAKE_CASE		=						True
           SCREAMING_SNAKE_CASE		=						True

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






     def 				SCREAMING_SNAKE_CASE__  (							self						:    str       )     ->		str:




           '''simple docstring'''


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

class 		UpperCamelCase__ (      lowerCAmelCase_   ):



     '''simple docstring'''

     __snake_case    :	Dict			=			version.parse("1.11"   )






     @property
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           return OrderedDict(
               [
                   ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
               ]       )






     @property
     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[Any]       )     ->		float:




           '''simple docstring'''


           return 1e-4






     @property
     def 				SCREAMING_SNAKE_CASE__  (							self						:    int       )     ->		Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           return OrderedDict({"""last_hidden_state""": {0: """batch""", 1: """encoder_sequence"""}}       )

class 		UpperCamelCase__ (      lowerCAmelCase_   ):



     '''simple docstring'''

     @property
     def 				SCREAMING_SNAKE_CASE__  (							self						:    Dict       )     ->		Mapping[str, Mapping[int, str]]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						OrderedDict()
           SCREAMING_SNAKE_CASE		=						{0: """batch""", 1: """past_decoder_sequence + sequence"""}
           SCREAMING_SNAKE_CASE		=						{0: """batch""", 1: """past_decoder_sequence + sequence"""}
           SCREAMING_SNAKE_CASE		=						{0: """batch""", 1: """encoder_sequence"""}

           return common_inputs






     def 				SCREAMING_SNAKE_CASE__  (							self						:    Tuple						,lowerCamelCase__						:    "PreTrainedTokenizerBase"						,lowerCamelCase__						:    int = -1						,lowerCamelCase__						:    int = -1						,lowerCamelCase__						:    bool = False						,lowerCamelCase__						:    Optional["TensorType"] = None						,)     ->		Mapping[str, Any]:




           '''simple docstring'''


           import torch

           SCREAMING_SNAKE_CASE		=						OrderedDict()

           SCREAMING_SNAKE_CASE		=						super().generate_dummy_inputs(
               lowerCamelCase__						,batch_size=lowerCamelCase__						,seq_length=lowerCamelCase__						,is_pair=lowerCamelCase__						,framework=lowerCamelCase__       )

           SCREAMING_SNAKE_CASE,					SCREAMING_SNAKE_CASE		=						dummy_input["""input_ids"""].shape
           SCREAMING_SNAKE_CASE		=						(batch, encoder_sequence, self._config.encoder_hidden_size)
           SCREAMING_SNAKE_CASE		=						dummy_input.pop("""input_ids"""       )
           SCREAMING_SNAKE_CASE		=						dummy_input.pop("""attention_mask"""       )
           SCREAMING_SNAKE_CASE		=						torch.zeros(lowerCamelCase__       )

           return common_inputs

class 		UpperCamelCase__ (      lowerCAmelCase_   ):



     '''simple docstring'''

     @property
     def 				SCREAMING_SNAKE_CASE__  (							self						:    List[Any]       )     ->		None:




           '''simple docstring'''


           pass






     def 				SCREAMING_SNAKE_CASE__  (							self						:    str						,lowerCamelCase__						:    PretrainedConfig       )     ->		OnnxConfig:




           '''simple docstring'''


           return VisionEncoderDecoderEncoderOnnxConfig(lowerCamelCase__       )






     def 				SCREAMING_SNAKE_CASE__  (							self						:    int						,lowerCamelCase__						:    PretrainedConfig						,lowerCamelCase__						:    PretrainedConfig						,lowerCamelCase__						:    str = "default"       )     ->		OnnxConfig:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						encoder_config.hidden_size
           return VisionEncoderDecoderDecoderOnnxConfig(lowerCamelCase__						,lowerCamelCase__       )









import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


SCREAMING_SNAKE_CASE_						   =       importlib.util.find_spec("""s3fs""") is not None

if _has_safs:
      from .safilesystem import SaFileSystem  # noqa: F401

SCREAMING_SNAKE_CASE_						   =       [
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
      if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
            warnings.warn(F'''A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.''')
      fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)



def    __lowercase   (      _SCREAMING_SNAKE_CASE	) ->   str:


      '''simple docstring'''


      if "://" in dataset_path:
            SCREAMING_SNAKE_CASE		=						dataset_path.split("""://"""	)[1]
      return dataset_path



def    __lowercase   (      _SCREAMING_SNAKE_CASE	) ->   bool:


      '''simple docstring'''


      if fs is not None and fs.protocol != "file":
            return True
      else:
            return False



def    __lowercase   (      _SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE	) ->   Dict:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						not is_remote_filesystem(_SCREAMING_SNAKE_CASE	)
      if is_local:
            # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
            shutil.move(fs._strip_protocol(_SCREAMING_SNAKE_CASE	) ,						fs._strip_protocol(_SCREAMING_SNAKE_CASE	)	)
      else:
            fs.mv(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						recursive=_SCREAMING_SNAKE_CASE	)



def    __lowercase   (      ) ->   None:


      '''simple docstring'''


      if hasattr(fsspec.asyn ,						"""reset_lock"""	):
            # for future fsspec>2022.05.0
            fsspec.asyn.reset_lock()
      else:
            SCREAMING_SNAKE_CASE		=						None
            SCREAMING_SNAKE_CASE		=						None
            SCREAMING_SNAKE_CASE		=						threading.Lock()


