


import tempfile
import unittest

import numpy as np

from diffusers import (
    DDIMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    LMSDiscreteScheduler,
    OnnxStableDiffusionPipeline,
    PNDMScheduler,
)
from diffusers.utils.testing_utils import is_onnx_available, nightly, require_onnxruntime, require_torch_gpu

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
       import onnxruntime as ort


class 	A_ (	__UpperCamelCase ,				unittest.TestCase   ):




      '''simple docstring'''


      __snake_case 	=       """hf-internal-testing/tiny-random-OnnxStableDiffusionPipeline"""




      def 					_snake_case     (    self:	int						,				a:	Optional[int]=0    ):
       __lowerCamelCase		:							Optional[int]		 =						np.random.RandomState(a    )
       __lowerCamelCase		:							str		 =						{
           'prompt': 'A painting of a squirrel eating a burger',
           'generator': generator,
           'num_inference_steps': 2,
           'guidance_scale': 7.5,
           'output_type': 'numpy',
       }
       return inputs




      def 					_snake_case     (    self:	Dict    ):
       __lowerCamelCase		:							str		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							List[str]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Optional[Any]		 =						pipe(**a    ).images
       __lowerCamelCase		:							int		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							Dict		 =						np.array([0.6_5_0_7_2, 0.5_8_4_9_2, 0.4_8_2_1_9, 0.5_5_5_2_1, 0.5_3_1_8_0, 0.5_5_9_3_9, 0.5_0_6_9_7, 0.3_9_8_0_0, 0.4_6_4_5_5]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	Optional[Any]    ):
       __lowerCamelCase		:							List[str]		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       __lowerCamelCase		:							Dict		 =						PNDMScheduler.from_config(pipe.scheduler.config						,				skip_prk_steps=a    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Any		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Dict		 =						pipe(**a    ).images
       __lowerCamelCase		:							int		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							Optional[Any]		 =						np.array([0.6_5_8_6_3, 0.5_9_4_2_5, 0.4_9_3_2_6, 0.5_6_3_1_3, 0.5_3_8_7_5, 0.5_6_6_2_7, 0.5_1_0_6_5, 0.3_9_7_7_7, 0.4_6_3_3_0]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	Optional[int]    ):
       __lowerCamelCase		:							str		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       __lowerCamelCase		:							int		 =						LMSDiscreteScheduler.from_config(pipe.scheduler.config    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							List[str]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							List[Any]		 =						pipe(**a    ).images
       __lowerCamelCase		:							str		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							Any		 =						np.array([0.5_3_7_5_5, 0.6_0_7_8_6, 0.4_7_4_0_2, 0.4_9_4_8_8, 0.5_1_8_6_9, 0.4_9_8_1_9, 0.4_7_9_8_5, 0.3_8_9_5_7, 0.4_4_2_7_9]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	Optional[Any]    ):
       __lowerCamelCase		:							Optional[Any]		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       __lowerCamelCase		:							List[str]		 =						EulerDiscreteScheduler.from_config(pipe.scheduler.config    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Optional[int]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							List[Any]		 =						pipe(**a    ).images
       __lowerCamelCase		:							List[str]		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							Tuple		 =						np.array([0.5_3_7_5_5, 0.6_0_7_8_6, 0.4_7_4_0_2, 0.4_9_4_8_8, 0.5_1_8_6_9, 0.4_9_8_1_9, 0.4_7_9_8_5, 0.3_8_9_5_7, 0.4_4_2_7_9]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	str    ):
       __lowerCamelCase		:							List[str]		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       __lowerCamelCase		:							Union[str, Any]		 =						EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Optional[Any]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Union[str, Any]		 =						pipe(**a    ).images
       __lowerCamelCase		:							Tuple		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							int		 =						np.array([0.5_3_8_1_7, 0.6_0_8_1_2, 0.4_7_3_8_4, 0.4_9_5_3_0, 0.5_1_8_9_4, 0.4_9_8_1_4, 0.4_7_9_8_4, 0.3_8_9_5_8, 0.4_4_2_7_1]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	int    ):
       __lowerCamelCase		:							Tuple		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       __lowerCamelCase		:							int		 =						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Optional[Any]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Dict		 =						pipe(**a    ).images
       __lowerCamelCase		:							int		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 128, 128, 3)
       __lowerCamelCase		:							Union[str, Any]		 =						np.array([0.5_3_8_9_5, 0.6_0_8_0_8, 0.4_7_9_3_3, 0.4_9_6_0_8, 0.5_1_8_8_6, 0.4_9_9_5_0, 0.4_8_0_5_3, 0.3_8_9_5_7, 0.4_4_2_0_0]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-2




      def 					_snake_case     (    self:	Optional[Any]    ):
       __lowerCamelCase		:							Any		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Union[str, Any]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							str		 =						3 * [inputs['prompt']]

       # forward
       __lowerCamelCase		:							int		 =						pipe(**a    )
       __lowerCamelCase		:							List[Any]		 =						output.images[0, -3:, -3:, -1]

       __lowerCamelCase		:							Union[str, Any]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							str		 =						3 * [inputs.pop('prompt'    )]

       __lowerCamelCase		:							Union[str, Any]		 =						pipe.tokenizer(
           a						,				padding='max_length'						,				max_length=pipe.tokenizer.model_max_length						,				truncation=a						,				return_tensors='np'						,				)
       __lowerCamelCase		:							str		 =						text_inputs['input_ids']

       __lowerCamelCase		:							List[Any]		 =						pipe.text_encoder(input_ids=text_inputs.astype(np.intaa    )    )[0]

       __lowerCamelCase		:							Optional[Any]		 =						prompt_embeds

       # forward
       __lowerCamelCase		:							Optional[Any]		 =						pipe(**a    )
       __lowerCamelCase		:							Optional[int]		 =						output.images[0, -3:, -3:, -1]

       assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()    ).max() < 1e-4




      def 					_snake_case     (    self:	Any    ):
       __lowerCamelCase		:							str		 =						OnnxStableDiffusionPipeline.from_pretrained(self.hub_checkpoint						,				provider='CPUExecutionProvider'    )
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							List[str]		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Optional[int]		 =						3 * ['this is a negative prompt']
       __lowerCamelCase		:							Dict		 =						negative_prompt
       __lowerCamelCase		:							Union[str, Any]		 =						3 * [inputs['prompt']]

       # forward
       __lowerCamelCase		:							str		 =						pipe(**a    )
       __lowerCamelCase		:							List[str]		 =						output.images[0, -3:, -3:, -1]

       __lowerCamelCase		:							Dict		 =						self.get_dummy_inputs()
       __lowerCamelCase		:							Optional[int]		 =						3 * [inputs.pop('prompt'    )]

       __lowerCamelCase		:							List[Any]		 =						[]
       for p in [prompt, negative_prompt]:
        __lowerCamelCase		:							Tuple		 =						pipe.tokenizer(
            a						,				padding='max_length'						,				max_length=pipe.tokenizer.model_max_length						,				truncation=a						,				return_tensors='np'						,				)
        __lowerCamelCase		:							Union[str, Any]		 =						text_inputs['input_ids']

        embeds.append(pipe.text_encoder(input_ids=text_inputs.astype(np.intaa    )    )[0]    )

       __lowerCamelCase ,					__lowerCamelCase		:							Tuple		 =						embeds

       # forward
       __lowerCamelCase		:							Union[str, Any]		 =						pipe(**a    )
       __lowerCamelCase		:							List[Any]		 =						output.images[0, -3:, -3:, -1]

       assert np.abs(image_slice_a.flatten() - image_slice_a.flatten()    ).max() < 1e-4



@nightly
@require_onnxruntime
@require_torch_gpu
class 	A_ (	unittest.TestCase   ):




      '''simple docstring'''


      @property
      def 					_snake_case     (    self:	List[str]    ):
       return (
           "CUDAExecutionProvider",
           {
               "gpu_mem_limit": "15000000000",  # 15GB
               "arena_extend_strategy": "kSameAsRequested",
           },
       )




      @property
      def 					_snake_case     (    self:	Any    ):
       __lowerCamelCase		:							Dict		 =						ort.SessionOptions()
       __lowerCamelCase		:							int		 =						False
       return options




      def 					_snake_case     (    self:	Dict    ):
       # using the PNDM scheduler by default
       __lowerCamelCase		:							Union[str, Any]		 =						OnnxStableDiffusionPipeline.from_pretrained(
           'CompVis/stable-diffusion-v1-4'						,				revision='onnx'						,				safety_checker=a						,				feature_extractor=a						,				provider=self.gpu_provider						,				sess_options=self.gpu_options						,				)
       sd_pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Union[str, Any]		 =						'A painting of a squirrel eating a burger'
       np.random.seed(0    )
       __lowerCamelCase		:							Any		 =						sd_pipe([prompt]						,				guidance_scale=6.0						,				num_inference_steps=10						,				output_type='np'    )
       __lowerCamelCase		:							Optional[int]		 =						output.images

       __lowerCamelCase		:							Union[str, Any]		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       __lowerCamelCase		:							Dict		 =						np.array([0.0_4_5_2, 0.0_3_9_0, 0.0_0_8_7, 0.0_3_5_0, 0.0_6_1_7, 0.0_3_6_4, 0.0_5_4_4, 0.0_5_2_3, 0.0_7_2_0]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-3




      def 					_snake_case     (    self:	Any    ):
       __lowerCamelCase		:							Tuple		 =						DDIMScheduler.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				subfolder='scheduler'						,				revision='onnx'    )
       __lowerCamelCase		:							Dict		 =						OnnxStableDiffusionPipeline.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				revision='onnx'						,				scheduler=a						,				safety_checker=a						,				feature_extractor=a						,				provider=self.gpu_provider						,				sess_options=self.gpu_options						,				)
       sd_pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							List[str]		 =						'open neural network exchange'
       __lowerCamelCase		:							Union[str, Any]		 =						np.random.RandomState(0    )
       __lowerCamelCase		:							List[str]		 =						sd_pipe([prompt]						,				guidance_scale=7.5						,				num_inference_steps=10						,				generator=a						,				output_type='np'    )
       __lowerCamelCase		:							Union[str, Any]		 =						output.images
       __lowerCamelCase		:							Union[str, Any]		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       __lowerCamelCase		:							List[str]		 =						np.array([0.2_8_6_7, 0.1_9_7_4, 0.1_4_8_1, 0.7_2_9_4, 0.7_2_5_1, 0.6_6_6_7, 0.4_1_9_4, 0.5_6_4_2, 0.6_4_8_6]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-3




      def 					_snake_case     (    self:	Dict    ):
       __lowerCamelCase		:							Optional[Any]		 =						LMSDiscreteScheduler.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				subfolder='scheduler'						,				revision='onnx'    )
       __lowerCamelCase		:							List[Any]		 =						OnnxStableDiffusionPipeline.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				revision='onnx'						,				scheduler=a						,				safety_checker=a						,				feature_extractor=a						,				provider=self.gpu_provider						,				sess_options=self.gpu_options						,				)
       sd_pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Tuple		 =						'open neural network exchange'
       __lowerCamelCase		:							str		 =						np.random.RandomState(0    )
       __lowerCamelCase		:							Dict		 =						sd_pipe([prompt]						,				guidance_scale=7.5						,				num_inference_steps=10						,				generator=a						,				output_type='np'    )
       __lowerCamelCase		:							List[Any]		 =						output.images
       __lowerCamelCase		:							str		 =						image[0, -3:, -3:, -1]

       assert image.shape == (1, 512, 512, 3)
       __lowerCamelCase		:							Any		 =						np.array([0.2_3_0_6, 0.1_9_5_9, 0.1_5_9_3, 0.6_5_4_9, 0.6_3_9_4, 0.5_4_0_8, 0.5_0_6_5, 0.6_0_1_0, 0.6_1_6_1]    )

       assert np.abs(image_slice.flatten() - expected_slice    ).max() < 1e-3




      def 					_snake_case     (    self:	Any    ):
       __lowerCamelCase		:							Union[str, Any]		 =						0

       def test_callback_fn(a:	int						,				a:	int						,				a:	np.ndarray    ) -> None:
        __lowerCamelCase		:							Optional[int]		 =						True
        nonlocal number_of_steps
        number_of_steps += 1
        if step == 0:
         assert latents.shape == (1, 4, 64, 64)
         __lowerCamelCase		:							str		 =						latents[0, -3:, -3:, -1]
         __lowerCamelCase		:							Optional[int]		 =						np.array(
             [-0.6_7_7_2, -0.3_8_3_5, -1.2_4_5_6, 0.1_9_0_5, -1.0_9_7_4, 0.6_9_6_7, -1.9_3_5_3, 0.0_1_7_8, 1.0_1_6_7]    )

         assert np.abs(latents_slice.flatten() - expected_slice    ).max() < 1e-3
        elif step == 5:
         assert latents.shape == (1, 4, 64, 64)
         __lowerCamelCase		:							Tuple		 =						latents[0, -3:, -3:, -1]
         __lowerCamelCase		:							Optional[Any]		 =						np.array(
             [-0.3_3_5_1, 0.2_2_4_1, -0.1_8_3_7, -0.2_3_2_5, -0.6_5_7_7, 0.3_3_9_3, -0.0_2_4_1, 0.5_8_9_9, 1.3_8_7_5]    )

         assert np.abs(latents_slice.flatten() - expected_slice    ).max() < 1e-3

       __lowerCamelCase		:							Dict		 =						False

       __lowerCamelCase		:							int		 =						OnnxStableDiffusionPipeline.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				revision='onnx'						,				safety_checker=a						,				feature_extractor=a						,				provider=self.gpu_provider						,				sess_options=self.gpu_options						,				)
       pipe.set_progress_bar_config(disable=a    )

       __lowerCamelCase		:							Tuple		 =						'Andromeda galaxy in a bottle'

       __lowerCamelCase		:							int		 =						np.random.RandomState(0    )
       pipe(
           prompt=a						,				num_inference_steps=5						,				guidance_scale=7.5						,				generator=a						,				callback=a						,				callback_steps=1						,				)
       assert test_callback_fn.has_been_called
       assert number_of_steps == 6




      def 					_snake_case     (    self:	int    ):
       __lowerCamelCase		:							int		 =						OnnxStableDiffusionPipeline.from_pretrained(
           'runwayml/stable-diffusion-v1-5'						,				revision='onnx'						,				safety_checker=a						,				feature_extractor=a						,				provider=self.gpu_provider						,				sess_options=self.gpu_options						,				)
       assert isinstance(a						,				a    )
       assert pipe.safety_checker is None

       __lowerCamelCase		:							str		 =						pipe('example prompt'						,				num_inference_steps=2    ).images[0]
       assert image is not None

       # check that there's no error when saving a pipeline with one of the models being None
       with tempfile.TemporaryDirectory() as tmpdirname:
        pipe.save_pretrained(a    )
        __lowerCamelCase		:							Dict		 =						OnnxStableDiffusionPipeline.from_pretrained(a    )

       # sanity check that the pipeline still works
       assert pipe.safety_checker is None
       __lowerCamelCase		:							str		 =						pipe('example prompt'						,				num_inference_steps=2    ).images[0]
       assert image is not None





import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
       from ...processing_utils import ProcessorMixin
       from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase_	   =     logging.get_logger(__name__)

lowercase_	   =     {
    'google/owlvit-base-patch32': 'https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json',
    'google/owlvit-base-patch16': 'https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json',
    'google/owlvit-large-patch14': 'https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json',
}


class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """owlvit_text_model"""




      def __init__(    self:	Optional[int]						,				a:	Dict=4_9408						,				a:	Optional[Any]=512						,				a:	Dict=2048						,				a:	Optional[Any]=12						,				a:	Tuple=8						,				a:	Union[str, Any]=16						,				a:	str="quick_gelu"						,				a:	List[Any]=1e-5						,				a:	Dict=0.0						,				a:	Optional[int]=0.0_2						,				a:	Dict=1.0						,				a:	Any=0						,				a:	Union[str, Any]=4_9406						,				a:	Any=4_9407						,				**a:	Dict						,				):
       super().__init__(pad_token_id=a						,				bos_token_id=a						,				eos_token_id=a						,				**a    )

       __lowerCamelCase		:							List[Any]		 =						vocab_size
       __lowerCamelCase		:							int		 =						hidden_size
       __lowerCamelCase		:							Optional[Any]		 =						intermediate_size
       __lowerCamelCase		:							List[Any]		 =						num_hidden_layers
       __lowerCamelCase		:							Any		 =						num_attention_heads
       __lowerCamelCase		:							Union[str, Any]		 =						max_position_embeddings
       __lowerCamelCase		:							List[Any]		 =						hidden_act
       __lowerCamelCase		:							List[str]		 =						layer_norm_eps
       __lowerCamelCase		:							Tuple		 =						attention_dropout
       __lowerCamelCase		:							Optional[int]		 =						initializer_range
       __lowerCamelCase		:							Tuple		 =						initializer_factor




      @classmethod
      def 					_snake_case     (    cls:	Dict						,				a:	Union[str, os.PathLike]						,				**a:	Optional[int]    ):
       cls._set_token_in_kwargs(a    )

       __lowerCamelCase ,					__lowerCamelCase		:							Dict		 =						cls.get_config_dict(a						,				**a    )

       # get the text config dict if we are loading from OwlViTConfig
       if config_dict.get('model_type'    ) == "owlvit":
        __lowerCamelCase		:							Optional[Any]		 =						config_dict['text_config']

       if "model_type" in config_dict and hasattr(cls						,				'model_type'    ) and config_dict["model_type"] != cls.model_type:
        logger.warning(
            F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
            F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'    )

       return cls.from_dict(a						,				**a    )



class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """owlvit_vision_model"""




      def __init__(    self:	int						,				a:	Tuple=768						,				a:	int=3072						,				a:	List[str]=12						,				a:	Optional[Any]=12						,				a:	Optional[int]=3						,				a:	Optional[int]=768						,				a:	Optional[Any]=32						,				a:	Optional[int]="quick_gelu"						,				a:	Union[str, Any]=1e-5						,				a:	Union[str, Any]=0.0						,				a:	Union[str, Any]=0.0_2						,				a:	int=1.0						,				**a:	Union[str, Any]						,				):
       super().__init__(**a    )

       __lowerCamelCase		:							str		 =						hidden_size
       __lowerCamelCase		:							Tuple		 =						intermediate_size
       __lowerCamelCase		:							Dict		 =						num_hidden_layers
       __lowerCamelCase		:							Optional[Any]		 =						num_attention_heads
       __lowerCamelCase		:							int		 =						num_channels
       __lowerCamelCase		:							Optional[Any]		 =						image_size
       __lowerCamelCase		:							Tuple		 =						patch_size
       __lowerCamelCase		:							List[str]		 =						hidden_act
       __lowerCamelCase		:							Tuple		 =						layer_norm_eps
       __lowerCamelCase		:							List[Any]		 =						attention_dropout
       __lowerCamelCase		:							Tuple		 =						initializer_range
       __lowerCamelCase		:							List[Any]		 =						initializer_factor




      @classmethod
      def 					_snake_case     (    cls:	Optional[int]						,				a:	Union[str, os.PathLike]						,				**a:	int    ):
       cls._set_token_in_kwargs(a    )

       __lowerCamelCase ,					__lowerCamelCase		:							Dict		 =						cls.get_config_dict(a						,				**a    )

       # get the vision config dict if we are loading from OwlViTConfig
       if config_dict.get('model_type'    ) == "owlvit":
        __lowerCamelCase		:							Any		 =						config_dict['vision_config']

       if "model_type" in config_dict and hasattr(cls						,				'model_type'    ) and config_dict["model_type"] != cls.model_type:
        logger.warning(
            F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
            F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'    )

       return cls.from_dict(a						,				**a    )



class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      __snake_case 	=       """owlvit"""
      __snake_case 	=       True




      def __init__(    self:	Dict						,				a:	int=None						,				a:	str=None						,				a:	Tuple=512						,				a:	Tuple=2.6_5_9_2						,				a:	int=True						,				**a:	int						,				):
       super().__init__(**a    )

       if text_config is None:
        __lowerCamelCase		:							List[str]		 =						{}
        logger.info('text_config is None. Initializing the OwlViTTextConfig with default values.'    )

       if vision_config is None:
        __lowerCamelCase		:							str		 =						{}
        logger.info('vision_config is None. initializing the OwlViTVisionConfig with default values.'    )

       __lowerCamelCase		:							List[Any]		 =						OwlViTTextConfig(**a    )
       __lowerCamelCase		:							str		 =						OwlViTVisionConfig(**a    )

       __lowerCamelCase		:							Union[str, Any]		 =						projection_dim
       __lowerCamelCase		:							Tuple		 =						logit_scale_init_value
       __lowerCamelCase		:							Dict		 =						return_dict
       __lowerCamelCase		:							Tuple		 =						1.0




      @classmethod
      def 					_snake_case     (    cls:	str						,				a:	Union[str, os.PathLike]						,				**a:	List[Any]    ):
       cls._set_token_in_kwargs(a    )

       __lowerCamelCase ,					__lowerCamelCase		:							List[Any]		 =						cls.get_config_dict(a						,				**a    )

       if "model_type" in config_dict and hasattr(cls						,				'model_type'    ) and config_dict["model_type"] != cls.model_type:
        logger.warning(
            F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
            F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'    )

       return cls.from_dict(a						,				**a    )




      @classmethod
      def 					_snake_case     (    cls:	Tuple						,				a:	Dict						,				a:	Dict						,				**a:	str    ):
       __lowerCamelCase		:							List[str]		 =						{}
       __lowerCamelCase		:							List[str]		 =						text_config
       __lowerCamelCase		:							Optional[int]		 =						vision_config

       return cls.from_dict(a						,				**a    )




      def 					_snake_case     (    self:	Optional[int]    ):
       __lowerCamelCase		:							Optional[Any]		 =						copy.deepcopy(self.__dict__    )
       __lowerCamelCase		:							List[Any]		 =						self.text_config.to_dict()
       __lowerCamelCase		:							List[str]		 =						self.vision_config.to_dict()
       __lowerCamelCase		:							Optional[Any]		 =						self.__class__.model_type
       return output



class 	A_ (	__UpperCamelCase   ):




      '''simple docstring'''


      @property
      def 					_snake_case     (    self:	str    ):
       return OrderedDict(
           [
               ('input_ids', {0: 'batch', 1: 'sequence'}),
               ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
               ('attention_mask', {0: 'batch', 1: 'sequence'}),
           ]    )




      @property
      def 					_snake_case     (    self:	Dict    ):
       return OrderedDict(
           [
               ('logits_per_image', {0: 'batch'}),
               ('logits_per_text', {0: 'batch'}),
               ('text_embeds', {0: 'batch'}),
               ('image_embeds', {0: 'batch'}),
           ]    )




      @property
      def 					_snake_case     (    self:	int    ):
       return 1e-4




      def 					_snake_case     (    self:	Any						,				a:	"ProcessorMixin"						,				a:	int = -1						,				a:	int = -1						,				a:	Optional["TensorType"] = None						,				):
       __lowerCamelCase		:							List[str]		 =						super().generate_dummy_inputs(
           processor.tokenizer						,				batch_size=a						,				seq_length=a						,				framework=a    )
       __lowerCamelCase		:							int		 =						super().generate_dummy_inputs(
           processor.image_processor						,				batch_size=a						,				framework=a    )
       return {**text_input_dict, **image_input_dict}




      @property
      def 					_snake_case     (    self:	int    ):
       return 14

