
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

SCREAMING_SNAKE_CASE							:List[Any]											=       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		)	->			int:







									"""simple docstring"""



									return cls


def 		UpperCAmelCase    (			a_	,     a_ = None	,     a_ = None	,     a_ = None	,     a_ = None	,     )	->			int:







				"""simple docstring"""



				__A         =				device
				__A         =				shape[0]

				__A         =				layout or torch.strided
				__A         =				device or torch.device("cpu"		)

				if generator is not None:
								__A         =				generator.device.type if not isinstance(a_	,     a_		) else generator[0].device.type
								if gen_device_type != device.type and gen_device_type == "cpu":
												__A         =				"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(a_	,     a_		):
								__A         =				(1,) + shape[1:]
								__A         =				[
								    torch.randn(a_	,     generator=generator[i]	,     device=a_	,     dtype=a_	,     layout=a_		)
								    for i in range(a_		)
								]
								__A         =				torch.cat(a_	,     dim=0		).to(a_		)
				else:
								__A         =				torch.randn(a_	,     generator=a_	,     device=a_	,     dtype=a_	,     layout=a_		).to(a_		)

				return latents


def 		UpperCAmelCase    (			a_		)	->			str:







				"""simple docstring"""



				if is_torch_version("<"	,     "2.0.0"		) or not hasattr(a_	,     "_dynamo"		):
								return False
				return isinstance(a_	,     torch._dynamo.eval_frame.OptimizedModule		)


def 		UpperCAmelCase    (			a_		)	->			int:







				"""simple docstring"""



				__A         =				str(a_		).strip()
				if not oct_string:
								raise ValueError("Empty string was passed to the function"		)
				__A         =				oct_string[0] == "-"
				if is_negative:
								__A         =				oct_string[1:]
				if not oct_string.isdigit() or not all(0 <= int(a_		) <= 7 for char in oct_string		):
								raise ValueError("Non-octal value was passed to the function"		)
				__A         =				0
				for char in oct_string:
								__A         =				8 * decimal_number + int(a_		)
				if is_negative:
								__A         =				-decimal_number
				return decimal_number


if __name__ == "__main__":
					from doctest import testmod

					testmod()
