





import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
      from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
      from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
      from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


lowerCAmelCase_						   =    DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

lowerCAmelCase_						   =    """main"""
# Default branch name
lowerCAmelCase_						   =    """f2c752cfc5c0ab6f4bdec59acea69eefbee381c2"""
# One particular commit (not the top of `main`)
lowerCAmelCase_						   =    """aaaaaaa"""
# This commit does not exist, so we should 404.

lowerCAmelCase_						   =    """d9e9f15bc825e4b2c9249e9578f884bbcb5e3684"""
# Sha-1 of config.json on the top of `main`, for checking purposes
lowerCAmelCase_						   =    """4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3"""


@contextlib.contextmanager
def     lowerCamelCase_	(      )->		int:
  print('Welcome!'				)
  yield
  print('Bye!'				)


@contextlib.contextmanager
def     lowerCamelCase_	(      )->		Optional[int]:
  print('Bonjour!'				)
  yield
  print('Au revoir!'				)



class        _lowerCAmelCase    (			unittest.TestCase							):


  '''simple docstring'''







  def UpperCamelCase_ (      self      :					int							):


    '''simple docstring'''





    assert transformers.__spec__ is not None
    assert importlib.util.find_spec('transformers'							) is not None




class        _lowerCAmelCase    (			unittest.TestCase							):


  '''simple docstring'''







  @unittest.mock.patch('sys.stdout'      ,				new_callable=io.StringIO							)
  def UpperCamelCase_ (      self      :					Tuple      ,				UpperCamelCase      :					List[Any]							):


    '''simple docstring'''





    with ContextManagers([]							):
      print('Transformers are awesome!'							)
    # The print statement adds a new line at the end of the output
    self.assertEqual(mock_stdout.getvalue()      ,				'Transformers are awesome!\n'							)







  @unittest.mock.patch('sys.stdout'      ,				new_callable=io.StringIO							)
  def UpperCamelCase_ (      self      :					str      ,				UpperCamelCase      :					Optional[Any]							):


    '''simple docstring'''





    with ContextManagers([context_en()]							):
      print('Transformers are awesome!'							)
    # The output should be wrapped with an English welcome and goodbye
    self.assertEqual(mock_stdout.getvalue()      ,				'Welcome!\nTransformers are awesome!\nBye!\n'							)







  @unittest.mock.patch('sys.stdout'      ,				new_callable=io.StringIO							)
  def UpperCamelCase_ (      self      :					List[Any]      ,				UpperCamelCase      :					str							):


    '''simple docstring'''





    with ContextManagers([context_fr(), context_en()]							):
      print('Transformers are awesome!'							)
    # The output should be wrapped with an English and French welcome and goodbye
    self.assertEqual(mock_stdout.getvalue()      ,				'Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n'							)







  @require_torch
  def UpperCamelCase_ (      self      :					Optional[int]							):


    '''simple docstring'''





    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels']							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels', 'next_sentence_label']							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				['start_positions', 'end_positions']							)



    class        _lowerCAmelCase    (			UpperCAmelCase_							):


      '''simple docstring'''
      pass




    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels']							)







  @require_tf
  def UpperCamelCase_ (      self      :					Optional[Any]							):


    '''simple docstring'''





    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels']							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels', 'next_sentence_label']							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				['start_positions', 'end_positions']							)



    class        _lowerCAmelCase    (			UpperCAmelCase_							):


      '''simple docstring'''
      pass




    self.assertEqual(find_labels(UpperCamelCase							)      ,				['labels']							)







  @require_flax
  def UpperCamelCase_ (      self      :					Any							):


    '''simple docstring'''





    self.assertEqual(find_labels(UpperCamelCase							)      ,				[]							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				[]							)
    self.assertEqual(find_labels(UpperCamelCase							)      ,				[]							)



    class        _lowerCAmelCase    (			UpperCAmelCase_							):


      '''simple docstring'''
      pass




    self.assertEqual(find_labels(UpperCamelCase							)      ,				[]							)











import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


lowerCAmelCase_						   =    {"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

lowerCAmelCase_						   =    {
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

lowerCAmelCase_						   =    {
    """unc-nlp/lxmert-base-uncased""": 512,
}

lowerCAmelCase_						   =    {
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}



class        _lowerCAmelCase    (			UpperCAmelCase_							):


  '''simple docstring'''
  a_							:       List[Any]      					=VOCAB_FILES_NAMES
  a_							:       Tuple      					=PRETRAINED_VOCAB_FILES_MAP
  a_							:       Optional[Any]      					=PRETRAINED_INIT_CONFIGURATION
  a_							:       Any      					=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  a_							:       Any      					=LxmertTokenizer







  def __init__(      self      :					Any      ,				UpperCamelCase      :					Union[str, Any]=None      ,				UpperCamelCase      :					Dict=None      ,				UpperCamelCase      :					List[str]=True      ,				UpperCamelCase      :					List[str]="[UNK]"      ,				UpperCamelCase      :					List[Any]="[SEP]"      ,				UpperCamelCase      :					List[Any]="[PAD]"      ,				UpperCamelCase      :					Optional[Any]="[CLS]"      ,				UpperCamelCase      :					Optional[int]="[MASK]"      ,				UpperCamelCase      :					Optional[int]=True      ,				UpperCamelCase      :					str=None      ,				**UpperCamelCase      :					List[str]      ,				):


    '''simple docstring'''





    super().__init__(
        UpperCamelCase      ,				tokenizer_file=UpperCamelCase      ,				do_lower_case=UpperCamelCase      ,				unk_token=UpperCamelCase      ,				sep_token=UpperCamelCase      ,				pad_token=UpperCamelCase      ,				cls_token=UpperCamelCase      ,				mask_token=UpperCamelCase      ,				tokenize_chinese_chars=UpperCamelCase      ,				strip_accents=UpperCamelCase      ,				**UpperCamelCase      ,				)

    _snake_case   :				Tuple														=	json.loads(self.backend_tokenizer.normalizer.__getstate__()							)
    if (
        normalizer_state.get('lowercase'      ,				UpperCamelCase							) != do_lower_case
        or normalizer_state.get('strip_accents'      ,				UpperCamelCase							) != strip_accents
        or normalizer_state.get('handle_chinese_chars'      ,				UpperCamelCase							) != tokenize_chinese_chars
    ):
      _snake_case   :				List[Any]														=	getattr(UpperCamelCase      ,				normalizer_state.pop('type'							)							)
      _snake_case   :				Optional[int]														=	do_lower_case
      _snake_case   :				Dict														=	strip_accents
      _snake_case   :				Optional[int]														=	tokenize_chinese_chars
      _snake_case   :				Optional[Any]														=	normalizer_class(**UpperCamelCase							)

    _snake_case   :				int														=	do_lower_case







  def UpperCamelCase_ (      self      :					int      ,				UpperCamelCase      :					List[str]      ,				UpperCamelCase      :					str=None							):


    '''simple docstring'''





    _snake_case   :				List[Any]														=	[self.cls_token_id] + token_ids_a + [self.sep_token_id]

    if token_ids_a:
      output += token_ids_a + [self.sep_token_id]

    return output







  def UpperCamelCase_ (      self      :					List[str]      ,				UpperCamelCase      :					List[int]      ,				UpperCamelCase      :					Optional[List[int]] = None							):


    '''simple docstring'''





    _snake_case   :				Tuple														=	[self.sep_token_id]
    _snake_case   :				List[str]														=	[self.cls_token_id]
    if token_ids_a is None:
      return len(cls + token_ids_a + sep							) * [0]
    return len(cls + token_ids_a + sep							) * [0] + len(token_ids_a + sep							) * [1]







  def UpperCamelCase_ (      self      :					int      ,				UpperCamelCase      :					str      ,				UpperCamelCase      :					Optional[str] = None							):


    '''simple docstring'''





    _snake_case   :				int														=	self._tokenizer.model.save(UpperCamelCase      ,				name=UpperCamelCase							)
    return tuple(UpperCamelCase							)




