


"""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

SCREAMING_SNAKE_CASE					:       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 						lowercase				(	cls		: Dict	)	->str:
				"""simple docstring"""





				return cls






def 						lowercase				(	_snake_case		: Union[Tuple, List]	,  _snake_case		: Optional[Union[List["torch.Generator"], "torch.Generator"]] = None	,  _snake_case		: Optional["torch.device"] = None	,  _snake_case		: Optional["torch.dtype"] = None	,  _snake_case		: Optional["torch.layout"] = None	,  )	->Any:
	"""simple docstring"""





	__snake_case      :		List[Any]         =							device
	__snake_case      :		Optional[int]         =							shape[0]

	__snake_case      :		Dict         =							layout or torch.strided
	__snake_case      :		Optional[Any]         =							device or torch.device('''cpu'''	)

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

	return latents






def 						lowercase				(	_snake_case		: Union[str, Any]	)	->Tuple:
	"""simple docstring"""





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










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available


UpperCAmelCase__			:   Optional[Any]      			=    {}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase__			:   List[Any]      			=    ['MBart50Tokenizer']

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase__			:   int      			=    ['MBart50TokenizerFast']


if TYPE_CHECKING:
					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_mbartaa import MBartaaTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_mbartaa_fast import MBartaaTokenizerFast

else:
					import sys

					UpperCAmelCase__			:   str      			=    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
