
import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          BioGptForCausalLM,
          BioGptForSequenceClassification,
          BioGptForTokenClassification,
          BioGptModel,
          BioGptTokenizer,
      )
      from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST



class 		UpperCamelCase__  :
   def __init__(self			: Optional[Any] ,    snake_case_			: Tuple ,    snake_case_			: Optional[int]=1_3 ,    snake_case_			: str=7 ,    snake_case_			: Union[str, Any]=True ,    snake_case_			: str=True ,    snake_case_			: Optional[Any]=False ,    snake_case_			: int=True ,    snake_case_			: List[str]=9_9 ,    snake_case_			: Union[str, Any]=3_2 ,    snake_case_			: Any=5 ,    snake_case_			: int=4 ,    snake_case_			: List[str]=3_7 ,    snake_case_			: Optional[Any]="gelu" ,    snake_case_			: Any=0.1 ,    snake_case_			: Any=0.1 ,    snake_case_			: Tuple=5_1_2 ,    snake_case_			: Any=1_6 ,    snake_case_			: int=2 ,    snake_case_			: List[str]=0.02 ,    snake_case_			: Dict=3 ,    snake_case_			: Optional[int]=4 ,    snake_case_			: List[Any]=None ,    ):
    __a			:  Optional[Any]		    =  parent
    __a			:  List[Any]		    =  batch_size
    __a			:  int		    =  seq_length
    __a			:  Any		    =  is_training
    __a			:  List[Any]		    =  use_input_mask
    __a			:  List[str]		    =  use_token_type_ids
    __a			:  Any		    =  use_labels
    __a			:  Optional[Any]		    =  vocab_size
    __a			:  Optional[Any]		    =  hidden_size
    __a			:  Any		    =  num_hidden_layers
    __a			:  List[Any]		    =  num_attention_heads
    __a			:  str		    =  intermediate_size
    __a			:  str		    =  hidden_act
    __a			:  Dict		    =  hidden_dropout_prob
    __a			:  List[str]		    =  attention_probs_dropout_prob
    __a			:  Any		    =  max_position_embeddings
    __a			:  Optional[Any]		    =  type_vocab_size
    __a			:  Tuple		    =  type_sequence_label_size
    __a			:  int		    =  initializer_range
    __a			:  List[str]		    =  num_labels
    __a			:  Optional[Any]		    =  num_choices
    __a			:  Dict		    =  scope
   def 				lowerCAmelCase      (self			: Dict       ):
    __a			:  Union[str, Any]		    =  ids_tensor([self.batch_size, self.seq_length] ,    self.vocab_size       )

    __a			:  Union[str, Any]		    =  None
    if self.use_input_mask:
     __a			:  Tuple		    =  random_attention_mask([self.batch_size, self.seq_length]       )

    __a			:  Optional[Any]		    =  None
    if self.use_token_type_ids:
     __a			:  Optional[Any]		    =  ids_tensor([self.batch_size, self.seq_length] ,    self.type_vocab_size       )

    __a			:  Dict		    =  None
    __a			:  int		    =  None
    __a			:  List[Any]		    =  None
    if self.use_labels:
     __a			:  Any		    =  ids_tensor([self.batch_size] ,    self.type_sequence_label_size       )
     __a			:  str		    =  ids_tensor([self.batch_size, self.seq_length] ,    self.num_labels       )
     __a			:  Optional[Any]		    =  ids_tensor([self.batch_size] ,    self.num_choices       )

    __a			:  Optional[int]		    =  self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def 				lowerCAmelCase      (self			: Union[str, Any]       ):
    return BioGptConfig(
        vocab_size=self.vocab_size ,    hidden_size=self.hidden_size ,    num_hidden_layers=self.num_hidden_layers ,    num_attention_heads=self.num_attention_heads ,    intermediate_size=self.intermediate_size ,    hidden_act=self.hidden_act ,    hidden_dropout_prob=self.hidden_dropout_prob ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob ,    max_position_embeddings=self.max_position_embeddings ,    type_vocab_size=self.type_vocab_size ,    is_decoder=snake_case_ ,    initializer_range=self.initializer_range ,    )
   def 				lowerCAmelCase      (self			: Any ,    snake_case_			: Optional[int] ,    snake_case_			: Dict ,    snake_case_			: int ,    snake_case_			: Union[str, Any] ,    snake_case_			: str ,    snake_case_			: List[str] ,    snake_case_			: Union[str, Any]       ):
    __a			:  Optional[Any]		    =  BioGptModel(config=snake_case_       )
    model.to(snake_case_       )
    model.eval()
    __a			:  Any		    =  model(snake_case_ ,    attention_mask=snake_case_       )
    __a			:  int		    =  model(snake_case_       )
    self.parent.assertEqual(result.last_hidden_state.shape ,    (self.batch_size, self.seq_length, self.hidden_size)       )
   def 				lowerCAmelCase      (self			: Optional[int] ,    snake_case_			: Optional[int] ,    snake_case_			: Dict ,    snake_case_			: List[Any] ,    snake_case_			: Optional[Any] ,    snake_case_			: str ,    snake_case_			: Dict ,    snake_case_			: Union[str, Any] ,    snake_case_			: int ,    snake_case_			: Optional[int] ,    ):
    __a			:  int		    =  BioGptForCausalLM(config=snake_case_       )
    model.to(snake_case_       )
    model.eval()
    __a			:  Tuple		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    token_type_ids=snake_case_ ,    labels=snake_case_       )
    self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.vocab_size)       )
   def 				lowerCAmelCase      (self			: List[Any] ,    snake_case_			: Optional[int] ,    snake_case_			: Optional[int] ,    snake_case_			: Optional[int] ,    snake_case_			: List[str] ,    snake_case_			: Dict ,    *snake_case_			: Union[str, Any]       ):
    __a			:  int		    =  BioGptModel(config=snake_case_       )
    model.to(snake_case_       )
    model.eval()

    # create attention mask
    __a			:  Union[str, Any]		    =  torch.ones(input_ids.shape ,    dtype=torch.long ,    device=snake_case_       )
    __a			:  List[str]		    =  self.seq_length // 2
    __a			:  List[Any]		    =  0

    # first forward pass
    __a    ,	__a			:  Optional[Any]		    =  model(snake_case_ ,    attention_mask=snake_case_       ).to_tuple()

    # create hypothetical next token and extent to next_input_ids
    __a			:  Optional[Any]		    =  ids_tensor((self.batch_size, 1) ,    config.vocab_size       )

    # change a random masked slice from input_ids
    __a			:  Optional[Any]		    =  ids_tensor((1,) ,    snake_case_       ).item() + 1
    __a			:  Tuple		    =  ids_tensor((self.batch_size, 1) ,    config.vocab_size       ).squeeze(-1       )
    __a			:  Dict		    =  random_other_next_tokens

    # append to next input_ids and attn_mask
    __a			:  Union[str, Any]		    =  torch.cat([input_ids, next_tokens] ,    dim=-1       )
    __a			:  Tuple		    =  torch.cat(
        [attn_mask, torch.ones((attn_mask.shape[0], 1) ,    dtype=torch.long ,    device=snake_case_       )] ,    dim=1 ,    )

    # get two different outputs
    __a			:  Dict		    =  model(snake_case_ ,    attention_mask=snake_case_       )['''last_hidden_state''']
    __a			:  Union[str, Any]		    =  model(snake_case_ ,    past_key_values=snake_case_ ,    attention_mask=snake_case_       )['''last_hidden_state''']

    # select random slice
    __a			:  List[Any]		    =  ids_tensor((1,) ,    output_from_past.shape[-1]       ).item()
    __a			:  Optional[int]		    =  output_from_no_past[:, -1, random_slice_idx].detach()
    __a			:  Union[str, Any]		    =  output_from_past[:, 0, random_slice_idx].detach()

    # test that outputs are equal for slice
    self.parent.assertTrue(torch.allclose(snake_case_ ,    snake_case_ ,    atol=1E-3       )       )
   def 				lowerCAmelCase      (self			: Tuple ,    snake_case_			: List[str] ,    snake_case_			: List[Any] ,    snake_case_			: Union[str, Any] ,    snake_case_			: Optional[Any] ,    snake_case_			: Any ,    *snake_case_			: Dict       ):
    __a			:  List[Any]		    =  BioGptModel(config=snake_case_       ).to(snake_case_       ).eval()

    __a			:  List[str]		    =  torch.ones(input_ids.shape ,    dtype=torch.long ,    device=snake_case_       )

    # first forward pass
    __a			:  Optional[Any]		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    use_cache=snake_case_       )

    __a    ,	__a			:  List[Any]		    =  outputs.to_tuple()

    # create hypothetical multiple next token and extent to next_input_ids
    __a			:  Tuple		    =  ids_tensor((self.batch_size, 3) ,    config.vocab_size       )
    __a			:  List[Any]		    =  ids_tensor((self.batch_size, 3) ,    2       )

    # append to next input_ids and
    __a			:  List[Any]		    =  torch.cat([input_ids, next_tokens] ,    dim=-1       )
    __a			:  Union[str, Any]		    =  torch.cat([attention_mask, next_attn_mask] ,    dim=-1       )

    __a			:  Any		    =  model(snake_case_ ,    attention_mask=snake_case_       )['''last_hidden_state''']
    __a			:  Dict		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    past_key_values=snake_case_       )[
        '''last_hidden_state'''
    ]

    # select random slice
    __a			:  List[Any]		    =  ids_tensor((1,) ,    output_from_past.shape[-1]       ).item()
    __a			:  Tuple		    =  output_from_no_past[:, -3:, random_slice_idx].detach()
    __a			:  Union[str, Any]		    =  output_from_past[:, :, random_slice_idx].detach()

    self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]       )

    # test that outputs are equal for slice
    self.parent.assertTrue(torch.allclose(snake_case_ ,    snake_case_ ,    atol=1E-3       )       )
   def 				lowerCAmelCase      (self			: Union[str, Any] ,    snake_case_			: Any ,    snake_case_			: int ,    snake_case_			: Dict ,    snake_case_			: Any ,    snake_case_			: Optional[Any] ,    *snake_case_			: str ,    snake_case_			: Optional[Any]=False       ):
    __a			:  Any		    =  BioGptForCausalLM(snake_case_       )
    model.to(snake_case_       )
    if gradient_checkpointing:
     model.gradient_checkpointing_enable()

    __a			:  Optional[int]		    =  model(snake_case_ ,    labels=snake_case_       )
    self.parent.assertEqual(result.loss.shape ,    ()       )
    self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.vocab_size)       )
    result.loss.backward()
   def 				lowerCAmelCase      (self			: Dict ,    snake_case_			: int ,    *snake_case_			: Any       ):
    __a			:  Optional[int]		    =  BioGptModel(snake_case_       )
    __a			:  str		    =  model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers       )
    for key in model.state_dict().keys():
     if "c_proj" in key and "weight" in key:
      self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]       ) - model_std       ) ,    0.001       )
      self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]       ) - 0.0       ) ,    0.01       )
   def 				lowerCAmelCase      (self			: Tuple ,    snake_case_			: int ,    snake_case_			: Union[str, Any] ,    snake_case_			: Tuple ,    snake_case_			: Any ,    snake_case_			: Union[str, Any] ,    *snake_case_			: Optional[int]       ):
    __a			:  str		    =  self.num_labels
    __a			:  List[str]		    =  BioGptForTokenClassification(snake_case_       )
    model.to(snake_case_       )
    model.eval()
    __a			:  str		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    token_type_ids=snake_case_       )
    self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.seq_length, self.num_labels)       )







   def 				lowerCAmelCase      (self			: int       ):
    __a			:  List[Any]		    =  self.prepare_config_and_inputs()
    (
        (
        __a
    )    ,	(
        __a
    )    ,	(
        __a
    )    ,	(
        __a
    )    ,	(
        __a
    )    ,	(
        __a
    )    ,	(
        __a
    )    ,	
    )			:  int		    =  config_and_inputs
    __a			:  Dict		    =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    return config, inputs_dict





@require_torch
class 		UpperCamelCase__  (	__lowercase   ,__lowercase   ,__lowercase   ,unittest.TestCase   ):
   _SCREAMING_SNAKE_CASE				:							Tuple     	=				(
       (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
       if is_torch_available()
       else ()
   )
   _SCREAMING_SNAKE_CASE				:							List[Any]     	=				(BioGptForCausalLM,) if is_torch_available() else ()
   _SCREAMING_SNAKE_CASE				:							List[str]     	=				(
       {
           "feature-extraction": BioGptModel,
           "text-classification": BioGptForSequenceClassification,
           "text-generation": BioGptForCausalLM,
           "token-classification": BioGptForTokenClassification,
           "zero-shot": BioGptForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   _SCREAMING_SNAKE_CASE				:							Dict     	=				False
   def 				lowerCAmelCase      (self			: List[str]       ):
    __a			:  int		    =  BioGptModelTester(self       )
    __a			:  Dict		    =  ConfigTester(self ,    config_class=snake_case_ ,    hidden_size=3_7       )
   def 				lowerCAmelCase      (self			: Optional[int]       ):
    self.config_tester.run_common_tests()
   def 				lowerCAmelCase      (self			: Any       ):
    __a			:  int		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*snake_case_       )
   def 				lowerCAmelCase      (self			: Tuple       ):
    __a			:  Union[str, Any]		    =  self.model_tester.prepare_config_and_inputs()
    for type in ["absolute", "relative_key", "relative_key_query"]:
     __a			:  str		    =  type
     self.model_tester.create_and_check_model(*snake_case_       )
   def 				lowerCAmelCase      (self			: List[str]       ):
    __a			:  str		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_biogpt_model_attention_mask_past(*snake_case_       )
   def 				lowerCAmelCase      (self			: Any       ):
    __a			:  str		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_forward_and_backwards(*snake_case_ ,    gradient_checkpointing=snake_case_       )
   def 				lowerCAmelCase      (self			: Dict       ):
    __a			:  Any		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_biogpt_model_past_large_inputs(*snake_case_       )
   def 				lowerCAmelCase      (self			: Union[str, Any]       ):
    __a			:  Optional[Any]		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_biogpt_weight_initialization(*snake_case_       )
   def 				lowerCAmelCase      (self			: int       ):
    __a			:  Optional[int]		    =  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_biogpt_for_token_classification(*snake_case_       )
   @slow
   def 				lowerCAmelCase      (self			: int       ):
    __a			:  List[str]		    =  BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''       )
    model.to(snake_case_       )
    __a			:  Dict		    =  BioGptTokenizer.from_pretrained('''microsoft/biogpt'''       )

    __a			:  str		    =  '''left'''

    # Define PAD Token = EOS Token = 50256
    __a			:  List[Any]		    =  tokenizer.eos_token
    __a			:  Dict		    =  model.config.eos_token_id

    # use different length sentences to test batching
    __a			:  Optional[int]		    =  [
        '''Hello, my dog is a little''',
        '''Today, I''',
    ]

    __a			:  Union[str, Any]		    =  tokenizer(snake_case_ ,    return_tensors='''pt''' ,    padding=snake_case_       )
    __a			:  List[str]		    =  inputs['''input_ids'''].to(snake_case_       )

    __a			:  List[Any]		    =  model.generate(
        input_ids=snake_case_ ,    attention_mask=inputs['''attention_mask'''].to(snake_case_       ) ,    )

    __a			:  List[str]		    =  tokenizer(sentences[0] ,    return_tensors='''pt'''       ).input_ids.to(snake_case_       )
    __a			:  Optional[Any]		    =  model.generate(input_ids=snake_case_       )

    __a			:  int		    =  inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].long().sum().cpu().item()
    __a			:  int		    =  tokenizer(sentences[1] ,    return_tensors='''pt'''       ).input_ids.to(snake_case_       )
    __a			:  str		    =  model.generate(input_ids=snake_case_ ,    max_length=model.config.max_length - num_paddings       )

    __a			:  str		    =  tokenizer.batch_decode(snake_case_ ,    skip_special_tokens=snake_case_       )
    __a			:  List[str]		    =  tokenizer.decode(output_non_padded[0] ,    skip_special_tokens=snake_case_       )
    __a			:  Union[str, Any]		    =  tokenizer.decode(output_padded[0] ,    skip_special_tokens=snake_case_       )

    __a			:  Optional[int]		    =  [
        '''Hello, my dog is a little bit bigger than a little bit.''',
        '''Today, I have a good idea of how to use the information''',
    ]
    self.assertListEqual(snake_case_ ,    snake_case_       )
    self.assertListEqual(snake_case_ ,    [non_padded_sentence, padded_sentence]       )
   @slow
   def 				lowerCAmelCase      (self			: Tuple       ):
    for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     __a			:  List[Any]		    =  BioGptModel.from_pretrained(snake_case_       )
     self.assertIsNotNone(snake_case_       )
   def 				lowerCAmelCase      (self			: Tuple       ):
    __a    ,	__a			:  Dict		    =  self.model_tester.prepare_config_and_inputs_for_common()
    __a			:  List[Any]		    =  3
    __a			:  List[Any]		    =  input_dict['''input_ids''']
    __a			:  Any		    =  input_ids.ne(1       ).to(snake_case_       )
    __a			:  int		    =  ids_tensor([self.model_tester.batch_size] ,    self.model_tester.type_sequence_label_size       )
    __a			:  Optional[int]		    =  BioGptForSequenceClassification(snake_case_       )
    model.to(snake_case_       )
    model.eval()
    __a			:  Dict		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    labels=snake_case_       )
    self.assertEqual(result.logits.shape ,    (self.model_tester.batch_size, self.model_tester.num_labels)       )







   def 				lowerCAmelCase      (self			: Any       ):
    __a    ,	__a			:  str		    =  self.model_tester.prepare_config_and_inputs_for_common()
    __a			:  Tuple		    =  3
    __a			:  str		    =  '''multi_label_classification'''
    __a			:  Dict		    =  input_dict['''input_ids''']
    __a			:  Dict		    =  input_ids.ne(1       ).to(snake_case_       )
    __a			:  Optional[Any]		    =  ids_tensor(
        [self.model_tester.batch_size, config.num_labels] ,    self.model_tester.type_sequence_label_size       ).to(torch.float       )
    __a			:  Dict		    =  BioGptForSequenceClassification(snake_case_       )
    model.to(snake_case_       )
    model.eval()
    __a			:  List[str]		    =  model(snake_case_ ,    attention_mask=snake_case_ ,    labels=snake_case_       )
    self.assertEqual(result.logits.shape ,    (self.model_tester.batch_size, self.model_tester.num_labels)       )





@require_torch
class 		UpperCamelCase__  (	unittest.TestCase   ):
   @slow
   def 				lowerCAmelCase      (self			: Dict       ):
    __a			:  Tuple		    =  BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''       )
    __a			:  Tuple		    =  torch.tensor([[2, 4_8_0_5, 9, 6_5_6, 2_1]]       )
    __a			:  Optional[Any]		    =  model(snake_case_       )[0]

    __a			:  Dict		    =  4_2_3_8_4

    __a			:  Optional[Any]		    =  torch.Size((1, 5, vocab_size)       )
    self.assertEqual(output.shape ,    snake_case_       )

    __a			:  Any		    =  torch.tensor(
        [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]]       )

    self.assertTrue(torch.allclose(output[:, :3, :3] ,    snake_case_ ,    atol=1E-4       )       )







   @slow
   def 				lowerCAmelCase      (self			: Union[str, Any]       ):
    __a			:  List[Any]		    =  BioGptTokenizer.from_pretrained('''microsoft/biogpt'''       )
    __a			:  int		    =  BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''       )
    model.to(snake_case_       )

    torch.manual_seed(0       )
    __a			:  Tuple		    =  tokenizer('''COVID-19 is''' ,    return_tensors='''pt'''       ).to(snake_case_       )
    __a			:  Optional[int]		    =  model.generate(
        **snake_case_ ,    min_length=1_0_0 ,    max_length=1_0_2_4 ,    num_beams=5 ,    early_stopping=snake_case_ ,    )
    __a			:  Union[str, Any]		    =  tokenizer.decode(output_ids[0] ,    skip_special_tokens=snake_case_       )

    __a			:  Any		    =  (
        '''COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'''
        ''' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'''
        ''' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'''
        ''' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'''
        ''' more than 800,000 deaths.'''
    )
    self.assertEqual(snake_case_ ,    snake_case_       )


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


lowercase__          ={
    'configuration_layoutlmv2': ['LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LayoutLMv2Config'],
    'processing_layoutlmv2': ['LayoutLMv2Processor'],
    'tokenization_layoutlmv2': ['LayoutLMv2Tokenizer'],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =['LayoutLMv2TokenizerFast']

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =['LayoutLMv2FeatureExtractor']
      lowercase__          =['LayoutLMv2ImageProcessor']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =[
          'LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST',
          'LayoutLMv2ForQuestionAnswering',
          'LayoutLMv2ForSequenceClassification',
          'LayoutLMv2ForTokenClassification',
          'LayoutLMv2Layer',
          'LayoutLMv2Model',
          'LayoutLMv2PreTrainedModel',
      ]

if TYPE_CHECKING:
      from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
      from .processing_layoutlmva import LayoutLMvaProcessor
      from .tokenization_layoutlmva import LayoutLMvaTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_layoutlmva import (
                LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
                LayoutLMvaForQuestionAnswering,
                LayoutLMvaForSequenceClassification,
                LayoutLMvaForTokenClassification,
                LayoutLMvaLayer,
                LayoutLMvaModel,
                LayoutLMvaPreTrainedModel,
            )
else:
      import sys

      lowercase__          =_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
