






import warnings

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


__snake_case												=  logging.get_logger(__name__)

__snake_case												=  {
    '''xlnet-base-cased''': '''https://huggingface.co/xlnet-base-cased/resolve/main/config.json''',
    '''xlnet-large-cased''': '''https://huggingface.co/xlnet-large-cased/resolve/main/config.json''',
}







class 			UpperCAmelCase_						(					UpperCamelCase_ ):



      """simple docstring"""
      UpperCamelCase_				:					str           ='xlnet'
      UpperCamelCase_				:					str           =['mems']
      UpperCamelCase_				:					List[Any]           ={
          'n_token': 'vocab_size',  # Backward compatibility
          'hidden_size': 'd_model',
          'num_attention_heads': 'n_head',
          'num_hidden_layers': 'n_layer',
      }
      def __init__(				self    ,				SCREAMING_SNAKE_CASE_=3_2000    ,				SCREAMING_SNAKE_CASE_=1024    ,				SCREAMING_SNAKE_CASE_=24    ,				SCREAMING_SNAKE_CASE_=16    ,				SCREAMING_SNAKE_CASE_=4096    ,				SCREAMING_SNAKE_CASE_="gelu"    ,				SCREAMING_SNAKE_CASE_=True    ,				SCREAMING_SNAKE_CASE_="bi"    ,				SCREAMING_SNAKE_CASE_=0.02    ,				SCREAMING_SNAKE_CASE_=1e-12    ,				SCREAMING_SNAKE_CASE_=0.1    ,				SCREAMING_SNAKE_CASE_=512    ,				SCREAMING_SNAKE_CASE_=None    ,				SCREAMING_SNAKE_CASE_=True    ,				SCREAMING_SNAKE_CASE_=False    ,				SCREAMING_SNAKE_CASE_=False    ,				SCREAMING_SNAKE_CASE_=-1    ,				SCREAMING_SNAKE_CASE_=False    ,				SCREAMING_SNAKE_CASE_="last"    ,				SCREAMING_SNAKE_CASE_=True    ,				SCREAMING_SNAKE_CASE_="tanh"    ,				SCREAMING_SNAKE_CASE_=0.1    ,				SCREAMING_SNAKE_CASE_=5    ,				SCREAMING_SNAKE_CASE_=5    ,				SCREAMING_SNAKE_CASE_=5    ,				SCREAMING_SNAKE_CASE_=1    ,				SCREAMING_SNAKE_CASE_=2    ,				**SCREAMING_SNAKE_CASE_    ,				)				->      Optional[Any]:
          UpperCamelCase       :Dict								=   vocab_size
          UpperCamelCase       :Optional[int]								=   d_model
          UpperCamelCase       :Tuple								=   n_layer
          UpperCamelCase       :str								=   n_head
          if d_model % n_head != 0:
              raise ValueError(F'''\'d_model % n_head\' ({d_model % n_head}) should be equal to 0''' )
          if "d_head" in kwargs:
              if kwargs["d_head"] != d_model // n_head:
                  raise ValueError(
                      F'''`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})''' )
          UpperCamelCase       :Optional[int]								=   d_model // n_head
          UpperCamelCase       :str								=   ff_activation
          UpperCamelCase       :int								=   d_inner
          UpperCamelCase       :List[str]								=   untie_r
          UpperCamelCase       :Dict								=   attn_type

          UpperCamelCase       :Union[str, Any]								=   initializer_range
          UpperCamelCase       :Tuple								=   layer_norm_eps

          UpperCamelCase       :Union[str, Any]								=   dropout
          UpperCamelCase       :Tuple								=   mem_len
          UpperCamelCase       :Union[str, Any]								=   reuse_len
          UpperCamelCase       :str								=   bi_data
          UpperCamelCase       :str								=   clamp_len
          UpperCamelCase       :Any								=   same_length

          UpperCamelCase       :Union[str, Any]								=   summary_type
          UpperCamelCase       :str								=   summary_use_proj
          UpperCamelCase       :str								=   summary_activation
          UpperCamelCase       :List[Any]								=   summary_last_dropout
          UpperCamelCase       :int								=   start_n_top
          UpperCamelCase       :Optional[int]								=   end_n_top

          UpperCamelCase       :Union[str, Any]								=   bos_token_id
          UpperCamelCase       :Tuple								=   pad_token_id
          UpperCamelCase       :Optional[int]								=   eos_token_id

          if "use_cache" in kwargs:
              warnings.warn(
                  '''The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'''
                  ''' instead.'''    ,				A_    ,				)
              UpperCamelCase       :str								=   kwargs['''use_cache''']

          UpperCamelCase       :Optional[int]								=   use_mems_eval
          UpperCamelCase       :str								=   use_mems_train
          super().__init__(pad_token_id=A_    ,				bos_token_id=A_    ,				eos_token_id=A_    ,				**A_ )
      @property
      def     UpperCAmelCase						(				self )				->      Dict:
          logger.info(F'''The model {self.model_type} is one of the few models that has no sequence length limit.''' )
          return -1




      @max_position_embeddings.setter
      def     UpperCAmelCase						(				self    ,				SCREAMING_SNAKE_CASE_ )				->      Any:
          # Message copied from Transformer-XL documentation
          raise NotImplementedError(
              F'''The model {self.model_type} is one of the few models that has no sequence length limit.''' )










import gc
import unittest

from diffusers import FlaxStableDiffusionInpaintPipeline
from diffusers.utils import is_flax_available, load_image, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
						import jax
						import jax.numpy as jnp
						from flax.jax_utils import replicate
						from flax.training.common_utils import shard



@slow
@require_flax
class 				__snake_case						(     unittest.TestCase						):




							def    UpperCAmelCase__			(       self     :       Tuple):
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()







							def    UpperCAmelCase__			(       self     :       List[str]):
									lowerCAmelCase_			:     Any									= load_image(
									    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
									    '''/sd2-inpaint/init_image.png''')
									lowerCAmelCase_			:     str									= load_image(
									    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-inpaint/mask.png''')

									lowerCAmelCase_			:     List[Any]									= '''xvjiarui/stable-diffusion-2-inpainting'''
									lowerCAmelCase_					,  lowerCAmelCase_			:     Optional[Any]									= FlaxStableDiffusionInpaintPipeline.from_pretrained(A_				,				safety_checker=A_)

									lowerCAmelCase_			:     List[str]									= '''Face of a yellow cat, high resolution, sitting on a park bench'''

									lowerCAmelCase_			:     List[Any]									= jax.random.PRNGKey(0)
									lowerCAmelCase_			:     str									= 5_0

									lowerCAmelCase_			:     List[Any]									= jax.device_count()
									lowerCAmelCase_			:     Union[str, Any]									= num_samples * [prompt]
									lowerCAmelCase_			:     str									= num_samples * [init_image]
									lowerCAmelCase_			:     Union[str, Any]									= num_samples * [mask_image]
									lowerCAmelCase_					,  lowerCAmelCase_					,  lowerCAmelCase_			:     Optional[Any]									= pipeline.prepare_inputs(A_				,				A_				,				A_)

									# shard inputs and rng
									lowerCAmelCase_			:     str									= replicate(A_)
									lowerCAmelCase_			:     str									= jax.random.split(A_				,				jax.device_count())
									lowerCAmelCase_			:     List[Any]									= shard(A_)
									lowerCAmelCase_			:     str									= shard(A_)
									lowerCAmelCase_			:     Tuple									= shard(A_)

									lowerCAmelCase_			:     int									= pipeline(
									    A_				,				A_				,				A_				,				A_				,				A_				,				A_				,				jit=A_)

									lowerCAmelCase_			:     Optional[int]									= output.images.reshape(A_				,				5_1_2				,				5_1_2				,				3)

									lowerCAmelCase_			:     List[str]									= images[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

									lowerCAmelCase_			:     int									= jnp.asarray(jax.device_get(image_slice.flatten()))
									lowerCAmelCase_			:     str									= jnp.array(
									    [0.361_1307, 0.3764_9736, 0.375_7408, 0.3821_3953, 0.3929_5167, 0.384_1631, 0.4155_4978, 0.413_7475, 0.421_7084])
									print(F"""output_slice: {output_slice}""")
									assert jnp.abs(output_slice - expected_slice).max() < 1e-2





