






from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_outputs import (
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import logging
from .configuration_regnet import RegNetConfig


A        =			logging.get_logger(__name__)

# General docstring
A        =			"RegNetConfig"

# Base docstring
A        =			"facebook/regnet-y-040"
A        =			[1, 1088, 7, 7]

# Image classification docstring
A        =			"facebook/regnet-y-040"
A        =			"tabby, tabby cat"

A        =			[
    "facebook/regnet-y-040",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]


class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = 3 ,    UpperCamelCase__ = 1 ,    UpperCamelCase__ = 1 ,    UpperCamelCase__ = "relu" ,    ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   nn.Convad(
						    lowercase_ ,    lowercase_ ,    kernel_size=lowercase_ ,    stride=lowercase_ ,    padding=kernel_size // 2 ,    groups=lowercase_ ,    bias=lowercase_ ,    )
						SCREAMING_SNAKE_CASE_   :	str													=   nn.BatchNormad(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ACTaFN[activation] if activation is not None else nn.Identity()






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.convolution(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	str													=   self.normalization(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.activation(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	str													=   RegNetConvLayer(
						    config.num_channels ,    config.embedding_size ,    kernel_size=3 ,    stride=2 ,    activation=config.hidden_act       )
						SCREAMING_SNAKE_CASE_   :	Any													=   config.num_channels






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   pixel_values.shape[1]
						if num_channels != self.num_channels:
										raise ValueError(
										    'Make sure that the channel dimension of the pixel values match with the one set in the configuration.'       )
						SCREAMING_SNAKE_CASE_   :	Any													=   self.embedder(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = 2       ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   nn.Convad(lowercase_ ,    lowercase_ ,    kernel_size=1 ,    stride=lowercase_ ,    bias=lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   nn.BatchNormad(lowercase_       )






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.convolution(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	str													=   self.normalization(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						super().__init__()

						SCREAMING_SNAKE_CASE_   :	int													=   nn.AdaptiveAvgPoolad((1, 1)       )
						SCREAMING_SNAKE_CASE_   :	int													=   nn.Sequential(
						    nn.Convad(lowercase_ ,    lowercase_ ,    kernel_size=1       ) ,    nn.ReLU() ,    nn.Convad(lowercase_ ,    lowercase_ ,    kernel_size=1       ) ,    nn.Sigmoid() ,    )






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						# b c h w -> b c 1 1
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.pooler(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.attention(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Any													=   hidden_state * attention
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = 1       ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   in_channels != out_channels or stride != 1
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   max(1 ,    out_channels // config.groups_width       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   (
						    RegNetShortCut(lowercase_ ,    lowercase_ ,    stride=lowercase_       ) if should_apply_shortcut else nn.Identity()
						)
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   nn.Sequential(
						    RegNetConvLayer(lowercase_ ,    lowercase_ ,    kernel_size=1 ,    activation=config.hidden_act       ) ,    RegNetConvLayer(lowercase_ ,    lowercase_ ,    stride=lowercase_ ,    groups=lowercase_ ,    activation=config.hidden_act       ) ,    RegNetConvLayer(lowercase_ ,    lowercase_ ,    kernel_size=1 ,    activation=lowercase_       ) ,    )
						SCREAMING_SNAKE_CASE_   :	int													=   ACTaFN[config.hidden_act]






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Any													=   hidden_state
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.layer(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.shortcut(lowercase_       )
						hidden_state += residual
						SCREAMING_SNAKE_CASE_   :	str													=   self.activation(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = 1       ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	str													=   in_channels != out_channels or stride != 1
						SCREAMING_SNAKE_CASE_   :	int													=   max(1 ,    out_channels // config.groups_width       )
						SCREAMING_SNAKE_CASE_   :	int													=   (
						    RegNetShortCut(lowercase_ ,    lowercase_ ,    stride=lowercase_       ) if should_apply_shortcut else nn.Identity()
						)
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   nn.Sequential(
						    RegNetConvLayer(lowercase_ ,    lowercase_ ,    kernel_size=1 ,    activation=config.hidden_act       ) ,    RegNetConvLayer(lowercase_ ,    lowercase_ ,    stride=lowercase_ ,    groups=lowercase_ ,    activation=config.hidden_act       ) ,    RegNetSELayer(lowercase_ ,    reduced_channels=int(round(in_channels / 4       )       )       ) ,    RegNetConvLayer(lowercase_ ,    lowercase_ ,    kernel_size=1 ,    activation=lowercase_       ) ,    )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   ACTaFN[config.hidden_act]






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   hidden_state
						SCREAMING_SNAKE_CASE_   :	str													=   self.layer(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	int													=   self.shortcut(lowercase_       )
						hidden_state += residual
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.activation(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = 2 ,    UpperCamelCase__ = 2 ,    ):
						super().__init__()

						SCREAMING_SNAKE_CASE_   :	str													=   RegNetXLayer if config.layer_type == """x""" else RegNetYLayer

						SCREAMING_SNAKE_CASE_   :	str													=   nn.Sequential(
						    # downsampling is done in the first layer with stride of 2
						    layer(
						        lowercase_ ,    lowercase_ ,    lowercase_ ,    stride=lowercase_ ,    ) ,    *[layer(lowercase_ ,    lowercase_ ,    lowercase_       ) for _ in range(depth - 1       )] ,    )






		def   __snake_case			(						self ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.layers(lowercase_       )
						return hidden_state






class 							__a							(  nn.Module						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super().__init__()
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   nn.ModuleList([]       )
						# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
						self.stages.append(
						    RegNetStage(
						        lowercase_ ,    config.embedding_size ,    config.hidden_sizes[0] ,    stride=2 if config.downsample_in_first_stage else 1 ,    depth=config.depths[0] ,    )       )
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   zip(config.hidden_sizes ,    config.hidden_sizes[1:]       )
						for (in_channels, out_channels), depth in zip(lowercase_ ,    config.depths[1:]       ):
										self.stages.append(RegNetStage(lowercase_ ,    lowercase_ ,    lowercase_ ,    depth=lowercase_       )       )






		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ = False ,    UpperCamelCase__ = True       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   () if output_hidden_states else None

						for stage_module in self.stages:
										if output_hidden_states:
														SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   hidden_states + (hidden_state,)

										SCREAMING_SNAKE_CASE_   :	Dict													=   stage_module(lowercase_       )

						if output_hidden_states:
										SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   hidden_states + (hidden_state,)

						if not return_dict:
										return tuple(v for v in [hidden_state, hidden_states] if v is not None       )

						return BaseModelOutputWithNoAttention(last_hidden_state=lowercase_ ,    hidden_states=lowercase_       )






class 							__a							(  _UpperCAmelCase						):





		'''simple docstring'''



		UpperCAmelCase__      :				int				    =						RegNetConfig
		UpperCAmelCase__      :				List[str]				    =						"""regnet"""
		UpperCAmelCase__      :				Any				    =						"""pixel_values"""
		UpperCAmelCase__      :				str				    =						True


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						if isinstance(lowercase_ ,    nn.Convad       ):
										nn.init.kaiming_normal_(module.weight ,    mode='fan_out' ,    nonlinearity='relu'       )
						elif isinstance(lowercase_ ,    (nn.BatchNormad, nn.GroupNorm)       ):
										nn.init.constant_(module.weight ,    1       )
										nn.init.constant_(module.bias ,    0       )






		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__=False       ):
						if isinstance(lowercase_ ,    lowercase_       ):
										SCREAMING_SNAKE_CASE_   :	List[str]													=   value






A        =			r"\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n"

A        =			r"\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~file_utils.ModelOutput`] instead of a plain tuple.\n"


@add_start_docstrings(
    """The bare RegNet model outputting raw features without any specific head on top.""" ,	_UpperCAmelCase ,	)
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class 							__a							(  _UpperCAmelCase						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super().__init__(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	List[str]													=   config
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   RegNetEmbeddings(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   RegNetEncoder(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	str													=   nn.AdaptiveAvgPoolad((1, 1)       )
						# Initialize weights and apply final processing
						self.post_init()






		@add_start_docstrings_to_model_forward(lowercase_       )
		@add_code_sample_docstrings(
		    checkpoint=_CHECKPOINT_FOR_DOC ,    output_type=lowercase_ ,    config_class=_CONFIG_FOR_DOC ,    modality='vision' ,    expected_output=_EXPECTED_OUTPUT_SHAPE ,    )
		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   (
						    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
						)
						SCREAMING_SNAKE_CASE_   :	Tuple													=   return_dict if return_dict is not None else self.config.use_return_dict

						SCREAMING_SNAKE_CASE_   :	str													=   self.embedder(lowercase_       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.encoder(
						    lowercase_ ,    output_hidden_states=lowercase_ ,    return_dict=lowercase_       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   encoder_outputs[0]

						SCREAMING_SNAKE_CASE_   :	str													=   self.pooler(lowercase_       )

						if not return_dict:
										return (last_hidden_state, pooled_output) + encoder_outputs[1:]

						return BaseModelOutputWithPoolingAndNoAttention(
						    last_hidden_state=lowercase_ ,    pooler_output=lowercase_ ,    hidden_states=encoder_outputs.hidden_states ,    )






@add_start_docstrings(
    """
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """ ,	_UpperCAmelCase ,	)
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class 							__a							(  _UpperCAmelCase						):





		'''simple docstring'''



		def __init__(						self ,    UpperCamelCase__       ):
						super().__init__(lowercase_       )
						SCREAMING_SNAKE_CASE_   :	Any													=   config.num_labels
						SCREAMING_SNAKE_CASE_   :	List[str]													=   RegNetModel(lowercase_       )
						# classification head
						SCREAMING_SNAKE_CASE_   :	Any													=   nn.Sequential(
						    nn.Flatten() ,    nn.Linear(config.hidden_sizes[-1] ,    config.num_labels       ) if config.num_labels > 0 else nn.Identity() ,    )
						# initialize weights and apply final processing
						self.post_init()






		@add_start_docstrings_to_model_forward(lowercase_       )
		@add_code_sample_docstrings(
		    checkpoint=_IMAGE_CLASS_CHECKPOINT ,    output_type=lowercase_ ,    config_class=_CONFIG_FOR_DOC ,    expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT ,    )
		def   __snake_case			(						self ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   return_dict if return_dict is not None else self.config.use_return_dict

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.regnet(lowercase_ ,    output_hidden_states=lowercase_ ,    return_dict=lowercase_       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   outputs.pooler_output if return_dict else outputs[1]

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.classifier(lowercase_       )

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   None

						if labels is not None:
										if self.config.problem_type is None:
														if self.num_labels == 1:
																		SCREAMING_SNAKE_CASE_   :	Optional[int]													=   """regression"""
														elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																		SCREAMING_SNAKE_CASE_   :	str													=   """single_label_classification"""
														else:
																		SCREAMING_SNAKE_CASE_   :	str													=   """multi_label_classification"""
										if self.config.problem_type == "regression":
														SCREAMING_SNAKE_CASE_   :	str													=   MSELoss()
														if self.num_labels == 1:
																		SCREAMING_SNAKE_CASE_   :	List[Any]													=   loss_fct(logits.squeeze() ,    labels.squeeze()       )
														else:
																		SCREAMING_SNAKE_CASE_   :	List[str]													=   loss_fct(lowercase_ ,    lowercase_       )
										elif self.config.problem_type == "single_label_classification":
														SCREAMING_SNAKE_CASE_   :	Optional[int]													=   CrossEntropyLoss()
														SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   loss_fct(logits.view(-1 ,    self.num_labels       ) ,    labels.view(-1       )       )
										elif self.config.problem_type == "multi_label_classification":
														SCREAMING_SNAKE_CASE_   :	Dict													=   BCEWithLogitsLoss()
														SCREAMING_SNAKE_CASE_   :	Tuple													=   loss_fct(lowercase_ ,    lowercase_       )

						if not return_dict:
										SCREAMING_SNAKE_CASE_   :	Tuple													=   (logits,) + outputs[2:]
										return (loss,) + output if loss is not None else output

						return ImageClassifierOutputWithNoAttention(loss=lowercase_ ,    logits=lowercase_ ,    hidden_states=outputs.hidden_states       )







import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
				from PIL import Image

				from transformers import AlignProcessor, EfficientNetImageProcessor


@require_vision
class 							__a							(  unittest.TestCase						):





		'''simple docstring'''



		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   tempfile.mkdtemp()

						SCREAMING_SNAKE_CASE_   :	List[str]													=   [
						    '[UNK]',
						    '[CLS]',
						    '[SEP]',
						    '[PAD]',
						    '[MASK]',
						    'want',
						    '##want',
						    '##ed',
						    'wa',
						    'un',
						    'runn',
						    '##ing',
						    ',',
						    'low',
						    'lowest',
						]
						SCREAMING_SNAKE_CASE_   :	Dict													=   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]       )       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   {
						    'do_resize': True,
						    'size': 20,
						    'do_center_crop': True,
						    'crop_size': 18,
						    'do_normalize': True,
						    'image_mean': [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73],
						    'image_std': [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11],
						}
						SCREAMING_SNAKE_CASE_   :	str													=   os.path.join(self.tmpdirname ,    UpperCamelCase__       )
						with open(self.image_processor_file ,    'w' ,    encoding='utf-8'       ) as fp:
										json.dump(UpperCamelCase__ ,    UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return BertTokenizer.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return BertTokenizerFast.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    **UpperCamelCase__       ):
						return EfficientNetImageProcessor.from_pretrained(self.tmpdirname ,    **UpperCamelCase__       )


		def   __snake_case			(						self       ):
						shutil.rmtree(self.tmpdirname       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   [np.random.randint(255 ,    size=(3, 30, 400) ,    dtype=np.uinta       )]
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   [Image.fromarray(np.moveaxis(UpperCamelCase__ ,    0 ,    -1       )       ) for x in image_inputs]
						return image_inputs


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.get_tokenizer()
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_rust_tokenizer()
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )
						processor_slow.save_pretrained(self.tmpdirname       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor.from_pretrained(self.tmpdirname ,    use_fast=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )
						processor_fast.save_pretrained(self.tmpdirname       )
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor.from_pretrained(self.tmpdirname       )

						self.assertEqual(processor_slow.tokenizer.get_vocab() ,    tokenizer_slow.get_vocab()       )
						self.assertEqual(processor_fast.tokenizer.get_vocab() ,    tokenizer_fast.get_vocab()       )
						self.assertEqual(tokenizer_slow.get_vocab() ,    tokenizer_fast.get_vocab()       )
						self.assertIsInstance(processor_slow.tokenizer ,    UpperCamelCase__       )
						self.assertIsInstance(processor_fast.tokenizer ,    UpperCamelCase__       )

						self.assertEqual(processor_slow.image_processor.to_json_string() ,    image_processor.to_json_string()       )
						self.assertEqual(processor_fast.image_processor.to_json_string() ,    image_processor.to_json_string()       )
						self.assertIsInstance(processor_slow.image_processor ,    UpperCamelCase__       )
						self.assertIsInstance(processor_fast.image_processor ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=self.get_tokenizer() ,    image_processor=self.get_image_processor()       )
						processor.save_pretrained(self.tmpdirname       )

						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.get_tokenizer(bos_token='(BOS)' ,    eos_token='(EOS)'       )
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_image_processor(do_normalize=UpperCamelCase__ ,    padding_value=1.0       )

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   AlignProcessor.from_pretrained(
						    self.tmpdirname ,    bos_token='(BOS)' ,    eos_token='(EOS)' ,    do_normalize=UpperCamelCase__ ,    padding_value=1.0       )

						self.assertEqual(processor.tokenizer.get_vocab() ,    tokenizer_add_kwargs.get_vocab()       )
						self.assertIsInstance(processor.tokenizer ,    UpperCamelCase__       )

						self.assertEqual(processor.image_processor.to_json_string() ,    image_processor_add_kwargs.to_json_string()       )
						self.assertIsInstance(processor.image_processor ,    UpperCamelCase__       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	str													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	str													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	int													=   image_processor(UpperCamelCase__ ,    return_tensors='np'       )
						SCREAMING_SNAKE_CASE_   :	Dict													=   processor(images=UpperCamelCase__ ,    return_tensors='np'       )

						for key in input_image_proc.keys():
										self.assertAlmostEqual(input_image_proc[key].sum() ,    input_processor[key].sum() ,    delta=1E-2       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	List[str]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   'lower newer'

						SCREAMING_SNAKE_CASE_   :	Tuple													=   processor(text=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	int													=   tokenizer(UpperCamelCase__ ,    padding='max_length' ,    max_length=64       )

						for key in encoded_tok.keys():
										self.assertListEqual(encoded_tok[key] ,    encoded_processor[key]       )


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	str													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	str													=   'lower newer'
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   processor(text=UpperCamelCase__ ,    images=UpperCamelCase__       )

						self.assertListEqual(list(inputs.keys()       ) ,    ['input_ids', 'token_type_ids', 'attention_mask', 'pixel_values']       )

						# test if it raises when no input is passed
						with pytest.raises(UpperCamelCase__       ):
										processor()


		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	Tuple													=   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

						SCREAMING_SNAKE_CASE_   :	List[str]													=   processor.batch_decode(UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   tokenizer.batch_decode(UpperCamelCase__       )

						self.assertListEqual(UpperCamelCase__ ,    UpperCamelCase__       )






		def   __snake_case			(						self       ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   self.get_image_processor()
						SCREAMING_SNAKE_CASE_   :	int													=   self.get_tokenizer()

						SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   AlignProcessor(tokenizer=UpperCamelCase__ ,    image_processor=UpperCamelCase__       )

						SCREAMING_SNAKE_CASE_   :	str													=   'lower newer'
						SCREAMING_SNAKE_CASE_   :	List[str]													=   self.prepare_image_inputs()

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   processor(text=UpperCamelCase__ ,    images=UpperCamelCase__       )

						self.assertListEqual(list(inputs.keys()       ) ,    processor.model_input_names       )