



'''simple docstring'''



from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
				import torch

_lowercase       :						str						=logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
				from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):


				def 							__UpperCAmelCase				(				cls				:Dict			)		->						Optional[Any]:
								return cls


def 							__UpperCAmelCase				(				UpperCamelCase__				:Union[Tuple, List]   ,				UpperCamelCase__				:Optional[Union[List["torch.Generator"], "torch.Generator"]] = None   ,				UpperCamelCase__				:Optional["torch.device"] = None   ,				UpperCamelCase__				:Optional["torch.dtype"] = None   ,				UpperCamelCase__				:Optional["torch.layout"] = None   ,				)		->						Optional[Any]:
				snake_case__      :   int      =    device
				snake_case__      :   str      =    shape[0]

				snake_case__      :   List[str]      =    layout or torch.strided
				snake_case__      :   List[str]      =    device or torch.device('''cpu'''			)

				if generator is not None:
								snake_case__      :   Dict      =    generator.device.type if not isinstance(UpperCamelCase__   ,				UpperCamelCase__			) else generator[0].device.type
								if gen_device_type != device.type and gen_device_type == "cpu":
												snake_case__      :   Union[str, Any]      =    '''cpu'''
												if device != "mps":
																logger.info(
																    F'''The passed generator was created on \'cpu\' even though a tensor on {device} was expected.'''
																    F''' Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably'''
																    F''' slighly speed up this function by passing a generator that was created on the {device} device.'''			)
								elif gen_device_type != device.type and gen_device_type == "cuda":
												raise ValueError(F'''Cannot generate a {device} tensor from a generator of type {gen_device_type}.'''			)

				if isinstance(UpperCamelCase__   ,				UpperCamelCase__			):
								snake_case__      :   Union[str, Any]      =    (1,) + shape[1:]
								snake_case__      :   List[str]      =    [
								    torch.randn(UpperCamelCase__   ,				generator=generator[i]   ,				device=UpperCamelCase__   ,				dtype=UpperCamelCase__   ,				layout=UpperCamelCase__			)
								    for i in range(UpperCamelCase__			)
								]
								snake_case__      :   List[Any]      =    torch.cat(UpperCamelCase__   ,				dim=0			).to(UpperCamelCase__			)
				else:
								snake_case__      :   Tuple      =    torch.randn(UpperCamelCase__   ,				generator=UpperCamelCase__   ,				device=UpperCamelCase__   ,				dtype=UpperCamelCase__   ,				layout=UpperCamelCase__			).to(UpperCamelCase__			)

				return latents



def 							__UpperCAmelCase				(				UpperCamelCase__				:Dict			)		->						List[Any]:
				if is_torch_version('''<'''   ,				'''2.0.0'''			) or not hasattr(UpperCamelCase__   ,				'''_dynamo'''			):
								return False
				return isinstance(UpperCamelCase__   ,				torch._dynamo.eval_frame.OptimizedModule			)









"""simple docstring"""






def 	snake_case__  (						__lowerCamelCase							:       int = 998001      ):
			"""simple docstring"""

			# fetches the next number
			for number in range(n - 1				,						9999				,						-1      ):
						lowerCamelCase__						:						Optional[int]						      =str(__lowerCamelCase      )

						# checks whether 'str_number' is a palindrome.
						if str_number == str_number[::-1]:
									lowerCamelCase__						:						Optional[int]						      =999

									# if 'number' is a product of two 3-digit numbers
									# then number is the answer otherwise fetch next number.
									while divisor != 99:
												if (number % divisor == 0) and (len(str(number // divisor      )      ) == 3.0):
															return number
												divisor -= 1
			raise ValueError('''That number is larger than our acceptable range.'''      )


if __name__ == "__main__":
		print(f'{solution() = }')




