




import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__         =      logging.get_logger(__name__)

UpperCamelCase__         =      {
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}
class       a__   ( snake_case__				):
						_a							:   Any =   """pix2struct_text_model"""
						_a							:   List[str] =   ["""past_key_values"""]
						_a							:   Union[str, Any] =   {
						    """hidden_size""": """hidden_size""",
						    """num_attention_heads""": """num_heads""",
						    """num_hidden_layers""": """num_layers""",
						}






						def __init__(       self		,      _A=5_0_2_4_4		,      _A=7_6_8		,      _A=6_4		,      _A=2_0_4_8		,      _A=1_2		,      _A=1_2		,      _A=3_2		,      _A=1_2_8		,      _A=0.1		,      _A=1E-6		,      _A=1.0		,      _A="gelu_new"		,      _A=0		,      _A=False		,      _A=0		,      _A=1		,      _A=False		,      _A=True		,      **_A		,      ):




											"""simple docstring"""



											__lowerCAmelCase           =	vocab_size
											__lowerCAmelCase           =	hidden_size
											__lowerCAmelCase           =	d_kv
											__lowerCAmelCase           =	d_ff
											__lowerCAmelCase           =	num_layers
											__lowerCAmelCase           =	num_heads
											__lowerCAmelCase           =	relative_attention_num_buckets
											__lowerCAmelCase           =	relative_attention_max_distance
											__lowerCAmelCase           =	dropout_rate
											__lowerCAmelCase           =	layer_norm_epsilon
											__lowerCAmelCase           =	initializer_factor
											__lowerCAmelCase           =	use_cache

											__lowerCAmelCase           =	eos_token_id
											__lowerCAmelCase           =	decoder_start_token_id

											# for backwards compatibility
											__lowerCAmelCase           =	dense_act_fn

											super().__init__(
											    pad_token_id=_A		,      eos_token_id=_A		,      decoder_start_token_id=_A		,      tie_word_embeddings=_A		,      is_decoder=_A		,      **_A		,      )






						@classmethod
						def     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      **_A      ):




											"""simple docstring"""



											cls._set_token_in_kwargs(_A      )

											__lowerCAmelCase       ,							__lowerCAmelCase           =	cls.get_config_dict(_A		,      **_A      )

											# get the text config dict if we are loading from Pix2StructConfig
											if config_dict.get("model_type"      ) == "pix2struct":
																__lowerCAmelCase           =	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__   ( snake_case__				):
						_a							:   int =   """pix2struct_vision_model"""






						def __init__(       self		,      _A=7_6_8		,      _A=7_6_8		,      _A=2_0_4_8		,      _A=6_4		,      _A=1_2		,      _A=1_2		,      _A="gelu_new"		,      _A=1E-6		,      _A=0.0		,      _A=0.0		,      _A=1E-1_0		,      _A=1.0		,      _A=4_0_9_6		,      _A=3_2		,      _A=1_2_8		,      **_A		,      ):




											"""simple docstring"""



											super().__init__(**_A      )

											__lowerCAmelCase           =	hidden_size
											__lowerCAmelCase           =	patch_embed_hidden_size
											__lowerCAmelCase           =	d_ff
											__lowerCAmelCase           =	dropout_rate
											__lowerCAmelCase           =	num_hidden_layers
											__lowerCAmelCase           =	num_attention_heads
											__lowerCAmelCase           =	initializer_range
											__lowerCAmelCase           =	initializer_factor
											__lowerCAmelCase           =	attention_dropout
											__lowerCAmelCase           =	layer_norm_eps
											__lowerCAmelCase           =	dense_act_fn
											__lowerCAmelCase           =	seq_len
											__lowerCAmelCase           =	relative_attention_num_buckets
											__lowerCAmelCase           =	relative_attention_max_distance
											__lowerCAmelCase           =	d_kv






						@classmethod
						def     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      **_A      ):




											"""simple docstring"""



											cls._set_token_in_kwargs(_A      )

											__lowerCAmelCase       ,							__lowerCAmelCase           =	cls.get_config_dict(_A		,      **_A      )

											# get the vision config dict if we are loading from Pix2StructConfig
											if config_dict.get("model_type"      ) == "pix2struct":
																__lowerCAmelCase           =	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__   ( snake_case__				):
						_a							:   Any =   """pix2struct"""
						_a							:   List[str] =   True






						def __init__(       self		,      _A=None		,      _A=None		,      _A=1.0		,      _A=0.02		,      _A=False		,      _A=False		,      _A=True		,      **_A		,      ):




											"""simple docstring"""



											super().__init__(tie_word_embeddings=_A		,      is_encoder_decoder=_A		,      **_A      )

											if text_config is None:
																__lowerCAmelCase           =	{}
																logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."      )

											if vision_config is None:
																__lowerCAmelCase           =	{}
																logger.info("vision_config is None. Initializing the Pix2StructVisionConfig with default values."      )

											__lowerCAmelCase           =	PixaStructTextConfig(**_A      )
											__lowerCAmelCase           =	PixaStructVisionConfig(**_A      )

											__lowerCAmelCase           =	self.text_config.decoder_start_token_id
											__lowerCAmelCase           =	self.text_config.pad_token_id
											__lowerCAmelCase           =	self.text_config.eos_token_id

											__lowerCAmelCase           =	initializer_factor
											__lowerCAmelCase           =	initializer_range

											__lowerCAmelCase           =	self.initializer_range
											__lowerCAmelCase           =	self.initializer_range

											__lowerCAmelCase           =	is_vqa






						@classmethod
						def     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      _A		,      **_A      ):




											"""simple docstring"""



											return cls(text_config=text_config.to_dict()		,      vision_config=vision_config.to_dict()		,      **_A      )






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



											__lowerCAmelCase           =	copy.deepcopy(self.__dict__      )
											__lowerCAmelCase           =	self.text_config.to_dict()
											__lowerCAmelCase           =	self.vision_config.to_dict()
											__lowerCAmelCase           =	self.__class__.model_type
											return output










UpperCamelCase__         =      """0.18.2"""

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
					if not is_onnx_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_onnx_objects import *  # noqa F403
else:
					from .pipelines import OnnxRuntimeModel

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_pt_objects import *  # noqa F403
else:
					from .models import (
					    AutoencoderKL,
					    ControlNetModel,
					    ModelMixin,
					    PriorTransformer,
					    TaFilmDecoder,
					    TransformeraDModel,
					    UNetaDModel,
					    UNetaDConditionModel,
					    UNetaDModel,
					    UNetaDConditionModel,
					    VQModel,
					)
					from .optimization import (
					    get_constant_schedule,
					    get_constant_schedule_with_warmup,
					    get_cosine_schedule_with_warmup,
					    get_cosine_with_hard_restarts_schedule_with_warmup,
					    get_linear_schedule_with_warmup,
					    get_polynomial_decay_schedule_with_warmup,
					    get_scheduler,
					)
					from .pipelines import (
					    AudioPipelineOutput,
					    ConsistencyModelPipeline,
					    DanceDiffusionPipeline,
					    DDIMPipeline,
					    DDPMPipeline,
					    DiffusionPipeline,
					    DiTPipeline,
					    ImagePipelineOutput,
					    KarrasVePipeline,
					    LDMPipeline,
					    LDMSuperResolutionPipeline,
					    PNDMPipeline,
					    RePaintPipeline,
					    ScoreSdeVePipeline,
					)
					from .schedulers import (
					    CMStochasticIterativeScheduler,
					    DDIMInverseScheduler,
					    DDIMParallelScheduler,
					    DDIMScheduler,
					    DDPMParallelScheduler,
					    DDPMScheduler,
					    DEISMultistepScheduler,
					    DPMSolverMultistepInverseScheduler,
					    DPMSolverMultistepScheduler,
					    DPMSolverSinglestepScheduler,
					    EulerAncestralDiscreteScheduler,
					    EulerDiscreteScheduler,
					    HeunDiscreteScheduler,
					    IPNDMScheduler,
					    KarrasVeScheduler,
					    KDPMaAncestralDiscreteScheduler,
					    KDPMaDiscreteScheduler,
					    PNDMScheduler,
					    RePaintScheduler,
					    SchedulerMixin,
					    ScoreSdeVeScheduler,
					    UnCLIPScheduler,
					    UniPCMultistepScheduler,
					    VQDiffusionScheduler,
					)
					from .training_utils import EMAModel

try:
					if not (is_torch_available() and is_scipy_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
					from .schedulers import LMSDiscreteScheduler

try:
					if not (is_torch_available() and is_torchsde_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
					from .schedulers import DPMSolverSDEScheduler

try:
					if not (is_torch_available() and is_transformers_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
					from .pipelines import (
					    AltDiffusionImgaImgPipeline,
					    AltDiffusionPipeline,
					    AudioLDMPipeline,
					    CycleDiffusionPipeline,
					    IFImgaImgPipeline,
					    IFImgaImgSuperResolutionPipeline,
					    IFInpaintingPipeline,
					    IFInpaintingSuperResolutionPipeline,
					    IFPipeline,
					    IFSuperResolutionPipeline,
					    ImageTextPipelineOutput,
					    KandinskyImgaImgPipeline,
					    KandinskyInpaintPipeline,
					    KandinskyPipeline,
					    KandinskyPriorPipeline,
					    KandinskyVaaControlnetImgaImgPipeline,
					    KandinskyVaaControlnetPipeline,
					    KandinskyVaaImgaImgPipeline,
					    KandinskyVaaInpaintPipeline,
					    KandinskyVaaPipeline,
					    KandinskyVaaPriorEmbaEmbPipeline,
					    KandinskyVaaPriorPipeline,
					    LDMTextToImagePipeline,
					    PaintByExamplePipeline,
					    SemanticStableDiffusionPipeline,
					    ShapEImgaImgPipeline,
					    ShapEPipeline,
					    StableDiffusionAttendAndExcitePipeline,
					    StableDiffusionControlNetImgaImgPipeline,
					    StableDiffusionControlNetInpaintPipeline,
					    StableDiffusionControlNetPipeline,
					    StableDiffusionDepthaImgPipeline,
					    StableDiffusionDiffEditPipeline,
					    StableDiffusionImageVariationPipeline,
					    StableDiffusionImgaImgPipeline,
					    StableDiffusionInpaintPipeline,
					    StableDiffusionInpaintPipelineLegacy,
					    StableDiffusionInstructPixaPixPipeline,
					    StableDiffusionLatentUpscalePipeline,
					    StableDiffusionLDMaDPipeline,
					    StableDiffusionModelEditingPipeline,
					    StableDiffusionPanoramaPipeline,
					    StableDiffusionParadigmsPipeline,
					    StableDiffusionPipeline,
					    StableDiffusionPipelineSafe,
					    StableDiffusionPixaPixZeroPipeline,
					    StableDiffusionSAGPipeline,
					    StableDiffusionUpscalePipeline,
					    StableUnCLIPImgaImgPipeline,
					    StableUnCLIPPipeline,
					    TextToVideoSDPipeline,
					    TextToVideoZeroPipeline,
					    UnCLIPImageVariationPipeline,
					    UnCLIPPipeline,
					    UniDiffuserModel,
					    UniDiffuserPipeline,
					    UniDiffuserTextDecoder,
					    VersatileDiffusionDualGuidedPipeline,
					    VersatileDiffusionImageVariationPipeline,
					    VersatileDiffusionPipeline,
					    VersatileDiffusionTextToImagePipeline,
					    VideoToVideoSDPipeline,
					    VQDiffusionPipeline,
					)

try:
					if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
					from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
					if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
					from .pipelines import StableDiffusionKDiffusionPipeline

try:
					if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
					from .pipelines import (
					    OnnxStableDiffusionImgaImgPipeline,
					    OnnxStableDiffusionInpaintPipeline,
					    OnnxStableDiffusionInpaintPipelineLegacy,
					    OnnxStableDiffusionPipeline,
					    OnnxStableDiffusionUpscalePipeline,
					    StableDiffusionOnnxPipeline,
					)

try:
					if not (is_torch_available() and is_librosa_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
					from .pipelines import AudioDiffusionPipeline, Mel

try:
					if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
					from .pipelines import SpectrogramDiffusionPipeline

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_flax_objects import *  # noqa F403
else:
					from .models.controlnet_flax import FlaxControlNetModel
					from .models.modeling_flax_utils import FlaxModelMixin
					from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
					from .models.vae_flax import FlaxAutoencoderKL
					from .pipelines import FlaxDiffusionPipeline
					from .schedulers import (
					    FlaxDDIMScheduler,
					    FlaxDDPMScheduler,
					    FlaxDPMSolverMultistepScheduler,
					    FlaxKarrasVeScheduler,
					    FlaxLMSDiscreteScheduler,
					    FlaxPNDMScheduler,
					    FlaxSchedulerMixin,
					    FlaxScoreSdeVeScheduler,
					)


try:
					if not (is_flax_available() and is_transformers_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
					from .pipelines import (
					    FlaxStableDiffusionControlNetPipeline,
					    FlaxStableDiffusionImgaImgPipeline,
					    FlaxStableDiffusionInpaintPipeline,
					    FlaxStableDiffusionPipeline,
					)

try:
					if not (is_note_seq_available()):
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					from .utils.dummy_note_seq_objects import *  # noqa F403
else:
					from .pipelines import MidiProcessor




