





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


lowercase    : List[Any]    	=  logging.get_logger(__name__)

lowercase    : str    	=  {
    """funnel-transformer/small""": """https://huggingface.co/funnel-transformer/small/resolve/main/config.json""",
    """funnel-transformer/small-base""": """https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json""",
    """funnel-transformer/medium""": """https://huggingface.co/funnel-transformer/medium/resolve/main/config.json""",
    """funnel-transformer/medium-base""": """https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json""",
    """funnel-transformer/intermediate""": (
        """https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json"""
    ),
    """funnel-transformer/intermediate-base""": (
        """https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json"""
    ),
    """funnel-transformer/large""": """https://huggingface.co/funnel-transformer/large/resolve/main/config.json""",
    """funnel-transformer/large-base""": """https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json""",
    """funnel-transformer/xlarge""": """https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json""",
    """funnel-transformer/xlarge-base""": """https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json""",
}

class  __A(						__UpperCAmelCase ):
     __A	  =       "funnel"
     __A	  =       {
         "hidden_size": "d_model",
         "num_attention_heads": "n_head",
     }

     def __init__(      self,       A=3_0522,       A=[4, 4, 4],       A=None,       A=2,       A=768,       A=12,       A=64,       A=3072,       A="gelu_new",       A=0.1,       A=0.1,       A=0.0,       A=0.1,       A=None,       A=1E-9,       A="mean",       A="relative_shift",       A=True,       A=True,       A=True,       **A,       ):





            """simple docstring"""

            _UpperCamelCase              =						vocab_size
            _UpperCamelCase              =						block_sizes
            _UpperCamelCase              =						[1] * len(A      ) if block_repeats is None else block_repeats
            assert len(A      ) == len(
                self.block_repeats      ), "`block_sizes` and `block_repeats` should have the same length."
            _UpperCamelCase              =						num_decoder_layers
            _UpperCamelCase              =						d_model
            _UpperCamelCase              =						n_head
            _UpperCamelCase              =						d_head
            _UpperCamelCase              =						d_inner
            _UpperCamelCase              =						hidden_act
            _UpperCamelCase              =						hidden_dropout
            _UpperCamelCase              =						attention_dropout
            _UpperCamelCase              =						activation_dropout
            _UpperCamelCase              =						initializer_range
            _UpperCamelCase              =						initializer_std
            _UpperCamelCase              =						layer_norm_eps
            assert pooling_type in [
                "mean",
                "max",
            ], F'''Got {pooling_type} for `pooling_type` but only \'mean\' and \'max\' are supported.'''
            _UpperCamelCase              =						pooling_type
            assert attention_type in [
                "relative_shift",
                "factorized",
            ], F'''Got {attention_type} for `attention_type` but only \'relative_shift\' and \'factorized\' are supported.'''
            _UpperCamelCase              =						attention_type
            _UpperCamelCase              =						separate_cls
            _UpperCamelCase              =						truncate_seq
            _UpperCamelCase              =						pool_q_only

            super().__init__(**A      )

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return sum(self.block_sizes      )

     @num_hidden_layers.setter
     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            raise NotImplementedError(
                '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.'''      )

     @property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return len(self.block_sizes      )



     @num_blocks.setter
     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.'''      )













import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, 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  __A(						unittest.TestCase ):

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            super().tearDown()
            gc.collect()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase       ,		_UpperCamelCase              =						FlaxStableDiffusionPipeline.from_pretrained(
                '''stabilityai/stable-diffusion-2''',       revision='''bf16''',       dtype=jnp.bfloataa,       )

            _UpperCamelCase              =						'''A painting of a squirrel eating a burger'''
            _UpperCamelCase              =						jax.device_count()
            _UpperCamelCase              =						num_samples * [prompt]
            _UpperCamelCase              =						sd_pipe.prepare_inputs(A      )

            _UpperCamelCase              =						replicate(A      )
            _UpperCamelCase              =						shard(A      )

            _UpperCamelCase              =						jax.random.PRNGKey(0      )
            _UpperCamelCase              =						jax.random.split(A,       jax.device_count()      )

            _UpperCamelCase              =						sd_pipe(A,       A,       A,       num_inference_steps=25,       jit=A      )[0]
            assert images.shape == (jax.device_count(), 1, 768, 768, 3)

            _UpperCamelCase              =						images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]      )
            _UpperCamelCase              =						images[0, 253:256, 253:256, -1]

            _UpperCamelCase              =						jnp.asarray(jax.device_get(image_slice.flatten()      )      )
            _UpperCamelCase              =						jnp.array([0.4_238, 0.4_414, 0.4_395, 0.4_453, 0.4_629, 0.4_590, 0.4_531, 0.45_508, 0.4_512]      )
            print(F'''output_slice: {output_slice}'''      )
            assert jnp.abs(output_slice - expected_slice      ).max() < 1E-2



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						'''stabilityai/stable-diffusion-2'''
            _UpperCamelCase       ,		_UpperCamelCase              =						FlaxDPMSolverMultistepScheduler.from_pretrained(A,       subfolder='''scheduler'''      )
            _UpperCamelCase       ,		_UpperCamelCase              =						FlaxStableDiffusionPipeline.from_pretrained(
                A,       scheduler=A,       revision='''bf16''',       dtype=jnp.bfloataa,       )
            _UpperCamelCase              =						scheduler_params

            _UpperCamelCase              =						'''A painting of a squirrel eating a burger'''
            _UpperCamelCase              =						jax.device_count()
            _UpperCamelCase              =						num_samples * [prompt]
            _UpperCamelCase              =						sd_pipe.prepare_inputs(A      )

            _UpperCamelCase              =						replicate(A      )
            _UpperCamelCase              =						shard(A      )

            _UpperCamelCase              =						jax.random.PRNGKey(0      )
            _UpperCamelCase              =						jax.random.split(A,       jax.device_count()      )

            _UpperCamelCase              =						sd_pipe(A,       A,       A,       num_inference_steps=25,       jit=A      )[0]
            assert images.shape == (jax.device_count(), 1, 768, 768, 3)

            _UpperCamelCase              =						images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]      )
            _UpperCamelCase              =						images[0, 253:256, 253:256, -1]

            _UpperCamelCase              =						jnp.asarray(jax.device_get(image_slice.flatten()      )      )
            _UpperCamelCase              =						jnp.array([0.4_336, 0.42_969, 0.4_453, 0.4_199, 0.4_297, 0.4_531, 0.4_434, 0.4_434, 0.4_297]      )
            print(F'''output_slice: {output_slice}'''      )
            assert jnp.abs(output_slice - expected_slice      ).max() < 1E-2






