





'''simple docstring'''




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      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	'''pix2struct_text_model'''
					SCREAMING_SNAKE_CASE__				=	['''past_key_values''']
					SCREAMING_SNAKE_CASE__				=	{
					    '''hidden_size''': '''hidden_size''',
					    '''num_attention_heads''': '''num_heads''',
					    '''num_hidden_layers''': '''num_layers''',
					}


					def __init__(						self				:			int      ,						lowerCamelCase_				:			Optional[Any]=5_02_44      ,						lowerCamelCase_				:			Tuple=7_68      ,						lowerCamelCase_				:			int=64      ,						lowerCamelCase_				:			Tuple=20_48      ,						lowerCamelCase_				:			List[Any]=12      ,						lowerCamelCase_				:			Dict=12      ,						lowerCamelCase_				:			Union[str, Any]=32      ,						lowerCamelCase_				:			str=1_28      ,						lowerCamelCase_				:			List[Any]=0.1      ,						lowerCamelCase_				:			List[Any]=1e-6      ,						lowerCamelCase_				:			List[Any]=1.0      ,						lowerCamelCase_				:			Optional[int]="gelu_new"      ,						lowerCamelCase_				:			Any=0      ,						lowerCamelCase_				:			Optional[int]=False      ,						lowerCamelCase_				:			Tuple=0      ,						lowerCamelCase_				:			Tuple=1      ,						lowerCamelCase_				:			int=False      ,						lowerCamelCase_				:			int=True      ,						**lowerCamelCase_				:			Union[str, Any]      ,						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			vocab_size
							SCREAMING_SNAKE_CASE :				Optional[int]		=			hidden_size
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			d_kv
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			d_ff
							SCREAMING_SNAKE_CASE :				str		=			num_layers
							SCREAMING_SNAKE_CASE :				Optional[int]		=			num_heads
							SCREAMING_SNAKE_CASE :				Dict		=			relative_attention_num_buckets
							SCREAMING_SNAKE_CASE :				Any		=			relative_attention_max_distance
							SCREAMING_SNAKE_CASE :				Optional[int]		=			dropout_rate
							SCREAMING_SNAKE_CASE :				Optional[int]		=			layer_norm_epsilon
							SCREAMING_SNAKE_CASE :				Any		=			initializer_factor
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			use_cache

							SCREAMING_SNAKE_CASE :				Tuple		=			eos_token_id
							SCREAMING_SNAKE_CASE :				Any		=			decoder_start_token_id

							# for backwards compatibility
							SCREAMING_SNAKE_CASE :				int		=			dense_act_fn

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



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

							'''simple docstring'''



							cls._set_token_in_kwargs(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Optional[Any]		=			cls.get_config_dict(lowerCamelCase_      ,						**lowerCamelCase_						)

							# get the text config dict if we are loading from Pix2StructConfig
							if config_dict.get("""model_type"""						) == "pix2struct":
									SCREAMING_SNAKE_CASE :				List[str]		=			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(lowerCamelCase_      ,						**lowerCamelCase_						)







class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	'''pix2struct_vision_model'''


					def __init__(						self				:			List[str]      ,						lowerCamelCase_				:			Optional[Any]=7_68      ,						lowerCamelCase_				:			str=7_68      ,						lowerCamelCase_				:			Dict=20_48      ,						lowerCamelCase_				:			Tuple=64      ,						lowerCamelCase_				:			str=12      ,						lowerCamelCase_				:			Any=12      ,						lowerCamelCase_				:			str="gelu_new"      ,						lowerCamelCase_				:			Optional[Any]=1e-6      ,						lowerCamelCase_				:			List[Any]=0.0      ,						lowerCamelCase_				:			Optional[int]=0.0      ,						lowerCamelCase_				:			Tuple=1e-10      ,						lowerCamelCase_				:			Dict=1.0      ,						lowerCamelCase_				:			Optional[int]=40_96      ,						lowerCamelCase_				:			Optional[Any]=32      ,						lowerCamelCase_				:			int=1_28      ,						**lowerCamelCase_				:			Any      ,						):

							'''simple docstring'''



							super().__init__(**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Dict		=			hidden_size
							SCREAMING_SNAKE_CASE :				int		=			patch_embed_hidden_size
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			d_ff
							SCREAMING_SNAKE_CASE :				Dict		=			dropout_rate
							SCREAMING_SNAKE_CASE :				Dict		=			num_hidden_layers
							SCREAMING_SNAKE_CASE :				int		=			num_attention_heads
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			initializer_range
							SCREAMING_SNAKE_CASE :				List[Any]		=			initializer_factor
							SCREAMING_SNAKE_CASE :				Dict		=			attention_dropout
							SCREAMING_SNAKE_CASE :				Optional[int]		=			layer_norm_eps
							SCREAMING_SNAKE_CASE :				Dict		=			dense_act_fn
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			seq_len
							SCREAMING_SNAKE_CASE :				int		=			relative_attention_num_buckets
							SCREAMING_SNAKE_CASE :				Optional[int]		=			relative_attention_max_distance
							SCREAMING_SNAKE_CASE :				Dict		=			d_kv



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

							'''simple docstring'''



							cls._set_token_in_kwargs(lowerCamelCase_						)

							SCREAMING_SNAKE_CASE,							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			cls.get_config_dict(lowerCamelCase_      ,						**lowerCamelCase_						)

							# get the vision config dict if we are loading from Pix2StructConfig
							if config_dict.get("""model_type"""						) == "pix2struct":
									SCREAMING_SNAKE_CASE :				Union[str, 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(lowerCamelCase_      ,						**lowerCamelCase_						)







class      UpperCamelCase__					(					lowercase_			):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__				=	'''pix2struct'''
					SCREAMING_SNAKE_CASE__				=	True


					def __init__(						self				:			Optional[Any]      ,						lowerCamelCase_				:			List[str]=None      ,						lowerCamelCase_				:			List[Any]=None      ,						lowerCamelCase_				:			Optional[Any]=1.0      ,						lowerCamelCase_				:			Dict=0.02      ,						lowerCamelCase_				:			Optional[Any]=False      ,						lowerCamelCase_				:			Tuple=False      ,						lowerCamelCase_				:			Dict=True      ,						**lowerCamelCase_				:			Any      ,						):

							'''simple docstring'''



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

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

							if vision_config is None:
									SCREAMING_SNAKE_CASE :				Union[str, Any]		=			{}
									logger.info("""vision_config is None. Initializing the Pix2StructVisionConfig with default values."""						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			PixaStructTextConfig(**lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Dict		=			PixaStructVisionConfig(**lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.text_config.decoder_start_token_id
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.text_config.pad_token_id
							SCREAMING_SNAKE_CASE :				Any		=			self.text_config.eos_token_id

							SCREAMING_SNAKE_CASE :				Dict		=			initializer_factor
							SCREAMING_SNAKE_CASE :				Tuple		=			initializer_range

							SCREAMING_SNAKE_CASE :				Tuple		=			self.initializer_range
							SCREAMING_SNAKE_CASE :				str		=			self.initializer_range

							SCREAMING_SNAKE_CASE :				Any		=			is_vqa


					@classmethod
					def lowerCamelCase_			(						cls				:			Optional[int]      ,						lowerCamelCase_				:			PixaStructTextConfig      ,						lowerCamelCase_				:			PixaStructVisionConfig      ,						**lowerCamelCase_				:			Dict						):

							'''simple docstring'''



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



					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			copy.deepcopy(self.__dict__						)
							SCREAMING_SNAKE_CASE :				str		=			self.text_config.to_dict()
							SCREAMING_SNAKE_CASE :				Tuple		=			self.vision_config.to_dict()
							SCREAMING_SNAKE_CASE :				Tuple		=			self.__class__.model_type
							return output










'''simple docstring'''




__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



