

import unittest

from datasets import load_dataset

from transformers import BloomTokenizerFast
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class 					a__						(					snake_case							,	unittest.TestCase			):
			"""simple docstring"""







			__lowerCamelCase        =       None
			__lowerCamelCase        =       BloomTokenizerFast
			__lowerCamelCase        =       BloomTokenizerFast
			__lowerCamelCase        =       True
			__lowerCamelCase        =       False
			__lowerCamelCase        =       'tokenizer_file'
			__lowerCamelCase        =       {'bos_token': '<s>', 'eos_token': '</s>', 'unk_token': '<unk>', 'pad_token': '<pad>'}


			def      UpperCamelCase		(    self       )  ->						Dict:
							'''simple docstring'''






							super().setUp()
							A__        =			BloomTokenizerFast.from_pretrained("bigscience/tokenizer"       )
							tokenizer.save_pretrained(self.tmpdirname       )


			def      UpperCamelCase		(    self      ,      **lowercase       )  ->						List[str]:
							'''simple docstring'''






							kwargs.update(self.special_tokens_map       )
							return BloomTokenizerFast.from_pretrained(self.tmpdirname      ,      **lowercase       )


			def      UpperCamelCase		(    self       )  ->						Dict:
							'''simple docstring'''






							A__        =			self.get_rust_tokenizer()

							A__        =			["The quick brown fox</s>", "jumps over the lazy dog</s>"]
							A__        =			[[2175, 23714, 73173, 144252, 2], [77, 132619, 3478, 368, 109586, 35433, 2]]

							A__        =			tokenizer.batch_encode_plus(lowercase       )["input_ids"]
							self.assertListEqual(lowercase      ,      lowercase       )

							A__        =			tokenizer.batch_decode(lowercase       )
							self.assertListEqual(lowercase      ,      lowercase       )


			def      UpperCamelCase		(    self      ,      lowercase=6       )  ->						List[str]:
							'''simple docstring'''






							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
											with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'       ):
															A__        =			self.rust_tokenizer_class.from_pretrained(lowercase      ,      **lowercase       )
															# tokenizer_r.pad_token = None # Hotfixing padding = None
															# Simple input
															A__        =			"This is a simple input"
															A__        =			["This is a simple input 1", "This is a simple input 2"]
															A__        =			("This is a simple input", "This is a pair")
															A__        =			[
															    ("This is a simple input 1", "This is a simple input 2"),
															    ("This is a simple pair 1", "This is a simple pair 2"),
															]

															# Simple input tests
															try:
																			tokenizer_r.encode(lowercase      ,      max_length=lowercase       )
																			tokenizer_r.encode_plus(lowercase      ,      max_length=lowercase       )

																			tokenizer_r.batch_encode_plus(lowercase      ,      max_length=lowercase       )
																			tokenizer_r.encode(lowercase      ,      max_length=lowercase       )
																			tokenizer_r.batch_encode_plus(lowercase      ,      max_length=lowercase       )
															except ValueError:
																			self.fail("Bloom Tokenizer should be able to deal with padding"       )

															A__        =			None  # Hotfixing padding = None
															self.assertRaises(lowercase      ,      tokenizer_r.encode      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"       )

															# Simple input
															self.assertRaises(lowercase      ,      tokenizer_r.encode_plus      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"       )

															# Simple input
															self.assertRaises(
															    lowercase      ,      tokenizer_r.batch_encode_plus      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"      ,      )

															# Pair input
															self.assertRaises(lowercase      ,      tokenizer_r.encode      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"       )

															# Pair input
															self.assertRaises(lowercase      ,      tokenizer_r.encode_plus      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"       )

															# Pair input
															self.assertRaises(
															    lowercase      ,      tokenizer_r.batch_encode_plus      ,      lowercase      ,      max_length=lowercase      ,      padding="max_length"      ,      )


			def      UpperCamelCase		(    self       )  ->						List[Any]:
							'''simple docstring'''






							A__        =			self.get_rust_tokenizer()
							A__        =			load_dataset("xnli"      ,      "all_languages"      ,      split="test"      ,      streaming=lowercase       )

							A__        =			next(iter(lowercase       )       )["premise"]  # pick up one data
							A__        =			list(sample_data.values()       )

							A__        =			list(map(tokenizer.encode      ,      lowercase       )       )
							A__        =			[tokenizer.decode(lowercase      ,      clean_up_tokenization_spaces=lowercase       ) for x in output_tokens]
							self.assertListEqual(lowercase      ,      lowercase       )


			def      UpperCamelCase		(    self       )  ->						Union[str, Any]:
							'''simple docstring'''






							self.assertGreaterEqual(len(self.tokenizer_class.pretrained_vocab_files_map       )      ,      1       )
							self.assertGreaterEqual(len(list(self.tokenizer_class.pretrained_vocab_files_map.values()       )[0]       )      ,      1       )




import unittest

import numpy as np

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

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
	import torch

if is_vision_available():
	from PIL import Image

	from transformers import PoolFormerImageProcessor

class 					a__						(					unittest.TestCase			):
			"""simple docstring"""







			def __init__(    self      ,      lowercase      ,      lowercase=7      ,      lowercase=3      ,      lowercase=30      ,      lowercase=400      ,      lowercase=True      ,      lowercase=None      ,      lowercase=0.9      ,      lowercase=None      ,      lowercase=True      ,      lowercase=[0.5, 0.5, 0.5]      ,      lowercase=[0.5, 0.5, 0.5]      ,      )  ->						str:
							'''simple docstring'''






							A__        =			size if size is not None else {"shortest_edge": 30}
							A__        =			crop_size if crop_size is not None else {"height": 30, "width": 30}
							A__        =			parent
							A__        =			batch_size
							A__        =			num_channels
							A__        =			min_resolution
							A__        =			max_resolution
							A__        =			do_resize_and_center_crop
							A__        =			size
							A__        =			crop_pct
							A__        =			crop_size
							A__        =			do_normalize
							A__        =			image_mean
							A__        =			image_std


			def      UpperCamelCase		(    self       )  ->						int:
							'''simple docstring'''






							return {
							    "size": self.size,
							    "do_resize_and_center_crop": self.do_resize_and_center_crop,
							    "crop_pct": self.crop_pct,
							    "crop_size": self.crop_size,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							}

@require_torch
@require_vision
class 					a__						(					snake_case							,	unittest.TestCase			):
			"""simple docstring"""







			__lowerCamelCase        =       PoolFormerImageProcessor if is_vision_available() else None


			def      UpperCamelCase		(    self       )  ->						str:
							'''simple docstring'''






							A__        =			PoolFormerImageProcessingTester(self       )


			@property
			def      UpperCamelCase		(    self       )  ->						List[str]:
							'''simple docstring'''






							return self.image_processor_tester.prepare_image_processor_dict()


			def      UpperCamelCase		(    self       )  ->						Any:
							'''simple docstring'''






							A__        =			self.image_processing_class(**self.image_processor_dict       )
							self.assertTrue(hasattr(lowercase      ,      "do_resize_and_center_crop"       )       )
							self.assertTrue(hasattr(lowercase      ,      "size"       )       )
							self.assertTrue(hasattr(lowercase      ,      "crop_pct"       )       )
							self.assertTrue(hasattr(lowercase      ,      "do_normalize"       )       )
							self.assertTrue(hasattr(lowercase      ,      "image_mean"       )       )
							self.assertTrue(hasattr(lowercase      ,      "image_std"       )       )


			def      UpperCamelCase		(    self       )  ->						List[str]:
							'''simple docstring'''






							A__        =			self.image_processing_class.from_dict(self.image_processor_dict       )
							self.assertEqual(image_processor.size      ,      {"shortest_edge": 30}       )
							self.assertEqual(image_processor.crop_size      ,      {"height": 30, "width": 30}       )

							A__        =			self.image_processing_class.from_dict(self.image_processor_dict      ,      size=42      ,      crop_size=84       )
							self.assertEqual(image_processor.size      ,      {"shortest_edge": 42}       )
							self.assertEqual(image_processor.crop_size      ,      {"height": 84, "width": 84}       )


			def      UpperCamelCase		(    self       )  ->						Optional[int]:
							'''simple docstring'''






							pass


			def      UpperCamelCase		(    self       )  ->						List[str]:
							'''simple docstring'''






							A__        =			self.image_processing_class(**self.image_processor_dict       )
							# create random PIL images
							A__        =			prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=lowercase       )
							for image in image_inputs:
											self.assertIsInstance(lowercase      ,      Image.Image       )

							# Test not batched input
							A__        =			image_processing(image_inputs[0]      ,      return_tensors="pt"       ).pixel_values

							self.assertEqual(
							    encoded_images.shape      ,      (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )

							# Test batched
							A__        =			image_processing(lowercase      ,      return_tensors="pt"       ).pixel_values
							self.assertEqual(
							    encoded_images.shape      ,      (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )


			def      UpperCamelCase		(    self       )  ->						Tuple:
							'''simple docstring'''






							A__        =			self.image_processing_class(**self.image_processor_dict       )
							# create random numpy tensors
							A__        =			prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=lowercase      ,      numpify=lowercase       )
							for image in image_inputs:
											self.assertIsInstance(lowercase      ,      np.ndarray       )

							# Test not batched input
							A__        =			image_processing(image_inputs[0]      ,      return_tensors="pt"       ).pixel_values
							self.assertEqual(
							    encoded_images.shape      ,      (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )

							# Test batched
							A__        =			image_processing(lowercase      ,      return_tensors="pt"       ).pixel_values
							self.assertEqual(
							    encoded_images.shape      ,      (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )


			def      UpperCamelCase		(    self       )  ->						Dict:
							'''simple docstring'''






							A__        =			self.image_processing_class(**self.image_processor_dict       )
							# create random PyTorch tensors
							A__        =			prepare_image_inputs(self.image_processor_tester      ,      equal_resolution=lowercase      ,      torchify=lowercase       )
							for image in image_inputs:
											self.assertIsInstance(lowercase      ,      torch.Tensor       )

							# Test not batched input
							A__        =			image_processing(image_inputs[0]      ,      return_tensors="pt"       ).pixel_values
							self.assertEqual(
							    encoded_images.shape      ,      (
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )

							# Test batched
							A__        =			image_processing(lowercase      ,      return_tensors="pt"       ).pixel_values
							self.assertEqual(
							    encoded_images.shape      ,      (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["height"],
							        self.image_processor_tester.crop_size["width"],
							    )      ,      )

