


from typing import List

import PIL
import torch
from PIL import Image

from ...configuration_utils import ConfigMixin
from ...models.modeling_utils import ModelMixin
from ...utils import PIL_INTERPOLATION

class      lowerCamelCase	(  SCREAMING_SNAKE_CASE,			SCREAMING_SNAKE_CASE     ):

       def __init__(			self					):






        '''simple docstring'''






        super().__init__()

        self.register_buffer('''watermark_image'''	,						torch.zeros((62, 62, 4)					)					)
        snake_case   : Tuple	  =      None



       def 				UpperCAmelCase				(			self	,						a__	,						a__=None					):






        '''simple docstring'''






        snake_case   : Dict	  =      images[0].height
        snake_case   : Any	  =      images[0].width

        snake_case   : List[Any]	  =      sample_size or h

        snake_case   : Union[str, Any]	  =      min(h / sample_size	,						w / sample_size					)
        snake_case  ,					snake_case   : int	  =      (int(h / coef					), int(w / coef					)) if coef < 1 else (h, w)

        snake_case  ,					snake_case   : List[Any]	  =      10_24**2, img_w * img_h
        snake_case   : Dict	  =      (Sa / Sa) ** 0.5
        snake_case  ,					snake_case  ,					snake_case   : Optional[int]	  =      int(K * 62					), img_w - int(14 * K					), img_h - int(14 * K					)

        if self.watermark_image_as_pil is None:
         snake_case   : Any	  =      self.watermark_image.to(torch.uinta					).cpu().numpy()
         snake_case   : int	  =      Image.fromarray(a__	,						mode='''RGBA'''					)
         snake_case   : Tuple	  =      watermark_image

        snake_case   : str	  =      self.watermark_image_as_pil.resize(
            (wm_size, wm_size)	,						PIL_INTERPOLATION['''bicubic''']	,						reducing_gap=a__					)

        for pil_img in images:
         pil_img.paste(a__	,						box=(wm_x - wm_size, wm_y - wm_size, wm_x, wm_y)	,						mask=wm_img.split()[-1]					)

        return images










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

a				:							Union[str, 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       )		->str:


   '''simple docstring'''
   return cls






def    _UpperCAmelCase	(   __lowerCamelCase ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     )		->Union[str, Any]:


 '''simple docstring'''
 snake_case   : Union[str, Any]	  =      device
 snake_case   : Any	  =      shape[0]

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

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

 return latents






def    _UpperCAmelCase	(   __lowerCamelCase       )		->Tuple:


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






