




"""simple docstring"""
import os
import unittest

from transformers import ElectraTokenizerFast
from transformers.models.electra.tokenization_electra import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    ElectraTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english







@require_tokenizers
class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__			,				unittest.TestCase				):



 '''simple docstring'''





 __UpperCAmelCase		   =							ElectraTokenizer
 __UpperCAmelCase		   =							ElectraTokenizerFast
 __UpperCAmelCase		   =							True
 __UpperCAmelCase		   =							True
 __UpperCAmelCase		   =							filter_non_english






 def lowercase_      (self   ):

  '''simple docstring'''







  super().setUp()

  _UpperCamelCase      :	List[str]					      =  [
      "[UNK]",
      "[CLS]",
      "[SEP]",
      "[PAD]",
      "[MASK]",
      "want",
      "##want",
      "##ed",
      "wa",
      "un",
      "runn",
      "##ing",
      ",",
      "low",
      "lowest",
  ]
  _UpperCamelCase      :	Any					      =  os.path.join(self.tmpdirname					,     VOCAB_FILES_NAMES["vocab_file"]   )
  with open(self.vocab_file					,     "w"					,     encoding="utf-8"   ) as vocab_writer:
   vocab_writer.write("".join([x + "\n" for x in vocab_tokens]   )   )






 def lowercase_      (self					,     lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[str]					      =  "UNwant\u00E9d,running"
  _UpperCamelCase      :	Any					      =  "unwanted, running"
  return input_text, output_text






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  self.tokenizer_class(self.vocab_file   )

  _UpperCamelCase      :	Optional[int]					      =  tokenizer.tokenize("UNwant\u00E9d,running"   )
  self.assertListEqual(lowerCAmelCase__					,     ["un", "##want", "##ed", ",", "runn", "##ing"]   )
  self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__   )					,     [9, 6, 7, 12, 10, 11]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  if not self.test_rust_tokenizer:
   return

  _UpperCamelCase      :	Any					      =  self.get_tokenizer()
  _UpperCamelCase      :	Tuple					      =  self.get_rust_tokenizer()

  _UpperCamelCase      :	int					      =  "UNwant\u00E9d,running"

  _UpperCamelCase      :	Union[str, Any]					      =  tokenizer.tokenize(lowerCAmelCase__   )
  _UpperCamelCase      :	List[str]					      =  rust_tokenizer.tokenize(lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

  _UpperCamelCase      :	Any					      =  tokenizer.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
  _UpperCamelCase      :	Any					      =  rust_tokenizer.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

  _UpperCamelCase      :	List[str]					      =  self.get_rust_tokenizer()
  _UpperCamelCase      :	List[str]					      =  tokenizer.encode(lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  rust_tokenizer.encode(lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

  # With lower casing
  _UpperCamelCase      :	List[str]					      =  self.get_tokenizer(do_lower_case=lowerCAmelCase__   )
  _UpperCamelCase      :	List[Any]					      =  self.get_rust_tokenizer(do_lower_case=lowerCAmelCase__   )

  _UpperCamelCase      :	Optional[Any]					      =  "UNwant\u00E9d,running"

  _UpperCamelCase      :	Dict					      =  tokenizer.tokenize(lowerCAmelCase__   )
  _UpperCamelCase      :	Tuple					      =  rust_tokenizer.tokenize(lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

  _UpperCamelCase      :	List[str]					      =  tokenizer.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  rust_tokenizer.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

  _UpperCamelCase      :	Any					      =  self.get_rust_tokenizer()
  _UpperCamelCase      :	Union[str, Any]					      =  tokenizer.encode(lowerCAmelCase__   )
  _UpperCamelCase      :	Any					      =  rust_tokenizer.encode(lowerCAmelCase__   )
  self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  BasicTokenizer()

  self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz"   )					,     ["ah", "\u535A", "\u63A8", "zz"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "   )					,     ["hello", "!", "how", "are", "you", "?"]   )
  self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )					,     ["hello"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__					,     strip_accents=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )					,     ["hällo", "!", "how", "are", "you", "?"]   )
  self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )					,     ["h\u00E9llo"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Dict					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__					,     strip_accents=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )					,     ["hallo", "!", "how", "are", "you", "?"]   )
  self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )					,     ["hello"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )					,     ["hallo", "!", "how", "are", "you", "?"]   )
  self.assertListEqual(tokenizer.tokenize("H\u00E9llo"   )					,     ["hello"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  "   )					,     ["HeLLo", "!", "how", "Are", "yoU", "?"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	str					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__					,     strip_accents=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )					,     ["HäLLo", "!", "how", "Are", "yoU", "?"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__					,     strip_accents=lowerCAmelCase__   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  "   )					,     ["HaLLo", "!", "how", "Are", "yoU", "?"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[Any]					      =  BasicTokenizer(do_lower_case=lowerCAmelCase__					,     never_split=["[UNK]"]   )

  self.assertListEqual(
      tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]"   )					,     ["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[str]					      =  ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

  _UpperCamelCase      :	Any					      =  {}
  for i, token in enumerate(lowerCAmelCase__   ):
   _UpperCamelCase      :	Optional[int]					      =  i
  _UpperCamelCase      :	Any					      =  WordpieceTokenizer(vocab=lowerCAmelCase__					,     unk_token="[UNK]"   )

  self.assertListEqual(tokenizer.tokenize(""   )					,     []   )

  self.assertListEqual(tokenizer.tokenize("unwanted running"   )					,     ["un", "##want", "##ed", "runn", "##ing"]   )

  self.assertListEqual(tokenizer.tokenize("unwantedX running"   )					,     ["[UNK]", "runn", "##ing"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  self.assertTrue(_is_whitespace(" "   )   )
  self.assertTrue(_is_whitespace("\t"   )   )
  self.assertTrue(_is_whitespace("\r"   )   )
  self.assertTrue(_is_whitespace("\n"   )   )
  self.assertTrue(_is_whitespace("\u00A0"   )   )

  self.assertFalse(_is_whitespace("A"   )   )
  self.assertFalse(_is_whitespace("-"   )   )






 def lowercase_      (self   ):

  '''simple docstring'''







  self.assertTrue(_is_control("\u0005"   )   )

  self.assertFalse(_is_control("A"   )   )
  self.assertFalse(_is_control(" "   )   )
  self.assertFalse(_is_control("\t"   )   )
  self.assertFalse(_is_control("\r"   )   )






 def lowercase_      (self   ):

  '''simple docstring'''







  self.assertTrue(_is_punctuation("-"   )   )
  self.assertTrue(_is_punctuation("$"   )   )
  self.assertTrue(_is_punctuation("`"   )   )
  self.assertTrue(_is_punctuation("."   )   )

  self.assertFalse(_is_punctuation("A"   )   )
  self.assertFalse(_is_punctuation(" "   )   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  self.get_tokenizer()
  _UpperCamelCase      :	List[Any]					      =  self.get_rust_tokenizer()

  # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
  self.assertListEqual([tokenizer.tokenize(lowerCAmelCase__   ) for t in ["Test", "\xad", "test"]]					,     [["[UNK]"], [], ["[UNK]"]]   )

  self.assertListEqual(
      [rust_tokenizer.tokenize(lowerCAmelCase__   ) for t in ["Test", "\xad", "test"]]					,     [["[UNK]"], [], ["[UNK]"]]   )






 @slow
 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  self.tokenizer_class.from_pretrained("google/electra-base-discriminator"   )

  _UpperCamelCase      :	int					      =  tokenizer.encode("sequence builders"					,     add_special_tokens=lowerCAmelCase__   )
  _UpperCamelCase      :	str					      =  tokenizer.encode("multi-sequence build"					,     add_special_tokens=lowerCAmelCase__   )

  _UpperCamelCase      :	Union[str, Any]					      =  tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[int]					      =  tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__					,     lowerCAmelCase__   )

  assert encoded_sentence == [1_01] + text + [1_02]
  assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]






 def lowercase_      (self   ):

  '''simple docstring'''







  for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
   with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"   ):
    _UpperCamelCase      :	Optional[Any]					      =  self.rust_tokenizer_class.from_pretrained(lowerCAmelCase__					,     **lowerCAmelCase__   )

    _UpperCamelCase      :	Any					      =  F"A, naïve {tokenizer_r.mask_token} AllenNLP sentence."
    _UpperCamelCase      :	str					      =  tokenizer_r.encode_plus(
        lowerCAmelCase__					,     return_attention_mask=lowerCAmelCase__					,     return_token_type_ids=lowerCAmelCase__					,     return_offsets_mapping=lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__					,     )

    _UpperCamelCase      :	Union[str, Any]					      =  tokenizer_r.do_lower_case if hasattr(lowerCAmelCase__					,     "do_lower_case"   ) else False
    _UpperCamelCase      :	str					      =  (
        [
            ((0, 0), tokenizer_r.cls_token),
            ((0, 1), "A"),
            ((1, 2), ","),
            ((3, 5), "na"),
            ((5, 6), "##ï"),
            ((6, 8), "##ve"),
            ((9, 15), tokenizer_r.mask_token),
            ((16, 21), "Allen"),
            ((21, 23), "##NL"),
            ((23, 24), "##P"),
            ((25, 33), "sentence"),
            ((33, 34), "."),
            ((0, 0), tokenizer_r.sep_token),
        ]
        if not do_lower_case
        else [
            ((0, 0), tokenizer_r.cls_token),
            ((0, 1), "a"),
            ((1, 2), ","),
            ((3, 8), "naive"),
            ((9, 15), tokenizer_r.mask_token),
            ((16, 21), "allen"),
            ((21, 23), "##nl"),
            ((23, 24), "##p"),
            ((25, 33), "sentence"),
            ((33, 34), "."),
            ((0, 0), tokenizer_r.sep_token),
        ]
    )

    self.assertEqual(
        [e[1] for e in expected_results]					,     tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]   )   )
    self.assertEqual([e[0] for e in expected_results]					,     tokens["offset_mapping"]   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Any					      =  ["的", "人", "有"]
  _UpperCamelCase      :	Optional[int]					      =  "".join(lowerCAmelCase__   )
  for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
   with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})"   ):
    _UpperCamelCase      :	Optional[int]					      =  True
    _UpperCamelCase      :	Optional[int]					      =  self.tokenizer_class.from_pretrained(lowerCAmelCase__					,     **lowerCAmelCase__   )
    _UpperCamelCase      :	int					      =  self.rust_tokenizer_class.from_pretrained(lowerCAmelCase__					,     **lowerCAmelCase__   )

    _UpperCamelCase      :	Optional[int]					      =  tokenizer_p.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
    _UpperCamelCase      :	List[Any]					      =  tokenizer_r.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )

    _UpperCamelCase      :	int					      =  tokenizer_r.convert_ids_to_tokens(lowerCAmelCase__   )
    _UpperCamelCase      :	str					      =  tokenizer_p.convert_ids_to_tokens(lowerCAmelCase__   )

    # it is expected that each Chinese character is not preceded by "##"
    self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )
    self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )

    _UpperCamelCase      :	Any					      =  False
    _UpperCamelCase      :	Dict					      =  self.rust_tokenizer_class.from_pretrained(lowerCAmelCase__					,     **lowerCAmelCase__   )
    _UpperCamelCase      :	Dict					      =  self.tokenizer_class.from_pretrained(lowerCAmelCase__					,     **lowerCAmelCase__   )

    _UpperCamelCase      :	Dict					      =  tokenizer_r.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )
    _UpperCamelCase      :	Dict					      =  tokenizer_p.encode(lowerCAmelCase__					,     add_special_tokens=lowerCAmelCase__   )

    _UpperCamelCase      :	Any					      =  tokenizer_r.convert_ids_to_tokens(lowerCAmelCase__   )
    _UpperCamelCase      :	List[str]					      =  tokenizer_p.convert_ids_to_tokens(lowerCAmelCase__   )

    # it is expected that only the first Chinese character is not preceded by "##".
    _UpperCamelCase      :	Tuple					      =  [
        F"##{token}" if idx != 0 else token for idx, token in enumerate(lowerCAmelCase__   )
    ]
    self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )
    self.assertListEqual(lowerCAmelCase__					,     lowerCAmelCase__   )









"""simple docstring"""
import json
import os
import tempfile

from transformers.testing_utils import check_json_file_has_correct_format, require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available


if is_torch_available():
    import numpy as np
    import torch

if is_vision_available():
    from PIL import Image






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Any  ,	__lowerCAmelCase			:		Dict=False  ,	__lowerCAmelCase			:		Optional[Any]=False  ,	__lowerCAmelCase			:		int=False						)    ->       List[str]:
 assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

 _UpperCamelCase      :	Optional[int]					      =  []
 for i in range(image_processor_tester.batch_size						):
  if equal_resolution:
   _UpperCamelCase      :	List[str]					      =  image_processor_tester.max_resolution
  else:
   # To avoid getting image width/height 0
   _UpperCamelCase      :	int					      =  image_processor_tester.min_resolution
   if getattr(__lowerCAmelCase  ,	"size_divisor"  ,	__lowerCAmelCase						):
    # If `size_divisor` is defined, the image needs to have width/size >= `size_divisor`
    _UpperCamelCase      :	Optional[int]					      =  max(image_processor_tester.size_divisor  ,	__lowerCAmelCase						)
   _UpperCamelCase      ,	_UpperCamelCase      :	Optional[Any]					      =  np.random.choice(np.arange(__lowerCAmelCase  ,	image_processor_tester.max_resolution						)  ,	2						)
  image_inputs.append(
      np.random.randint(255  ,	size=(image_processor_tester.num_channels, width, height)  ,	dtype=np.uinta						)						)

 if not numpify and not torchify:
  # PIL expects the channel dimension as last dimension
  _UpperCamelCase      :	Optional[Any]					      =  [Image.fromarray(np.moveaxis(__lowerCAmelCase  ,	0  ,	-1						)						) for image in image_inputs]

 if torchify:
  _UpperCamelCase      :	str					      =  [torch.from_numpy(__lowerCAmelCase						) for image in image_inputs]

 return image_inputs






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Optional[Any]  ,	__lowerCAmelCase			:		Tuple=10  ,	__lowerCAmelCase			:		str=10  ,	__lowerCAmelCase			:		Any=False  ,	__lowerCAmelCase			:		List[Any]=False						)    ->       Optional[int]:
 _UpperCamelCase      :	Optional[int]					      =  []
 for i in range(image_processor_tester.num_frames						):
  video.append(np.random.randint(255  ,	size=(image_processor_tester.num_channels, width, height)  ,	dtype=np.uinta						)						)

 if not numpify and not torchify:
  # PIL expects the channel dimension as last dimension
  _UpperCamelCase      :	Optional[int]					      =  [Image.fromarray(np.moveaxis(__lowerCAmelCase  ,	0  ,	-1						)						) for frame in video]

 if torchify:
  _UpperCamelCase      :	int					      =  [torch.from_numpy(__lowerCAmelCase						) for frame in video]

 return video






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		List[Any]  ,	__lowerCAmelCase			:		Union[str, Any]=False  ,	__lowerCAmelCase			:		Any=False  ,	__lowerCAmelCase			:		Dict=False						)    ->       Any:
 assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

 _UpperCamelCase      :	Optional[Any]					      =  []
 for i in range(image_processor_tester.batch_size						):
  if equal_resolution:
   _UpperCamelCase      :	List[Any]					      =  image_processor_tester.max_resolution
  else:
   _UpperCamelCase      ,	_UpperCamelCase      :	Optional[int]					      =  np.random.choice(
       np.arange(image_processor_tester.min_resolution  ,	image_processor_tester.max_resolution						)  ,	2						)
   _UpperCamelCase      :	List[Any]					      =  prepare_video(
       image_processor_tester=__lowerCAmelCase  ,	width=__lowerCAmelCase  ,	height=__lowerCAmelCase  ,	numpify=__lowerCAmelCase  ,	torchify=__lowerCAmelCase  ,	)
  video_inputs.append(__lowerCAmelCase						)

 return video_inputs







class  _SCREAMING_SNAKE_CASE       :



 '''simple docstring'''





 __UpperCAmelCase		   =							None






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	str					      =  self.image_processing_class(**self.image_processor_dict   )
  _UpperCamelCase      :	Optional[int]					      =  json.loads(image_processor.to_json_string()   )
  for key, value in self.image_processor_dict.items():
   self.assertEqual(obj[key]					,     lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  self.image_processing_class(**self.image_processor_dict   )

  with tempfile.TemporaryDirectory() as tmpdirname:
   _UpperCamelCase      :	Tuple					      =  os.path.join(lowerCAmelCase__					,     "image_processor.json"   )
   image_processor_first.to_json_file(lowerCAmelCase__   )
   _UpperCamelCase      :	Tuple					      =  self.image_processing_class.from_json_file(lowerCAmelCase__   )

  self.assertEqual(image_processor_second.to_dict()					,     image_processor_first.to_dict()   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Dict					      =  self.image_processing_class(**self.image_processor_dict   )

  with tempfile.TemporaryDirectory() as tmpdirname:
   _UpperCamelCase      :	Optional[int]					      =  image_processor_first.save_pretrained(lowerCAmelCase__   )[0]
   check_json_file_has_correct_format(lowerCAmelCase__   )
   _UpperCamelCase      :	int					      =  self.image_processing_class.from_pretrained(lowerCAmelCase__   )

  self.assertEqual(image_processor_second.to_dict()					,     image_processor_first.to_dict()   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  self.image_processing_class()
  self.assertIsNotNone(lowerCAmelCase__   )






 @require_torch
 @require_vision
 def lowercase_      (self   ):

  '''simple docstring'''







  if self.test_cast_dtype is not None:
   # Initialize image_processor
   _UpperCamelCase      :	Optional[int]					      =  self.image_processing_class(**self.image_processor_dict   )

   # create random PyTorch tensors
   _UpperCamelCase      :	str					      =  prepare_image_inputs(self.image_processor_tester					,     equal_resolution=lowerCAmelCase__					,     torchify=lowerCAmelCase__   )

   _UpperCamelCase      :	List[Any]					      =  image_processor(lowerCAmelCase__					,     return_tensors="pt"   )
   # for layoutLM compatiblity
   self.assertEqual(encoding.pixel_values.device					,     torch.device("cpu"   )   )
   self.assertEqual(encoding.pixel_values.dtype					,     torch.floataa   )

   _UpperCamelCase      :	List[Any]					      =  image_processor(lowerCAmelCase__					,     return_tensors="pt"   ).to(torch.floataa   )
   self.assertEqual(encoding.pixel_values.device					,     torch.device("cpu"   )   )
   self.assertEqual(encoding.pixel_values.dtype					,     torch.floataa   )

   _UpperCamelCase      :	str					      =  image_processor(lowerCAmelCase__					,     return_tensors="pt"   ).to("cpu"					,     torch.bfloataa   )
   self.assertEqual(encoding.pixel_values.device					,     torch.device("cpu"   )   )
   self.assertEqual(encoding.pixel_values.dtype					,     torch.bfloataa   )

   with self.assertRaises(lowerCAmelCase__   ):
    _UpperCamelCase      :	Optional[int]					      =  image_processor(lowerCAmelCase__					,     return_tensors="pt"   ).to(torch.bfloataa					,     "cpu"   )

   # Try with text + image feature
   _UpperCamelCase      :	Union[str, Any]					      =  image_processor(lowerCAmelCase__					,     return_tensors="pt"   )
   encoding.update({"input_ids": torch.LongTensor([[1, 2, 3], [4, 5, 6]]   )}   )
   _UpperCamelCase      :	Optional[int]					      =  encoding.to(torch.floataa   )

   self.assertEqual(encoding.pixel_values.device					,     torch.device("cpu"   )   )
   self.assertEqual(encoding.pixel_values.dtype					,     torch.floataa   )
   self.assertEqual(encoding.input_ids.dtype					,     torch.long   )



