






"""simple docstring"""


import inspect

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
       import jax


@require_flax
class    snake_case						:


   '''simple docstring'''

   def 							_SCREAMING_SNAKE_CASE							(      self					:	Union[str, Any]    ):

     '''simple docstring'''
     __A     ,       __A		     =					self.prepare_init_args_and_inputs_for_common()

     __A		     =					self.model_class(**_lowerCamelCase    )
     __A		     =					model.init(inputs_dict['''prng_key'''],			inputs_dict['''sample''']    )
     jax.lax.stop_gradient(_lowerCamelCase    )

     __A		     =					model.apply(_lowerCamelCase,			inputs_dict['''sample''']    )

     if isinstance(_lowerCamelCase,			_lowerCamelCase    ):
       __A		     =					output.sample

     self.assertIsNotNone(_lowerCamelCase    )
     __A		     =					inputs_dict['''sample'''].shape
     self.assertEqual(output.shape,			_lowerCamelCase,			'''Input and output shapes do not match'''    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Dict    ):

     '''simple docstring'''
     __A     ,       __A		     =					self.prepare_init_args_and_inputs_for_common()

     __A		     =					16
     __A		     =					(16, 32)

     __A		     =					self.model_class(**_lowerCamelCase    )
     __A		     =					model.init(inputs_dict['''prng_key'''],			inputs_dict['''sample''']    )
     jax.lax.stop_gradient(_lowerCamelCase    )

     __A		     =					model.apply(_lowerCamelCase,			inputs_dict['''sample''']    )

     if isinstance(_lowerCamelCase,			_lowerCamelCase    ):
       __A		     =					output.sample

     self.assertIsNotNone(_lowerCamelCase    )
     __A		     =					inputs_dict['''sample'''].shape
     self.assertEqual(output.shape,			_lowerCamelCase,			'''Input and output shapes do not match'''    )






   def 							_SCREAMING_SNAKE_CASE							(      self					:	Any    ):

     '''simple docstring'''
     __A		     =					'''kwargs''' in inspect.signature(self.model_class.__init__    ).parameters
     __A		     =					len(self.model_class._deprecated_kwargs    ) > 0

     if has_kwarg_in_model_class and not has_deprecated_kwarg:
       raise ValueError(
           f'{self.model_class} has `**kwargs` in its __init__ method but has not defined any deprecated kwargs'
           ''' under the `_deprecated_kwargs` class attribute. Make sure to either remove `**kwargs` if there are'''
           ''' no deprecated arguments or add the deprecated argument with `_deprecated_kwargs ='''
           ''' [<deprecated_argument>]`'''    )

     if not has_kwarg_in_model_class and has_deprecated_kwarg:
       raise ValueError(
           f'{self.model_class} doesn\'t have `**kwargs` in its __init__ method but has defined deprecated kwargs'
           ''' under the `_deprecated_kwargs` class attribute. Make sure to either add the `**kwargs` argument to'''
           f' {self.model_class}.__init__ if there are deprecated arguments or remove the deprecated argument'
           ''' from `_deprecated_kwargs = [<deprecated_argument>]`'''    )










import torch
import torch.nn.functional as F

from diffusers import VQDiffusionScheduler

from .test_schedulers import SchedulerCommonTest






class        __lowerCAmelCase					(			UpperCAmelCase__					):
			snake_case_ :					List[str]						=	(VQDiffusionScheduler,)







			def UpperCamelCase     (			self       :     Dict       ,       **snake_case__       :     int ):




									"""simple docstring"""


									_UpperCAmelCase						=	{
									    "num_vec_classes": 4_097,
									    "num_train_timesteps": 100,
									}

									config.update(**snake_case__ )
									return config







			def UpperCamelCase     (			self       :     Optional[int]       ,       snake_case__       :     Any ):




									"""simple docstring"""


									_UpperCAmelCase						=	4
									_UpperCAmelCase						=	8
									_UpperCAmelCase						=	8

									_UpperCAmelCase						=	torch.randint(0       ,       snake_case__       ,       (batch_size, height * width) )

									return sample







			@property
			def UpperCamelCase     (			self       :     str ):




									"""simple docstring"""


									assert False







			def UpperCamelCase     (			self       :     List[str]       ,       snake_case__       :     Optional[Any] ):




									"""simple docstring"""


									def model(snake_case__       :     Dict       ,       snake_case__       :     Tuple       ,       *snake_case__       :     str ):
															_UpperCAmelCase				,					_UpperCAmelCase						=	sample.shape
															_UpperCAmelCase						=	torch.rand((batch_size, num_vec_classes - 1, num_latent_pixels) )
															_UpperCAmelCase						=	F.log_softmax(logits.double()       ,       dim=1 ).float()
															return return_value

									return model







			def UpperCamelCase     (			self       :     Optional[int] ):




									"""simple docstring"""


									for timesteps in [2, 5, 100, 1_000]:
															self.check_over_configs(num_train_timesteps=snake_case__ )







			def UpperCamelCase     (			self       :     Optional[int] ):




									"""simple docstring"""


									for num_vec_classes in [5, 100, 1_000, 4_000]:
															self.check_over_configs(num_vec_classes=snake_case__ )







			def UpperCamelCase     (			self       :     Optional[Any] ):




									"""simple docstring"""


									for t in [0, 50, 99]:
															self.check_over_forward(time_step=snake_case__ )







			def UpperCamelCase     (			self       :     Tuple ):




									"""simple docstring"""


									pass




