






from collections import OrderedDict
from typing import Mapping

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


_a      	=  logging.get_logger(__name__)

_a      	=  {
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""






	UpperCamelCase__								=      "xlm"
	UpperCamelCase__								=      {
	    "hidden_size": "emb_dim",
	    "num_attention_heads": "n_heads",
	    "num_hidden_layers": "n_layers",
	    "n_words": "vocab_size",  # For backward compatibility
	}

	def __init__(							self       ,    UpperCAmelCase=3_0145       ,    UpperCAmelCase=2048       ,    UpperCAmelCase=12       ,    UpperCAmelCase=16       ,    UpperCAmelCase=0.1       ,    UpperCAmelCase=0.1       ,    UpperCAmelCase=True       ,    UpperCAmelCase=False       ,    UpperCAmelCase=False       ,    UpperCAmelCase=False       ,    UpperCAmelCase=1       ,    UpperCAmelCase=True       ,    UpperCAmelCase=512       ,    UpperCAmelCase=2048**-0.5       ,    UpperCAmelCase=1e-12       ,    UpperCAmelCase=0.02       ,    UpperCAmelCase=0       ,    UpperCAmelCase=1       ,    UpperCAmelCase=2       ,    UpperCAmelCase=3       ,    UpperCAmelCase=5       ,    UpperCAmelCase=True       ,    UpperCAmelCase="first"       ,    UpperCAmelCase=True       ,    UpperCAmelCase=None       ,    UpperCAmelCase=True       ,    UpperCAmelCase=0.1       ,    UpperCAmelCase=5       ,    UpperCAmelCase=5       ,    UpperCAmelCase=0       ,    UpperCAmelCase=0       ,    UpperCAmelCase=2       ,    UpperCAmelCase=0       ,    **UpperCAmelCase       ,    ):
							"""simple docstring"""







							_UpperCAmelCase									=			vocab_size
							_UpperCAmelCase									=			emb_dim
							_UpperCAmelCase									=			n_layers
							_UpperCAmelCase									=			n_heads
							_UpperCAmelCase									=			dropout
							_UpperCAmelCase									=			attention_dropout
							_UpperCAmelCase									=			gelu_activation
							_UpperCAmelCase									=			sinusoidal_embeddings
							_UpperCAmelCase									=			causal
							_UpperCAmelCase									=			asm
							_UpperCAmelCase									=			n_langs
							_UpperCAmelCase									=			use_lang_emb
							_UpperCAmelCase									=			layer_norm_eps
							_UpperCAmelCase									=			bos_index
							_UpperCAmelCase									=			eos_index
							_UpperCAmelCase									=			pad_index
							_UpperCAmelCase									=			unk_index
							_UpperCAmelCase									=			mask_index
							_UpperCAmelCase									=			is_encoder
							_UpperCAmelCase									=			max_position_embeddings
							_UpperCAmelCase									=			embed_init_std
							_UpperCAmelCase									=			init_std
							_UpperCAmelCase									=			summary_type
							_UpperCAmelCase									=			summary_use_proj
							_UpperCAmelCase									=			summary_activation
							_UpperCAmelCase									=			summary_proj_to_labels
							_UpperCAmelCase									=			summary_first_dropout
							_UpperCAmelCase									=			start_n_top
							_UpperCAmelCase									=			end_n_top
							_UpperCAmelCase									=			mask_token_id
							_UpperCAmelCase									=			lang_id

							if "n_words" in kwargs:
													_UpperCAmelCase									=			kwargs['n_words']

							super().__init__(pad_token_id=UpperCAmelCase       ,    bos_token_id=UpperCAmelCase       ,    **UpperCAmelCase    )





class __lowerCamelCase (      snake_case__):





	"""simple docstring"""






	@property
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							if self.task == "multiple-choice":
													_UpperCAmelCase									=			{0: 'batch', 1: 'choice', 2: 'sequence'}
							else:
													_UpperCAmelCase									=			{0: 'batch', 1: 'sequence'}
							return OrderedDict(
							    [
							        ('input_ids', dynamic_axis),
							        ('attention_mask', dynamic_axis),
							        ('token_type_ids', dynamic_axis),
							    ]    )





"""simple docstring"""
import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin
@skip_mps
class 							_UpperCAmelCase							( a		,a		,unittest.TestCase      ):





     '''simple docstring'''



     a__									=IFImgaImgSuperResolutionPipeline
     a__									=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
     a__									=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}      )
     a__									=PipelineTesterMixin.required_optional_params - {'''latents'''}





     def  __lowerCAmelCase	(					self		)							->					List[str]:
         return self._get_superresolution_dummy_components()





     def  __lowerCAmelCase	(					self       ,	A       ,	A=0		)							->					Union[str, Any]:
         if str(A		).startswith('''mps'''		):
             _UpperCAmelCase							:  Any											=    torch.manual_seed(A		)
         else:
             _UpperCAmelCase							:  int											=    torch.Generator(device=A		).manual_seed(A		)

         _UpperCAmelCase							:  str											=    floats_tensor((1, 3, 3_2, 3_2)       ,	rng=random.Random(A		)		).to(A		)
         _UpperCAmelCase							:  Dict											=    floats_tensor((1, 3, 1_6, 1_6)       ,	rng=random.Random(A		)		).to(A		)

         _UpperCAmelCase							:  List[Any]											=    {
             '''prompt''': '''A painting of a squirrel eating a burger''',
             '''image''': image,
             '''original_image''': original_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  __lowerCAmelCase	(					self		)							->					List[Any]:
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)





     def  __lowerCAmelCase	(					self		)							->					List[str]:
         self._test_save_load_optional_components()





     @unittest.skipIf(torch_device != '''cuda'''       ,	reason='''float16 requires CUDA'''		)
     def  __lowerCAmelCase	(					self		)							->					Optional[Any]:
         # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
         super().test_save_load_floataa(expected_max_diff=1E-1		)





     def  __lowerCAmelCase	(					self		)							->					int:
         self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)





     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         self._test_save_load_local()





     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         self._test_inference_batch_single_identical(
             expected_max_diff=1E-2       ,	)


