


import inspect
import unittest

from transformers import BitConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch
       from torch import nn

       from transformers import BitBackbone, BitForImageClassification, BitImageProcessor, BitModel
       from transformers.models.bit.modeling_bit import BIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image


class   a__	:

       def __init__(   self      :     Union[str, Any]      ,							lowerCamelCase_      :     Dict      ,							lowerCamelCase_      :     List[str]=3      ,							lowerCamelCase_      :     Any=3_2      ,							lowerCamelCase_      :     Optional[Any]=3      ,							lowerCamelCase_      :     Optional[int]=1_0      ,							lowerCamelCase_      :     str=[8, 1_6, 3_2, 6_4]      ,							lowerCamelCase_      :     Optional[int]=[1, 1, 2, 1]      ,							lowerCamelCase_      :     Dict=True      ,							lowerCamelCase_      :     Union[str, Any]=True      ,							lowerCamelCase_      :     str="relu"      ,							lowerCamelCase_      :     Tuple=3      ,							lowerCamelCase_      :     str=None      ,							lowerCamelCase_      :     str=["stage2", "stage3", "stage4"]      ,							lowerCamelCase_      :     str=[2, 3, 4]      ,							lowerCamelCase_      :     List[Any]=1      ,							):
            a_    :     Tuple										=    parent
            a_    :     Union[str, Any]										=    batch_size
            a_    :     Any										=    image_size
            a_    :     Any										=    num_channels
            a_    :     Tuple										=    embeddings_size
            a_    :     Dict										=    hidden_sizes
            a_    :     int										=    depths
            a_    :     List[Any]										=    is_training
            a_    :     Optional[int]										=    use_labels
            a_    :     List[str]										=    hidden_act
            a_    :     Tuple										=    num_labels
            a_    :     Dict										=    scope
            a_    :     List[str]										=    len(lowerCamelCase_    )
            a_    :     Union[str, Any]										=    out_features
            a_    :     Optional[int]										=    out_indices
            a_    :     Union[str, Any]										=    num_groups

       def 						UpperCAmelCase(   self      :     List[Any]    ):
            a_    :     Optional[Any]										=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

            a_    :     Union[str, Any]										=    None
            if self.use_labels:
                 a_    :     Any										=    ids_tensor([self.batch_size]      ,							self.num_labels    )

            a_    :     Union[str, Any]										=    self.get_config()

            return config, pixel_values, labels

       def 						UpperCAmelCase(   self      :     Dict    ):
            return BitConfig(
                num_channels=self.num_channels      ,							embeddings_size=self.embeddings_size      ,							hidden_sizes=self.hidden_sizes      ,							depths=self.depths      ,							hidden_act=self.hidden_act      ,							num_labels=self.num_labels      ,							out_features=self.out_features      ,							out_indices=self.out_indices      ,							num_groups=self.num_groups      ,							)

       def 						UpperCAmelCase(   self      :     str      ,							lowerCamelCase_      :     Optional[int]      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     Optional[int]    ):
            a_    :     List[str]										=    BitModel(config=lowerCamelCase_    )
            model.to(lowerCamelCase_    )
            model.eval()
            a_    :     Dict										=    model(lowerCamelCase_    )
            self.parent.assertEqual(
                result.last_hidden_state.shape      ,							(self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)      ,							)

       def 						UpperCAmelCase(   self      :     Tuple      ,							lowerCamelCase_      :     Any      ,							lowerCamelCase_      :     Any      ,							lowerCamelCase_      :     Optional[Any]    ):
            a_    :     str										=    self.num_labels
            a_    :     Optional[int]										=    BitForImageClassification(lowerCamelCase_    )
            model.to(lowerCamelCase_    )
            model.eval()
            a_    :     List[str]										=    model(lowerCamelCase_      ,							labels=lowerCamelCase_    )
            self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_labels)    )

       def 						UpperCAmelCase(   self      :     List[str]      ,							lowerCamelCase_      :     Any      ,							lowerCamelCase_      :     Dict      ,							lowerCamelCase_      :     Optional[int]    ):
            a_    :     Dict										=    BitBackbone(config=lowerCamelCase_    )
            model.to(lowerCamelCase_    )
            model.eval()
            a_    :     Any										=    model(lowerCamelCase_    )

            # verify feature maps
            self.parent.assertEqual(len(result.feature_maps    )      ,							len(config.out_features    )    )
            self.parent.assertListEqual(list(result.feature_maps[0].shape    )      ,							[self.batch_size, self.hidden_sizes[1], 4, 4]    )

            # verify channels
            self.parent.assertEqual(len(model.channels    )      ,							len(config.out_features    )    )
            self.parent.assertListEqual(model.channels      ,							config.hidden_sizes[1:]    )

            # verify backbone works with out_features=None
            a_    :     str										=    None
            a_    :     Dict										=    BitBackbone(config=lowerCamelCase_    )
            model.to(lowerCamelCase_    )
            model.eval()
            a_    :     List[str]										=    model(lowerCamelCase_    )

            # verify feature maps
            self.parent.assertEqual(len(result.feature_maps    )      ,							1    )
            self.parent.assertListEqual(list(result.feature_maps[0].shape    )      ,							[self.batch_size, self.hidden_sizes[-1], 1, 1]    )

            # verify channels
            self.parent.assertEqual(len(model.channels    )      ,							1    )
            self.parent.assertListEqual(model.channels      ,							[config.hidden_sizes[-1]]    )

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            a_    :     str										=    self.prepare_config_and_inputs()
            a_			,			a_			,			a_    :     Union[str, Any]										=    config_and_inputs
            a_    :     Any										=    {"""pixel_values""": pixel_values}
            return config, inputs_dict


@require_torch
class   a__	(						lowerCAmelCase_						,       lowerCAmelCase_						,       unittest.TestCase    ):
       lowerCamelCase__:     Any							    =     (BitModel, BitForImageClassification, BitBackbone) if is_torch_available() else ()
       lowerCamelCase__:     str							    =     (
           {"""feature-extraction""": BitModel, """image-classification""": BitForImageClassification}
           if is_torch_available()
           else {}
       )

       lowerCamelCase__:     Any							    =     False
       lowerCamelCase__:     List[str]							    =     False
       lowerCamelCase__:     List[str]							    =     False
       lowerCamelCase__:     int							    =     False
       lowerCamelCase__:     List[str]							    =     False

       def 						UpperCAmelCase(   self      :     Optional[Any]    ):
            a_    :     List[Any]										=    BitModelTester(self    )
            a_    :     List[Any]										=    ConfigTester(self      ,							config_class=lowerCamelCase_      ,							has_text_modality=lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            self.create_and_test_config_common_properties()
            self.config_tester.create_and_test_config_to_json_string()
            self.config_tester.create_and_test_config_to_json_file()
            self.config_tester.create_and_test_config_from_and_save_pretrained()
            self.config_tester.create_and_test_config_with_num_labels()
            self.config_tester.check_config_can_be_init_without_params()
            self.config_tester.check_config_arguments_init()

       def 						UpperCAmelCase(   self      :     Optional[int]    ):
            return

       @unittest.skip(reason="""Bit does not output attentions"""    )
       def 						UpperCAmelCase(   self      :     Dict    ):
            pass

       @unittest.skip(reason="""Bit does not use inputs_embeds"""    )
       def 						UpperCAmelCase(   self      :     int    ):
            pass

       @unittest.skip(reason="""Bit does not support input and output embeddings"""    )
       def 						UpperCAmelCase(   self      :     Any    ):
            pass

       def 						UpperCAmelCase(   self      :     Tuple    ):
            a_			,			a_    :     int										=    self.model_tester.prepare_config_and_inputs_for_common()

            for model_class in self.all_model_classes:
                 a_    :     Dict										=    model_class(lowerCamelCase_    )
                 a_    :     List[str]										=    inspect.signature(model.forward    )
                 # signature.parameters is an OrderedDict => so arg_names order is deterministic
                 a_    :     str										=    [*signature.parameters.keys()]

                 a_    :     List[str]										=    ["""pixel_values"""]
                 self.assertListEqual(arg_names[:1]      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Tuple    ):
            a_    :     Optional[Any]										=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     List[Any]    ):
            a_    :     Optional[int]										=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_backbone(*lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Optional[int]    ):
            a_			,			a_    :     str										=    self.model_tester.prepare_config_and_inputs_for_common()

            for model_class in self.all_model_classes:
                 a_    :     str										=    model_class(config=lowerCamelCase_    )
                 for name, module in model.named_modules():
                      if isinstance(lowerCamelCase_      ,							(nn.BatchNormad, nn.GroupNorm)    ):
                           self.assertTrue(
                               torch.all(module.weight == 1    )      ,							msg=F'''Parameter {name} of model {model_class} seems not properly initialized'''      ,							)
                           self.assertTrue(
                               torch.all(module.bias == 0    )      ,							msg=F'''Parameter {name} of model {model_class} seems not properly initialized'''      ,							)

       def 						UpperCAmelCase(   self      :     Optional[Any]    ):
            def check_hidden_states_output(lowerCamelCase_      :     Union[str, Any]      ,							lowerCamelCase_      :     Tuple      ,							lowerCamelCase_      :     Optional[Any]    ):
                 a_    :     List[str]										=    model_class(lowerCamelCase_    )
                 model.to(lowerCamelCase_    )
                 model.eval()

                 with torch.no_grad():
                      a_    :     List[str]										=    model(**self._prepare_for_class(lowerCamelCase_      ,							lowerCamelCase_    )    )

                 a_    :     str										=    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                 a_    :     Union[str, Any]										=    self.model_tester.num_stages
                 self.assertEqual(len(lowerCamelCase_    )      ,							expected_num_stages + 1    )

                 # Bit's feature maps are of shape (batch_size, num_channels, height, width)
                 self.assertListEqual(
                     list(hidden_states[0].shape[-2:]    )      ,							[self.model_tester.image_size // 4, self.model_tester.image_size // 4]      ,							)

            a_			,			a_    :     Union[str, Any]										=    self.model_tester.prepare_config_and_inputs_for_common()
            a_    :     Union[str, Any]										=    ["""preactivation""", """bottleneck"""]
            for model_class in self.all_model_classes:
                 for layer_type in layers_type:
                      a_    :     Dict										=    layer_type
                      a_    :     List[str]										=    True
                      check_hidden_states_output(lowerCamelCase_      ,							lowerCamelCase_      ,							lowerCamelCase_    )

                      # check that output_hidden_states also work using config
                      del inputs_dict["output_hidden_states"]
                      a_    :     int										=    True

                      check_hidden_states_output(lowerCamelCase_      ,							lowerCamelCase_      ,							lowerCamelCase_    )

       @unittest.skip(reason="""Bit does not use feedforward chunking"""    )
       def 						UpperCAmelCase(   self      :     Dict    ):
            pass

       def 						UpperCAmelCase(   self      :     Optional[int]    ):
            a_    :     Dict										=    self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_    )

       @slow
       def 						UpperCAmelCase(   self      :     str    ):
            for model_name in BIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 a_    :     Any										=    BitModel.from_pretrained(lowerCamelCase_    )
                 self.assertIsNotNone(lowerCamelCase_    )



def  _a			(						):
     a_    :     Optional[int]										=    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
     return image


@require_torch
@require_vision
class   a__	(						unittest.TestCase    ):

       @cached_property
       def 						UpperCAmelCase(   self      :     str    ):
            return (
                BitImageProcessor.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]    ) if is_vision_available() else None
            )

       @slow
       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            a_    :     Optional[int]										=    BitForImageClassification.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]    ).to(lowerCamelCase_    )

            a_    :     Union[str, Any]										=    self.default_image_processor
            a_    :     int										=    prepare_img()
            a_    :     Dict										=    image_processor(images=lowerCamelCase_      ,							return_tensors="""pt"""    ).to(lowerCamelCase_    )

            # forward pass
            with torch.no_grad():
                 a_    :     List[str]										=    model(**lowerCamelCase_    )

            # verify the logits
            a_    :     str										=    torch.Size((1, 1_0_0_0)    )
            self.assertEqual(outputs.logits.shape      ,							lowerCamelCase_    )

            a_    :     List[Any]										=    torch.tensor([[-0.6_5_2_6, -0.5_2_6_3, -1.4_3_9_8]]    ).to(lowerCamelCase_    )

            self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,							lowerCamelCase_      ,							atol=1E-4    )    )


@require_torch
class   a__	(						lowerCAmelCase_						,       unittest.TestCase    ):
       lowerCamelCase__:     Optional[int]							    =     (BitBackbone,) if is_torch_available() else ()
       lowerCamelCase__:     Any							    =     BitConfig

       lowerCamelCase__:     Dict							    =     False

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            a_    :     List[str]										=    BitModelTester(self    )







import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    IMAGE_PROCESSOR_MAPPING,
    AutoConfig,
    AutoImageProcessor,
    CLIPConfig,
    CLIPImageProcessor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_image_processing import CustomImageProcessor  # noqa E402


class   a__	(						unittest.TestCase    ):

       def 						UpperCAmelCase(   self      :     int    ):
            a_    :     Any										=    0

       def 						UpperCAmelCase(   self      :     Dict    ):
            a_    :     List[str]										=    AutoImageProcessor.from_pretrained("""openai/clip-vit-base-patch32"""    )
            self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     int    ):
            with tempfile.TemporaryDirectory() as tmpdirname:
                 a_    :     Any										=    Path(lowerCamelCase_    ) / """preprocessor_config.json"""
                 a_    :     Tuple										=    Path(lowerCamelCase_    ) / """config.json"""
                 json.dump(
                     {"""image_processor_type""": """CLIPImageProcessor""", """processor_class""": """CLIPProcessor"""}      ,							open(lowerCamelCase_      ,							"""w"""    )      ,							)
                 json.dump({"""model_type""": """clip"""}      ,							open(lowerCamelCase_      ,							"""w"""    )    )

                 a_    :     Union[str, Any]										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    )
                 self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     List[Any]    ):
            # Ensure we can load the image processor from the feature extractor config
            with tempfile.TemporaryDirectory() as tmpdirname:
                 a_    :     Dict										=    Path(lowerCamelCase_    ) / """preprocessor_config.json"""
                 a_    :     List[str]										=    Path(lowerCamelCase_    ) / """config.json"""
                 json.dump(
                     {"""feature_extractor_type""": """CLIPFeatureExtractor""", """processor_class""": """CLIPProcessor"""}      ,							open(lowerCamelCase_      ,							"""w"""    )      ,							)
                 json.dump({"""model_type""": """clip"""}      ,							open(lowerCamelCase_      ,							"""w"""    )    )

                 a_    :     int										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    )
                 self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Optional[Any]    ):
            with tempfile.TemporaryDirectory() as tmpdirname:
                 a_    :     int										=    CLIPConfig()

                 # Create a dummy config file with image_proceesor_type
                 a_    :     Tuple										=    Path(lowerCamelCase_    ) / """preprocessor_config.json"""
                 a_    :     Tuple										=    Path(lowerCamelCase_    ) / """config.json"""
                 json.dump(
                     {"""image_processor_type""": """CLIPImageProcessor""", """processor_class""": """CLIPProcessor"""}      ,							open(lowerCamelCase_      ,							"""w"""    )      ,							)
                 json.dump({"""model_type""": """clip"""}      ,							open(lowerCamelCase_      ,							"""w"""    )    )

                 # remove image_processor_type to make sure config.json alone is enough to load image processor locally
                 a_    :     Optional[int]										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    ).to_dict()

                 config_dict.pop("""image_processor_type"""    )
                 a_    :     Tuple										=    CLIPImageProcessor(**lowerCamelCase_    )

                 # save in new folder
                 model_config.save_pretrained(lowerCamelCase_    )
                 config.save_pretrained(lowerCamelCase_    )

                 a_    :     Optional[int]										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    )

                 # make sure private variable is not incorrectly saved
                 a_    :     str										=    json.loads(config.to_json_string()    )
                 self.assertTrue("""_processor_class""" not in dict_as_saved    )

            self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Dict    ):
            with tempfile.TemporaryDirectory() as tmpdirname:
                 a_    :     Union[str, Any]										=    Path(lowerCamelCase_    ) / """preprocessor_config.json"""
                 json.dump(
                     {"""image_processor_type""": """CLIPImageProcessor""", """processor_class""": """CLIPProcessor"""}      ,							open(lowerCamelCase_      ,							"""w"""    )      ,							)

                 a_    :     Optional[int]										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    )
                 self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     int    ):
            with self.assertRaisesRegex(
                lowerCamelCase_      ,							"""clip-base is not a local folder and is not a valid model identifier"""    ):
                 a_    :     Any										=    AutoImageProcessor.from_pretrained("""clip-base"""    )

       def 						UpperCAmelCase(   self      :     Optional[Any]    ):
            with self.assertRaisesRegex(
                lowerCamelCase_      ,							R"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""    ):
                 a_    :     Dict										=    AutoImageProcessor.from_pretrained(lowerCamelCase_      ,							revision="""aaaaaa"""    )

       def 						UpperCAmelCase(   self      :     Dict    ):
            with self.assertRaisesRegex(
                lowerCamelCase_      ,							"""hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json."""      ,							):
                 a_    :     Any										=    AutoImageProcessor.from_pretrained("""hf-internal-testing/config-no-model"""    )

       def 						UpperCAmelCase(   self      :     str    ):
            # If remote code is not set, we will time out when asking whether to load the model.
            with self.assertRaises(lowerCamelCase_    ):
                 a_    :     int										=    AutoImageProcessor.from_pretrained("""hf-internal-testing/test_dynamic_image_processor"""    )
            # If remote code is disabled, we can't load this config.
            with self.assertRaises(lowerCamelCase_    ):
                 a_    :     Tuple										=    AutoImageProcessor.from_pretrained(
                     """hf-internal-testing/test_dynamic_image_processor"""      ,							trust_remote_code=lowerCamelCase_    )

            a_    :     int										=    AutoImageProcessor.from_pretrained(
                """hf-internal-testing/test_dynamic_image_processor"""      ,							trust_remote_code=lowerCamelCase_    )
            self.assertEqual(image_processor.__class__.__name__      ,							"""NewImageProcessor"""    )

            # Test image processor can be reloaded.
            with tempfile.TemporaryDirectory() as tmp_dir:
                 image_processor.save_pretrained(lowerCamelCase_    )
                 a_    :     int										=    AutoImageProcessor.from_pretrained(lowerCamelCase_      ,							trust_remote_code=lowerCamelCase_    )
            self.assertEqual(reloaded_image_processor.__class__.__name__      ,							"""NewImageProcessor"""    )

       def 						UpperCAmelCase(   self      :     List[str]    ):
            try:
                 AutoConfig.register("""custom"""      ,							lowerCamelCase_    )
                 AutoImageProcessor.register(lowerCamelCase_      ,							lowerCamelCase_    )
                 # Trying to register something existing in the Transformers library will raise an error
                 with self.assertRaises(lowerCamelCase_    ):
                      AutoImageProcessor.register(lowerCamelCase_      ,							lowerCamelCase_    )

                 with tempfile.TemporaryDirectory() as tmpdirname:
                      a_    :     Dict										=    Path(lowerCamelCase_    ) / """preprocessor_config.json"""
                      a_    :     Union[str, Any]										=    Path(lowerCamelCase_    ) / """config.json"""
                      json.dump(
                          {"""feature_extractor_type""": """CLIPFeatureExtractor""", """processor_class""": """CLIPProcessor"""}      ,							open(lowerCamelCase_      ,							"""w"""    )      ,							)
                      json.dump({"""model_type""": """clip"""}      ,							open(lowerCamelCase_      ,							"""w"""    )    )

                      a_    :     str										=    CustomImageProcessor.from_pretrained(lowerCamelCase_    )

                 # Now that the config is registered, it can be used as any other config with the auto-API
                 with tempfile.TemporaryDirectory() as tmp_dir:
                      image_processor.save_pretrained(lowerCamelCase_    )
                      a_    :     Any										=    AutoImageProcessor.from_pretrained(lowerCamelCase_    )
                      self.assertIsInstance(lowerCamelCase_      ,							lowerCamelCase_    )

            finally:
                 if "custom" in CONFIG_MAPPING._extra_content:
                      del CONFIG_MAPPING._extra_content["custom"]
                 if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
                      del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):


            class   a__	(						lowerCAmelCase_    ):
                   lowerCamelCase__:     List[Any]							    =     True

            try:
                 AutoConfig.register("""custom"""      ,							lowerCamelCase_    )
                 AutoImageProcessor.register(lowerCamelCase_      ,							lowerCamelCase_    )
                 # If remote code is not set, the default is to use local
                 a_    :     Dict										=    AutoImageProcessor.from_pretrained("""hf-internal-testing/test_dynamic_image_processor"""    )
                 self.assertEqual(image_processor.__class__.__name__      ,							"""NewImageProcessor"""    )
                 self.assertTrue(image_processor.is_local    )

                 # If remote code is disabled, we load the local one.
                 a_    :     Optional[Any]										=    AutoImageProcessor.from_pretrained(
                     """hf-internal-testing/test_dynamic_image_processor"""      ,							trust_remote_code=lowerCamelCase_    )
                 self.assertEqual(image_processor.__class__.__name__      ,							"""NewImageProcessor"""    )
                 self.assertTrue(image_processor.is_local    )

                 # If remote is enabled, we load from the Hub
                 a_    :     Dict										=    AutoImageProcessor.from_pretrained(
                     """hf-internal-testing/test_dynamic_image_processor"""      ,							trust_remote_code=lowerCamelCase_    )
                 self.assertEqual(image_processor.__class__.__name__      ,							"""NewImageProcessor"""    )
                 self.assertTrue(not hasattr(lowerCamelCase_      ,							"""is_local"""    )    )

            finally:
                 if "custom" in CONFIG_MAPPING._extra_content:
                      del CONFIG_MAPPING._extra_content["custom"]
                 if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
                      del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]



