

"""simple docstring"""




import torch
import torch.nn.functional as F

from diffusers import VQDiffusionScheduler

from .test_schedulers import SchedulerCommonTest





class 				lowerCamelCase  (A__     ):
			lowerCamelCase__				:						List[str]   						=							(VQDiffusionScheduler,)

			def    SCREAMING_SNAKE_CASE			(   self			:  List[Any]      ,			**__UpperCAmelCase			:  Dict    )				->      str:
						SCREAMING_SNAKE_CASE__									= {
						    """num_vec_classes""": 4_0_9_7,
						    """num_train_timesteps""": 1_0_0,
						}

						config.update(**__UpperCAmelCase    )
						return config

			def    SCREAMING_SNAKE_CASE			(   self			:  str      ,			__UpperCAmelCase			:  Dict    )				->      str:
						SCREAMING_SNAKE_CASE__									= 4
						SCREAMING_SNAKE_CASE__									= 8
						SCREAMING_SNAKE_CASE__									= 8

						SCREAMING_SNAKE_CASE__									= torch.randint(0      ,			__UpperCAmelCase      ,			(batch_size, height * width)    )

						return sample

			@property
			def    SCREAMING_SNAKE_CASE			(   self			:  Tuple    )				->      List[Any]:
						assert False

			def    SCREAMING_SNAKE_CASE			(   self			:  int      ,			__UpperCAmelCase			:  Union[str, Any]    )				->      int:
						def model(__UpperCAmelCase			:  List[str]      ,			__UpperCAmelCase			:  int      ,			*__UpperCAmelCase			:  int    ):
									SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__									= sample.shape
									SCREAMING_SNAKE_CASE__									= torch.rand((batch_size, num_vec_classes - 1, num_latent_pixels)    )
									SCREAMING_SNAKE_CASE__									= F.log_softmax(logits.double()      ,			dim=1    ).float()
									return return_value

						return model

			def    SCREAMING_SNAKE_CASE			(   self			:  Optional[int]    )				->      Tuple:
						for timesteps in [2, 5, 1_0_0, 1_0_0_0]:
									self.check_over_configs(num_train_timesteps=__UpperCAmelCase    )

			def    SCREAMING_SNAKE_CASE			(   self			:  Any    )				->      Any:
						for num_vec_classes in [5, 1_0_0, 1_0_0_0, 4_0_0_0]:
									self.check_over_configs(num_vec_classes=__UpperCAmelCase    )

			def    SCREAMING_SNAKE_CASE			(   self			:  Tuple    )				->      int:
						for t in [0, 5_0, 9_9]:
									self.check_over_forward(time_step=__UpperCAmelCase    )





			def    SCREAMING_SNAKE_CASE			(   self			:  Optional[int]    )				->      str:
						pass





"""simple docstring"""




import importlib.metadata
import subprocess
import sys

def 		A    (       snake_case__ = False      ):




			'''simple docstring'''


			SCREAMING_SNAKE_CASE__									= False
			if "IPython" in sys.modules:
						SCREAMING_SNAKE_CASE__									= """google.colab""" in str(sys.modules["""IPython"""].get_ipython()      )

			if in_colab:
						if upgrade:
									SCREAMING_SNAKE_CASE__									= ["""pip""", """install""", """-U""", """torch"""]
									subprocess.run(snake_case__						,			check=snake_case__      )
						# get the current version of torch
						SCREAMING_SNAKE_CASE__									= importlib.metadata.version("""torch"""      )
						SCREAMING_SNAKE_CASE__									= torch_version[: torch_version.rindex("""."""      )]
						SCREAMING_SNAKE_CASE__									= f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
						SCREAMING_SNAKE_CASE__									= ["""pip""", """install""", xla_wheel]
						subprocess.run(snake_case__						,			check=snake_case__      )
			else:
						raise RuntimeError("""`install_xla` utility works only on google colab."""      )


