



from typing import List, Optional, Union

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





class 		UpperCAmelCase						(						snake_case_				):
   SCREAMING_SNAKE_CASE__							=     ['''image_processor''', '''tokenizer''']
   SCREAMING_SNAKE_CASE__							=     '''BlipImageProcessor'''
   SCREAMING_SNAKE_CASE__							=     ('''BertTokenizer''', '''BertTokenizerFast''')





   def __init__(	self       ,     _lowerCAmelCase       ,     _lowerCAmelCase			):
         _lowerCAmelCase 			=  False
         super().__init__(_lowerCAmelCase       ,     _lowerCAmelCase			)
         _lowerCAmelCase 			=  self.image_processor





   def __call__(	self       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = True       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = 0       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = None       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = False       ,     _lowerCAmelCase = True       ,     _lowerCAmelCase = None       ,     **_lowerCAmelCase       ,     ):
         if images is None and text is None:
               raise ValueError('''You have to specify either images or text.'''			)

         # Get only text
         if images is None:
               _lowerCAmelCase 			=  self.tokenizer
               _lowerCAmelCase 			=  self.tokenizer(
                   text=_lowerCAmelCase       ,     add_special_tokens=_lowerCAmelCase       ,     padding=_lowerCAmelCase       ,     truncation=_lowerCAmelCase       ,     max_length=_lowerCAmelCase       ,     stride=_lowerCAmelCase       ,     pad_to_multiple_of=_lowerCAmelCase       ,     return_attention_mask=_lowerCAmelCase       ,     return_overflowing_tokens=_lowerCAmelCase       ,     return_special_tokens_mask=_lowerCAmelCase       ,     return_offsets_mapping=_lowerCAmelCase       ,     return_token_type_ids=_lowerCAmelCase       ,     return_length=_lowerCAmelCase       ,     verbose=_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase       ,     **_lowerCAmelCase       ,     )
               return text_encoding

         # add pixel_values
         _lowerCAmelCase 			=  self.image_processor(_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase			)

         if text is not None:
               _lowerCAmelCase 			=  self.tokenizer(
                   text=_lowerCAmelCase       ,     add_special_tokens=_lowerCAmelCase       ,     padding=_lowerCAmelCase       ,     truncation=_lowerCAmelCase       ,     max_length=_lowerCAmelCase       ,     stride=_lowerCAmelCase       ,     pad_to_multiple_of=_lowerCAmelCase       ,     return_attention_mask=_lowerCAmelCase       ,     return_overflowing_tokens=_lowerCAmelCase       ,     return_special_tokens_mask=_lowerCAmelCase       ,     return_offsets_mapping=_lowerCAmelCase       ,     return_token_type_ids=_lowerCAmelCase       ,     return_length=_lowerCAmelCase       ,     verbose=_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase       ,     **_lowerCAmelCase       ,     )
         else:
               _lowerCAmelCase 			=  None

         if text_encoding is not None:
               encoding_image_processor.update(_lowerCAmelCase			)

         return encoding_image_processor





   def 	__lowerCAmelCase							(	self       ,     *_lowerCAmelCase       ,     **_lowerCAmelCase			):
         return self.tokenizer.batch_decode(*_lowerCAmelCase       ,     **_lowerCAmelCase			)





   def 	__lowerCAmelCase							(	self       ,     *_lowerCAmelCase       ,     **_lowerCAmelCase			):
         return self.tokenizer.decode(*_lowerCAmelCase       ,     **_lowerCAmelCase			)





   @property
   def 	__lowerCAmelCase							(	self			):
         _lowerCAmelCase 			=  self.tokenizer.model_input_names
         _lowerCAmelCase 			=  self.image_processor.model_input_names
         return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)




import argparse

import torch

from ...utils import logging
from . import AlbertConfig, AlbertForPreTraining, load_tf_weights_in_albert


logging.set_verbosity_info()
def 							UpperCAmelCase__		(				_SCREAMING_SNAKE_CASE   :	Optional[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]     ,				_SCREAMING_SNAKE_CASE   :	List[Any]				)->Dict:
      # Initialise PyTorch model
      _lowerCAmelCase 			=  AlbertConfig.from_json_file(_SCREAMING_SNAKE_CASE				)
      print(f'''Building PyTorch model from configuration: {config}'''				)
      _lowerCAmelCase 			=  AlbertForPreTraining(_SCREAMING_SNAKE_CASE				)

      # Load weights from tf checkpoint
      load_tf_weights_in_albert(_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE     ,				_SCREAMING_SNAKE_CASE				)

      # Save pytorch-model
      print(f'''Save PyTorch model to {pytorch_dump_path}'''				)
      torch.save(model.state_dict()     ,				_SCREAMING_SNAKE_CASE				)


if __name__ == "__main__":
    UpperCAmelCase_									=							argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
    )
    parser.add_argument(
        "--albert_config_file",
        default=None,
        type=str,
        required=True,
        help=(
            "The config json file corresponding to the pre-trained ALBERT model. \n"
            "This specifies the model architecture."
        ),
    )
    parser.add_argument(
        "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
    )
    UpperCAmelCase_									=							parser.parse_args()
    convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.albert_config_file, args.pytorch_dump_path)