


import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils







class 			snake_case__(							unittest.TestCase							):







						'''simple docstring'''




						@patch('''diffusers.utils.hub_utils.get_full_repo_name'''							)
						def   lowercase_	(			self				,  __lowercase							)   ->      None:
										lowerCAmelCase_	: Dict      			=			'''full_repo_name'''
										with TemporaryDirectory() as tmpdir:
														# Dummy args values
														lowerCAmelCase_	: Union[str, Any]      			=			Mock()
														lowerCAmelCase_	: Union[str, Any]      			=			tmpdir
														lowerCAmelCase_	: str      			=			0
														lowerCAmelCase_	: Any      			=			'''hub_token'''
														lowerCAmelCase_	: str      			=			'''dataset_name'''
														lowerCAmelCase_	: Dict      			=			0.01
														lowerCAmelCase_	: Optional[int]      			=			1_0_0_0_0_0
														lowerCAmelCase_	: Dict      			=			1_0_0_0_0
														lowerCAmelCase_	: Optional[int]      			=			0.01
														lowerCAmelCase_	: Optional[int]      			=			0.02
														lowerCAmelCase_	: str      			=			0.03
														lowerCAmelCase_	: Union[str, Any]      			=			0.00_05
														lowerCAmelCase_	: str      			=			0.00_00_01
														lowerCAmelCase_	: Dict      			=			1
														lowerCAmelCase_	: Dict      			=			1_0
														lowerCAmelCase_	: List[str]      			=			0.0_01
														lowerCAmelCase_	: int      			=			0.1
														lowerCAmelCase_	: int      			=			0.2
														lowerCAmelCase_	: Any      			=			True

														# Model card mush be rendered and saved
														diffusers.utils.hub_utils.create_model_card(__lowercase				,  model_name='''model_name'''							)
														self.assertTrue((Path(__lowercase							) / '''README.md''').is_file()							)



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

_UpperCAmelCase     :					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      lowerCAmelCase	(						cls	)->	int:
										return cls



def      lowerCAmelCase	(						lowerCAmelCase_	,				lowerCAmelCase_ = None	,				lowerCAmelCase_ = None	,				lowerCAmelCase_ = None	,				lowerCAmelCase_ = None	,				)->	int:
				lowerCAmelCase_	: Tuple      			=			device
				lowerCAmelCase_	: List[str]      			=			shape[0]

				lowerCAmelCase_	: Union[str, Any]      			=			layout or torch.strided
				lowerCAmelCase_	: Union[str, Any]      			=			device or torch.device('''cpu'''	)

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

				return latents




def      lowerCAmelCase	(						lowerCAmelCase_	)->	Optional[Any]:
				if is_torch_version('''<'''	,				'''2.0.0'''	) or not hasattr(lowerCAmelCase_	,				'''_dynamo'''	):
								return False
				return isinstance(lowerCAmelCase_	,				torch._dynamo.eval_frame.OptimizedModule	)