


from typing import Any, Callable, Dict, List, Optional, Union

import PIL.Image
import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionImgaImgPipeline,
    StableDiffusionInpaintPipelineLegacy,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.configuration_utils import FrozenDict
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
from diffusers.utils import deprecate, logging


__a   				=      logging.get_logger(__name__)  # pylint: disable=invalid-name






class 				__SCREAMING_SNAKE_CASE   (			__UpperCAmelCase   ):
      A				:							Union[str, Any]    							=     ["""safety_checker""", """feature_extractor"""]


      def __init__(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = True							,						):
            super().__init__()
            if hasattr(scheduler.config							,						'''steps_offset'''		) and scheduler.config.steps_offset != 1:
                  lowercase			:   Any					   =		(
                      f"""The configuration file of this scheduler: {scheduler} is outdated. `steps_offset`"""
                      f""" should be set to 1 instead of {scheduler.config.steps_offset}. Please make sure """
                      '''to update the config accordingly as leaving `steps_offset` might led to incorrect results'''
                      ''' in future versions. If you have downloaded this checkpoint from the Hugging Face Hub,'''
                      ''' it would be very nice if you could open a Pull request for the `scheduler/scheduler_config.json`'''
                      ''' file'''
                  )
                  deprecate('''steps_offset!=1'''							,						'''1.0.0'''							,						lowerCamelCase__							,						standard_warn=lowerCamelCase__		)
                  lowercase			:   int					   =		dict(scheduler.config		)
                  lowercase			:   Tuple					   =		1
                  lowercase			:   Union[str, Any]					   =		FrozenDict(lowerCamelCase__		)

            self.register_modules(
                vae=lowerCamelCase__							,						text_encoder=lowerCamelCase__							,						tokenizer=lowerCamelCase__							,						unet=lowerCamelCase__							,						scheduler=lowerCamelCase__							,						safety_checker=lowerCamelCase__							,						feature_extractor=lowerCamelCase__							,						)
            self.register_to_config(requires_safety_checker=lowerCamelCase__		)


      @property
      def        __lowerCamelCase			(							self		):
            return {k: getattr(self							,						lowerCamelCase__		) for k in self.config.keys() if not k.startswith('''_'''		)}


      def        __lowerCamelCase			(							self							,						SCREAMING_SNAKE_CASE__ = "auto"		):



            if slice_size == "auto":
                  # half the attention head size is usually a good trade-off between
                  # speed and memory
                  lowercase			:   int					   =		self.unet.config.attention_head_dim // 2
            self.unet.set_attention_slice(lowerCamelCase__		)


      def        __lowerCamelCase			(							self		):
            self.enable_attention_slicing(lowerCamelCase__		)


      @torch.no_grad()
      def        __lowerCamelCase			(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = 0.8							,						SCREAMING_SNAKE_CASE__ = 50							,						SCREAMING_SNAKE_CASE__ = 7.5							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						SCREAMING_SNAKE_CASE__ = 0.0							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = "pil"							,						SCREAMING_SNAKE_CASE__ = True							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						):
            return StableDiffusionInpaintPipelineLegacy(**self.components		)(
                prompt=lowerCamelCase__							,						image=lowerCamelCase__							,						mask_image=lowerCamelCase__							,						strength=lowerCamelCase__							,						num_inference_steps=lowerCamelCase__							,						guidance_scale=lowerCamelCase__							,						negative_prompt=lowerCamelCase__							,						num_images_per_prompt=lowerCamelCase__							,						eta=lowerCamelCase__							,						generator=lowerCamelCase__							,						output_type=lowerCamelCase__							,						return_dict=lowerCamelCase__							,						callback=lowerCamelCase__							,						)


      @torch.no_grad()
      def        __lowerCamelCase			(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = 0.8							,						SCREAMING_SNAKE_CASE__ = 50							,						SCREAMING_SNAKE_CASE__ = 7.5							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						SCREAMING_SNAKE_CASE__ = 0.0							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = "pil"							,						SCREAMING_SNAKE_CASE__ = True							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						**SCREAMING_SNAKE_CASE__							,						):
            return StableDiffusionImgaImgPipeline(**self.components		)(
                prompt=lowerCamelCase__							,						image=lowerCamelCase__							,						strength=lowerCamelCase__							,						num_inference_steps=lowerCamelCase__							,						guidance_scale=lowerCamelCase__							,						negative_prompt=lowerCamelCase__							,						num_images_per_prompt=lowerCamelCase__							,						eta=lowerCamelCase__							,						generator=lowerCamelCase__							,						output_type=lowerCamelCase__							,						return_dict=lowerCamelCase__							,						callback=lowerCamelCase__							,						callback_steps=lowerCamelCase__							,						)






      @torch.no_grad()
      def        __lowerCamelCase			(							self							,						SCREAMING_SNAKE_CASE__							,						SCREAMING_SNAKE_CASE__ = 512							,						SCREAMING_SNAKE_CASE__ = 512							,						SCREAMING_SNAKE_CASE__ = 50							,						SCREAMING_SNAKE_CASE__ = 7.5							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						SCREAMING_SNAKE_CASE__ = 0.0							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = "pil"							,						SCREAMING_SNAKE_CASE__ = True							,						SCREAMING_SNAKE_CASE__ = None							,						SCREAMING_SNAKE_CASE__ = 1							,						):
            return StableDiffusionPipeline(**self.components		)(
                prompt=lowerCamelCase__							,						height=lowerCamelCase__							,						width=lowerCamelCase__							,						num_inference_steps=lowerCamelCase__							,						guidance_scale=lowerCamelCase__							,						negative_prompt=lowerCamelCase__							,						num_images_per_prompt=lowerCamelCase__							,						eta=lowerCamelCase__							,						generator=lowerCamelCase__							,						latents=lowerCamelCase__							,						output_type=lowerCamelCase__							,						return_dict=lowerCamelCase__							,						callback=lowerCamelCase__							,						callback_steps=lowerCamelCase__							,						)





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__a   				=      {
    '''configuration_decision_transformer''': [
        '''DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DecisionTransformerConfig''',
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __a   				=      [
      '''DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''DecisionTransformerGPT2Model''',
      '''DecisionTransformerGPT2PreTrainedModel''',
      '''DecisionTransformerModel''',
      '''DecisionTransformerPreTrainedModel''',
  ]


if TYPE_CHECKING:
  from .configuration_decision_transformer import (
      DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DecisionTransformerConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_decision_transformer import (
        DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        DecisionTransformerGPTaModel,
        DecisionTransformerGPTaPreTrainedModel,
        DecisionTransformerModel,
        DecisionTransformerPreTrainedModel,
    )


else:
  import sys

  __a   				=      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

