



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


SCREAMING_SNAKE_CASE__       =      logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__       =      {
    '''microsoft/trocr-base-handwritten''': (
        '''https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json'''
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}


class      __lowerCAmelCase     (		UpperCAmelCase_      ):
					"""simple docstring"""






					A__				:		Dict			       =    "trocr"
					A__				:		List[Any]			       =    ["past_key_values"]
					A__				:		List[Any]			       =    {
					    "num_attention_heads": "decoder_attention_heads",
					    "hidden_size": "d_model",
					    "num_hidden_layers": "decoder_layers",
					}



					def __init__(     self					:       Tuple				,					_snake_case					:       Any=5_02_65				,					_snake_case					:       Optional[Any]=10_24				,					_snake_case					:       List[Any]=12				,					_snake_case					:       List[Any]=16				,					_snake_case					:       str=40_96				,					_snake_case					:       List[str]="gelu"				,					_snake_case					:       List[Any]=5_12				,					_snake_case					:       Dict=0.1				,					_snake_case					:       Any=0.0				,					_snake_case					:       str=0.0				,					_snake_case					:       List[str]=2				,					_snake_case					:       Tuple=0.02				,					_snake_case					:       int=0.0				,					_snake_case					:       Dict=True				,					_snake_case					:       List[str]=False				,					_snake_case					:       Optional[int]=True				,					_snake_case					:       Any=True				,					_snake_case					:       List[Any]=1				,					_snake_case					:       List[Any]=0				,					_snake_case					:       Union[str, Any]=2				,					**_snake_case					:       Optional[int]				,					):






								"""simple docstring"""


								A__       =    vocab_size
								A__       =    d_model
								A__       =    decoder_layers
								A__       =    decoder_attention_heads
								A__       =    decoder_ffn_dim
								A__       =    activation_function
								A__       =    max_position_embeddings
								A__       =    dropout
								A__       =    attention_dropout
								A__       =    activation_dropout
								A__       =    init_std
								A__       =    decoder_layerdrop
								A__       =    use_cache
								A__       =    scale_embedding
								A__       =    use_learned_position_embeddings
								A__       =    layernorm_embedding

								super().__init__(
								    pad_token_id=_snake_case				,					bos_token_id=_snake_case				,					eos_token_id=_snake_case				,					decoder_start_token_id=_snake_case				,					**_snake_case				,					)









import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin


@skip_mps
class      __lowerCAmelCase     (		UpperCAmelCase_							,     UpperCAmelCase_							,     unittest.TestCase      ):
					"""simple docstring"""






					A__				:		Any			       =    IFInpaintingPipeline
					A__				:		Dict			       =    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
					A__				:		List[Any]			       =    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
					A__				:		Dict			       =    PipelineTesterMixin.required_optional_params - {"latents"}



					def     _a							(     self					:       Any					):






								"""simple docstring"""


								return self._get_dummy_components()



					def     _a							(     self					:       Optional[int]				,					_snake_case					:       Any				,					_snake_case					:       str=0					):






								"""simple docstring"""


								if str(_snake_case					).startswith('mps'					):
											A__       =    torch.manual_seed(_snake_case					)
								else:
											A__       =    torch.Generator(device=_snake_case					).manual_seed(_snake_case					)

								A__       =    floats_tensor((1, 3, 32, 32)				,					rng=random.Random(_snake_case					)					).to(_snake_case					)
								A__       =    floats_tensor((1, 3, 32, 32)				,					rng=random.Random(_snake_case					)					).to(_snake_case					)

								A__       =    {
								    'prompt': 'A painting of a squirrel eating a burger',
								    'image': image,
								    'mask_image': mask_image,
								    'generator': generator,
								    'num_inference_steps': 2,
								    'output_type': 'numpy',
								}

								return inputs



					@unittest.skipIf(
					    torch_device != 'cuda' or not is_xformers_available()				,					reason='XFormers attention is only available with CUDA and `xformers` installed'				,					)
					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3					)



					def     _a							(     self					:       int					):






								"""simple docstring"""


								self._test_save_load_optional_components()



					@unittest.skipIf(torch_device != 'cuda'				,					reason='float16 requires CUDA'					)
					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								super().test_save_load_floataa(expected_max_diff=1E-1					)



					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


								self._test_attention_slicing_forward_pass(expected_max_diff=1E-2					)



					def     _a							(     self					:       Dict					):






								"""simple docstring"""


								self._test_save_load_local()



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								self._test_inference_batch_single_identical(
								    expected_max_diff=1E-2				,					)




