






'''simple docstring'''


from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available




@dataclass
class 							lowerCAmelCase					(							lowerCamelCase__   ):







   """simple docstring"""







   _A						=   {
       'sld_warmup_steps': 15,
       'sld_guidance_scale': 20,
       'sld_threshold': 0.0,
       'sld_momentum_scale': 0.0,
       'sld_mom_beta': 0.0,
   }
   _A						=   {
       'sld_warmup_steps': 10,
       'sld_guidance_scale': 10_00,
       'sld_threshold': 0.01,
       'sld_momentum_scale': 0.3,
       'sld_mom_beta': 0.4,
   }
   _A						=   {
       'sld_warmup_steps': 7,
       'sld_guidance_scale': 20_00,
       'sld_threshold': 0.025,
       'sld_momentum_scale': 0.5,
       'sld_mom_beta': 0.7,
   }
   _A						=   {
       'sld_warmup_steps': 0,
       'sld_guidance_scale': 50_00,
       'sld_threshold': 1.0,
       'sld_momentum_scale': 0.5,
       'sld_mom_beta': 0.7,
   }




@dataclass
class 							lowerCAmelCase					(							lowerCamelCase__   ):







   """simple docstring"""







   _A						=   42
   _A						=   42
   _A						=   42
   _A						=   42


if is_transformers_available() and is_torch_available():
  from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
  from .safety_checker import SafeStableDiffusionSafetyChecker












'''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_				      =							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		):
   return cls






def   lowerCAmelCase__			(					SCREAMING_SNAKE_CASE__       ,		SCREAMING_SNAKE_CASE__ = None       ,		SCREAMING_SNAKE_CASE__ = None       ,		SCREAMING_SNAKE_CASE__ = None       ,		SCREAMING_SNAKE_CASE__ = None       ,		):
 __a    :	int									=						device
 __a    :	Union[str, Any]									=						shape[0]

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

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

 return latents






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




