





'''simple docstring'''







import os
import re
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


snake_case_     :       List[Any]						=  logging.get_logger(__name__)

snake_case_     :       List[str]						=  {"vocab_file": "spiece.model"}

snake_case_     :       Union[str, Any]						=  {
    "vocab_file": {
        "google/bigbird-roberta-base": "https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model",
        "google/bigbird-roberta-large": (
            "https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model"
        ),
        "google/bigbird-base-trivia-itc": (
            "https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model"
        ),
    }
}

snake_case_     :       Any						=  {
    "google/bigbird-roberta-base": 40_96,
    "google/bigbird-roberta-large": 40_96,
    "google/bigbird-base-trivia-itc": 40_96,
}


class 					__a      (__a     ):
       __a					:   int									=       VOCAB_FILES_NAMES
       __a					:   Any									=       PRETRAINED_VOCAB_FILES_MAP
       __a					:   Dict									=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __a					:   int									=       ["input_ids", "attention_mask"]
       __a					:   List[int]									=       []

       def __init__(							self							:     List[str]       ,     __magic_name__							:     int       ,     __magic_name__							:     List[Any]="<unk>"       ,     __magic_name__							:     int="<s>"       ,     __magic_name__							:     Union[str, Any]="</s>"       ,     __magic_name__							:     Any="<pad>"       ,     __magic_name__							:     Any="[SEP]"       ,     __magic_name__							:     Any="[MASK]"       ,     __magic_name__							:     Any="[CLS]"       ,     __magic_name__							:     Any = None       ,     **__magic_name__							:     str       ,     )					->       None:







             """simple docstring"""
             UpperCAmelCase_			:      List[Any]     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else bos_token
             UpperCAmelCase_			:      List[str]     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else eos_token
             UpperCAmelCase_			:      int     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else unk_token
             UpperCAmelCase_			:      str     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else pad_token
             UpperCAmelCase_			:      int     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else cls_token
             UpperCAmelCase_			:      str     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else sep_token

             # Mask token behave like a normal word, i.e. include the space before it
             UpperCAmelCase_			:      str     						=  AddedToken(lowerCAmelCase_       ,     lstrip=lowerCAmelCase_       ,     rstrip=lowerCAmelCase_   ) if isinstance(lowerCAmelCase_       ,     lowerCAmelCase_   ) else mask_token

             UpperCAmelCase_			:      Union[str, Any]     						=  {} if sp_model_kwargs is None else sp_model_kwargs

             super().__init__(
                 bos_token=lowerCAmelCase_       ,     eos_token=lowerCAmelCase_       ,     unk_token=lowerCAmelCase_       ,     pad_token=lowerCAmelCase_       ,     sep_token=lowerCAmelCase_       ,     mask_token=lowerCAmelCase_       ,     cls_token=lowerCAmelCase_       ,     sp_model_kwargs=self.sp_model_kwargs       ,     **lowerCAmelCase_       ,     )

             UpperCAmelCase_			:      Any     						=  vocab_file

             UpperCAmelCase_			:      Any     						=  spm.SentencePieceProcessor(**self.sp_model_kwargs   )
             self.sp_model.Load(lowerCAmelCase_   )

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







             """simple docstring"""
             return self.sp_model.get_piece_size()

       def     UpperCAmelCase__	(							self							:     str   )					->       Optional[Any]:







             """simple docstring"""
             UpperCAmelCase_			:      Optional[int]     						=  {self.convert_ids_to_tokens(lowerCAmelCase_   ): i for i in range(self.vocab_size   )}
             vocab.update(self.added_tokens_encoder   )
             return vocab

       def __getstate__(							self							:     Optional[Any]   )					->       Optional[Any]:







             """simple docstring"""
             UpperCAmelCase_			:      Optional[int]     						=  self.__dict__.copy()
             UpperCAmelCase_			:      Dict     						=  None
             return state

       def __setstate__(							self							:     Any       ,     __magic_name__							:     Tuple   )					->       List[Any]:







             """simple docstring"""
             UpperCAmelCase_			:      int     						=  d

             # for backward compatibility
             if not hasattr(self       ,     '''sp_model_kwargs'''   ):
                   UpperCAmelCase_			:      int     						=  {}

             UpperCAmelCase_			:      List[Any]     						=  spm.SentencePieceProcessor(**self.sp_model_kwargs   )
             self.sp_model.Load(self.vocab_file   )

       def     UpperCAmelCase__	(							self							:     Tuple       ,     __magic_name__							:     Any   )					->       List[str]:







             """simple docstring"""
             return self.sp_model.encode(lowerCAmelCase_       ,     out_type=lowerCAmelCase_   )

       def     UpperCAmelCase__	(							self							:     Union[str, Any]       ,     __magic_name__							:     str   )					->       Any:







             """simple docstring"""
             return self.sp_model.piece_to_id(lowerCAmelCase_   )

       def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     List[Any]   )					->       Optional[Any]:







             """simple docstring"""
             UpperCAmelCase_			:      Optional[Any]     						=  self.sp_model.IdToPiece(lowerCAmelCase_   )
             return token

       def     UpperCAmelCase__	(							self							:     Union[str, Any]       ,     __magic_name__							:     int   )					->       Union[str, Any]:







             """simple docstring"""
             UpperCAmelCase_			:      Union[str, Any]     						=  []
             UpperCAmelCase_			:      Union[str, Any]     						=  ''''''
             UpperCAmelCase_			:      Optional[Any]     						=  False
             for token in tokens:
                   # make sure that special tokens are not decoded using sentencepiece model
                   if token in self.all_special_tokens:
                         if not prev_is_special:
                               out_string += " "
                         out_string += self.sp_model.decode(lowerCAmelCase_   ) + token
                         UpperCAmelCase_			:      str     						=  True
                         UpperCAmelCase_			:      Tuple     						=  []
                   else:
                         current_sub_tokens.append(lowerCAmelCase_   )
                         UpperCAmelCase_			:      Any     						=  False
             out_string += self.sp_model.decode(lowerCAmelCase_   )
             return out_string.strip()

       def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     Union[str, Any]       ,     __magic_name__							:     Optional[Any] = False       ,     __magic_name__							:     List[Any] = None       ,     __magic_name__							:     Any = True       ,     **__magic_name__							:     str       ,     )					->       str:







             """simple docstring"""
             UpperCAmelCase_			:      int     						=  kwargs.pop('''use_source_tokenizer'''       ,     lowerCAmelCase_   )

             UpperCAmelCase_			:      List[Any]     						=  self.convert_ids_to_tokens(lowerCAmelCase_       ,     skip_special_tokens=lowerCAmelCase_   )

             # To avoid mixing byte-level and unicode for byte-level BPT
             # we need to build string separately for added tokens and byte-level tokens
             # cf. https://github.com/huggingface/transformers/issues/1133
             UpperCAmelCase_			:      Optional[Any]     						=  []
             UpperCAmelCase_			:      str     						=  []
             for token in filtered_tokens:
                   if skip_special_tokens and token in self.all_special_ids:
                         continue
                   if token in self.added_tokens_encoder:
                         if current_sub_text:
                               sub_texts.append(self.convert_tokens_to_string(lowerCAmelCase_   )   )
                               UpperCAmelCase_			:      List[Any]     						=  []
                         sub_texts.append(lowerCAmelCase_   )
                   else:
                         current_sub_text.append(lowerCAmelCase_   )
             if current_sub_text:
                   sub_texts.append(self.convert_tokens_to_string(lowerCAmelCase_   )   )

             # Mimic the behavior of the Rust tokenizer:
             # No space before [MASK] and [SEP]
             if spaces_between_special_tokens:
                   UpperCAmelCase_			:      Tuple     						=  re.sub(R''' (\[(MASK|SEP)\])'''       ,     R'''\1'''       ,     ''' '''.join(lowerCAmelCase_   )   )
             else:
                   UpperCAmelCase_			:      Dict     						=  ''''''.join(lowerCAmelCase_   )

             UpperCAmelCase_			:      str     						=  (
                 clean_up_tokenization_spaces
                 if clean_up_tokenization_spaces is not None
                 else self.clean_up_tokenization_spaces
             )
             if clean_up_tokenization_spaces:
                   UpperCAmelCase_			:      Optional[Any]     						=  self.clean_up_tokenization(lowerCAmelCase_   )
                   return clean_text
             else:
                   return text

       def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Tuple = None   )					->       Tuple[str]:







             """simple docstring"""







             if not os.path.isdir(lowerCAmelCase_   ):
                   logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""   )
                   return
             UpperCAmelCase_			:      int     						=  os.path.join(
                 lowerCAmelCase_       ,     (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']   )

             if os.path.abspath(self.vocab_file   ) != os.path.abspath(lowerCAmelCase_   ) and os.path.isfile(self.vocab_file   ):
                   copyfile(self.vocab_file       ,     lowerCAmelCase_   )
             elif not os.path.isfile(self.vocab_file   ):
                   with open(lowerCAmelCase_       ,     '''wb'''   ) as fi:
                         UpperCAmelCase_			:      str     						=  self.sp_model.serialized_model_proto()
                         fi.write(lowerCAmelCase_   )

             return (out_vocab_file,)

       def     UpperCAmelCase__	(							self							:     Optional[int]       ,     __magic_name__							:     int       ,     __magic_name__							:     Union[str, Any] = None   )					->       List[int]:







             """simple docstring"""







             if token_ids_a is None:
                   return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
             UpperCAmelCase_			:      Any     						=  [self.cls_token_id]
             UpperCAmelCase_			:      Optional[int]     						=  [self.sep_token_id]
             return cls + token_ids_a + sep + token_ids_a + sep

       def     UpperCAmelCase__	(							self							:     Any       ,     __magic_name__							:     List[Any]       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Union[str, Any] = False   )					->       List[int]:







             """simple docstring"""







             if already_has_special_tokens:
                   return super().get_special_tokens_mask(
                       token_ids_a=lowerCAmelCase_       ,     token_ids_a=lowerCAmelCase_       ,     already_has_special_tokens=lowerCAmelCase_   )

             if token_ids_a is None:
                   return [1] + ([0] * len(lowerCAmelCase_   )) + [1]
             return [1] + ([0] * len(lowerCAmelCase_   )) + [1] + ([0] * len(lowerCAmelCase_   )) + [1]



       def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Tuple = None   )					->       List[int]:







             """simple docstring"""
             UpperCAmelCase_			:      Any     						=  [self.sep_token_id]
             UpperCAmelCase_			:      Optional[int]     						=  [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]












'''simple docstring'''







import unittest

from transformers import LiltConfig, 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    LiltForQuestionAnswering,
					    LiltForSequenceClassification,
					    LiltForTokenClassification,
					    LiltModel,
					)
					from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST


class 					__a      :

							def __init__(							self							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     Any=13       ,     __magic_name__							:     Any=7       ,     __magic_name__							:     Union[str, Any]=True       ,     __magic_name__							:     Union[str, Any]=True       ,     __magic_name__							:     str=True       ,     __magic_name__							:     Optional[int]=True       ,     __magic_name__							:     List[Any]=99       ,     __magic_name__							:     int=24       ,     __magic_name__							:     Optional[int]=2       ,     __magic_name__							:     Tuple=6       ,     __magic_name__							:     Union[str, Any]=37       ,     __magic_name__							:     Optional[Any]="gelu"       ,     __magic_name__							:     Any=0.1       ,     __magic_name__							:     str=0.1       ,     __magic_name__							:     Tuple=5_12       ,     __magic_name__							:     Union[str, Any]=16       ,     __magic_name__							:     Tuple=2       ,     __magic_name__							:     Tuple=0.0_2       ,     __magic_name__							:     Optional[Any]=3       ,     __magic_name__							:     Optional[int]=None       ,     __magic_name__							:     Any=10_00       ,     )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  parent
													UpperCAmelCase_			:      Optional[int]     						=  batch_size
													UpperCAmelCase_			:      List[str]     						=  seq_length
													UpperCAmelCase_			:      Dict     						=  is_training
													UpperCAmelCase_			:      List[str]     						=  use_input_mask
													UpperCAmelCase_			:      Any     						=  use_token_type_ids
													UpperCAmelCase_			:      Any     						=  use_labels
													UpperCAmelCase_			:      Any     						=  vocab_size
													UpperCAmelCase_			:      Dict     						=  hidden_size
													UpperCAmelCase_			:      Tuple     						=  num_hidden_layers
													UpperCAmelCase_			:      Tuple     						=  num_attention_heads
													UpperCAmelCase_			:      int     						=  intermediate_size
													UpperCAmelCase_			:      Union[str, Any]     						=  hidden_act
													UpperCAmelCase_			:      Optional[int]     						=  hidden_dropout_prob
													UpperCAmelCase_			:      Optional[Any]     						=  attention_probs_dropout_prob
													UpperCAmelCase_			:      Union[str, Any]     						=  max_position_embeddings
													UpperCAmelCase_			:      int     						=  type_vocab_size
													UpperCAmelCase_			:      List[Any]     						=  type_sequence_label_size
													UpperCAmelCase_			:      int     						=  initializer_range
													UpperCAmelCase_			:      Dict     						=  num_labels
													UpperCAmelCase_			:      List[str]     						=  scope
													UpperCAmelCase_			:      List[str]     						=  range_bbox

							def     UpperCAmelCase__	(							self							:     Optional[int]   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[int]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size   )

													UpperCAmelCase_			:      List[str]     						=  ids_tensor([self.batch_size, self.seq_length, 4]       ,     self.range_bbox   )
													# Ensure that bbox is legal
													for i in range(bbox.shape[0]   ):
																			for j in range(bbox.shape[1]   ):
																									if bbox[i, j, 3] < bbox[i, j, 1]:
																															UpperCAmelCase_			:      List[str]     						=  bbox[i, j, 3]
																															UpperCAmelCase_			:      Dict     						=  bbox[i, j, 1]
																															UpperCAmelCase_			:      Optional[Any]     						=  t
																									if bbox[i, j, 2] < bbox[i, j, 0]:
																															UpperCAmelCase_			:      List[str]     						=  bbox[i, j, 2]
																															UpperCAmelCase_			:      Tuple     						=  bbox[i, j, 0]
																															UpperCAmelCase_			:      Union[str, Any]     						=  t

													UpperCAmelCase_			:      int     						=  None
													if self.use_input_mask:
																			UpperCAmelCase_			:      Optional[int]     						=  ids_tensor([self.batch_size, self.seq_length]       ,     vocab_size=2   )

													UpperCAmelCase_			:      Optional[int]     						=  None
													if self.use_token_type_ids:
																			UpperCAmelCase_			:      str     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size   )

													UpperCAmelCase_			:      Dict     						=  None
													UpperCAmelCase_			:      Tuple     						=  None
													if self.use_labels:
																			UpperCAmelCase_			:      Any     						=  ids_tensor([self.batch_size]       ,     self.type_sequence_label_size   )
																			UpperCAmelCase_			:      Dict     						=  ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels   )

													UpperCAmelCase_			:      int     						=  self.get_config()

													return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels

							def     UpperCAmelCase__	(							self							:     Any   )					->       List[Any]:







													"""simple docstring"""
													return LiltConfig(
													    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       ,     initializer_range=self.initializer_range       ,     )

							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int       ,     )					->       Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  LiltModel(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      Optional[Any]     						=  model(__magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      List[Any]     						=  model(__magic_name__       ,     bbox=__magic_name__       ,     token_type_ids=__magic_name__   )
													UpperCAmelCase_			:      Optional[int]     						=  model(__magic_name__       ,     bbox=__magic_name__   )

													self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)   )
													self.parent.assertEqual(result.pooler_output.shape       ,     (self.batch_size, self.hidden_size)   )

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     List[str]       ,     __magic_name__							:     Any       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     List[Any]       ,     )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.num_labels
													UpperCAmelCase_			:      List[Any]     						=  LiltForTokenClassification(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      List[Any]     						=  model(
													    __magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__       ,     labels=__magic_name__   )
													self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels)   )

							def     UpperCAmelCase__	(							self							:     Any       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     Any       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     int       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     Any       ,     )					->       Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  LiltForQuestionAnswering(config=__magic_name__   )
													model.to(__magic_name__   )
													model.eval()
													UpperCAmelCase_			:      Optional[Any]     						=  model(
													    __magic_name__       ,     bbox=__magic_name__       ,     attention_mask=__magic_name__       ,     token_type_ids=__magic_name__       ,     start_positions=__magic_name__       ,     end_positions=__magic_name__       ,     )
													self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length)   )
													self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length)   )



							def     UpperCAmelCase__	(							self							:     List[Any]   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  self.prepare_config_and_inputs()
													(
													    (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       (
													    UpperCAmelCase_
													)						,       
													)			:      Optional[int]     						=  config_and_inputs
													UpperCAmelCase_			:      Tuple     						=  {
													    '''input_ids''': input_ids,
													    '''bbox''': bbox,
													    '''token_type_ids''': token_type_ids,
													    '''attention_mask''': input_mask,
													}
													return config, inputs_dict





@require_torch
class 					__a      (lowerCamelCase       ,		lowerCamelCase       ,		lowerCamelCase       ,		unittest.TestCase     ):
							__a					:   Tuple									=       (
							    (
							        LiltModel,
							        LiltForSequenceClassification,
							        LiltForTokenClassification,
							        LiltForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							__a					:   Any									=       (
							    {
							        "feature-extraction": LiltModel,
							        "question-answering": LiltForQuestionAnswering,
							        "text-classification": LiltForSequenceClassification,
							        "token-classification": LiltForTokenClassification,
							        "zero-shot": LiltForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							__a					:   Union[str, Any]									=       False
							__a					:   int									=       False

							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Dict       ,     __magic_name__							:     List[Any]       ,     __magic_name__							:     Optional[int]       ,     __magic_name__							:     Optional[Any]       ,     __magic_name__							:     int   )					->       str:







													"""simple docstring"""
													return True

							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[Any]     						=  LiltModelTester(self   )
													UpperCAmelCase_			:      List[Any]     						=  ConfigTester(self       ,     config_class=__magic_name__       ,     hidden_size=37   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       str:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def     UpperCAmelCase__	(							self							:     str   )					->       Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_model(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     str   )					->       str:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs()
													for type in ["absolute", "relative_key", "relative_key_query"]:
																			UpperCAmelCase_			:      Tuple     						=  type
																			self.model_tester.create_and_check_model(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]   )					->       int:







													"""simple docstring"""
													UpperCAmelCase_			:      Any     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_token_classification(*__magic_name__   )

							def     UpperCAmelCase__	(							self							:     str   )					->       List[Any]:







													"""simple docstring"""
													UpperCAmelCase_			:      Optional[Any]     						=  self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_for_question_answering(*__magic_name__   )



							@slow
							def     UpperCAmelCase__	(							self							:     int   )					->       Union[str, Any]:







													"""simple docstring"""
													for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_			:      Optional[int]     						=  LiltModel.from_pretrained(__magic_name__   )
																			self.assertIsNotNone(__magic_name__   )





@require_torch
@slow
class 					__a      (unittest.TestCase     ):

							def     UpperCAmelCase__	(							self							:     Tuple   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  LiltModel.from_pretrained('''SCUT-DLVCLab/lilt-roberta-en-base'''   ).to(__magic_name__   )

													UpperCAmelCase_			:      Any     						=  torch.tensor([[1, 2]]       ,     device=__magic_name__   )
													UpperCAmelCase_			:      int     						=  torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]       ,     device=__magic_name__   )

													# forward pass
													with torch.no_grad():
																			UpperCAmelCase_			:      Optional[int]     						=  model(input_ids=__magic_name__       ,     bbox=__magic_name__   )

													UpperCAmelCase_			:      int     						=  torch.Size([1, 2, 7_68]   )
													UpperCAmelCase_			:      List[str]     						=  torch.tensor(
													    [[-0.0_6_5_3, 0.0_9_5_0, -0.0_0_6_1], [-0.0_5_4_5, 0.0_9_2_6, -0.0_3_2_4]]       ,     device=__magic_name__       ,     )

													self.assertTrue(outputs.last_hidden_state.shape       ,     __magic_name__   )
													self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]       ,     __magic_name__       ,     atol=1E-3   )   )





