




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

_lowerCamelCase			 =						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 					SCREAMING_SNAKE_CASE	(       cls			:						List[Any]      )  ->							Tuple:
     return cls




def 					SCREAMING_SNAKE_CASE	(       __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       ,     )  ->							Union[str, Any]:
    UpperCAmelCase_							 =     device
    UpperCAmelCase_							 =     shape[0]

    UpperCAmelCase_							 =     layout or torch.strided
    UpperCAmelCase_							 =     device or torch.device('''cpu'''      )

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

    return latents




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						Union[str, Any]      )  ->							str:
    if is_torch_version('''<'''       ,     '''2.0.0'''      ) or not hasattr(__UpperCamelCase       ,     '''_dynamo'''      ):
        return False
    return isinstance(__UpperCamelCase       ,     torch._dynamo.eval_frame.OptimizedModule      )











from __future__ import annotations




def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						list[int | float]      )  ->							int | float:
    if len(__UpperCamelCase      ) == 0:
        raise ValueError('''find_max() arg is an empty sequence'''      )
    UpperCAmelCase_							 =     nums[0]
    for x in nums:
        if x > max_num:
            UpperCAmelCase_							 =     x
    return max_num


if __name__ == "__main__":
 import doctest

 doctest.testmod(verbose=True)





