

'''simple docstring'''






import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__A    	=   argparse.ArgumentParser('''Stable Diffusion script with intel optimization''', add_help=False)
parser.add_argument('''--dpm''', action='''store_true''', help='''Enable DPMSolver or not''')
parser.add_argument('''--steps''', default=None, type=int, help='''Num inference steps''')
__A    	=   parser.parse_args()


__A    	=   '''cpu'''
__A    	=   '''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

__A    	=   '''path-to-your-trained-model'''
__A    	=   StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
      __A    	=   DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
__A    	=   pipe.to(device)

# to channels last
__A    	=   pipe.unet.to(memory_format=torch.channels_last)
__A    	=   pipe.vae.to(memory_format=torch.channels_last)
__A    	=   pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
      __A    	=   pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
__A    	=   torch.randn(2, 4, 6_4, 6_4)
__A    	=   torch.rand(1) * 9_9_9
__A    	=   torch.randn(2, 7_7, 7_6_8)
__A    	=   (sample, timestep, encoder_hidden_status)
try:
      __A    	=   ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
      __A    	=   ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
__A    	=   ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
__A    	=   ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
      __A    	=   ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
__A    	=   6_6_6
__A    	=   torch.Generator(device).manual_seed(seed)
__A    	=   {'''generator''': generator}
if args.steps is not None:
      __A    	=   args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
      __A    	=   pipe(prompt, **generate_kwargs).images[0]

# save image
image.save('''generated.png''')







'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__A    	=   {
    '''configuration_distilbert''': [
        '''DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''DistilBertConfig''',
        '''DistilBertOnnxConfig''',
    ],
    '''tokenization_distilbert''': ['''DistilBertTokenizer'''],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   ['''DistilBertTokenizerFast''']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''DistilBertForMaskedLM''',
          '''DistilBertForMultipleChoice''',
          '''DistilBertForQuestionAnswering''',
          '''DistilBertForSequenceClassification''',
          '''DistilBertForTokenClassification''',
          '''DistilBertModel''',
          '''DistilBertPreTrainedModel''',
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''TFDistilBertForMaskedLM''',
          '''TFDistilBertForMultipleChoice''',
          '''TFDistilBertForQuestionAnswering''',
          '''TFDistilBertForSequenceClassification''',
          '''TFDistilBertForTokenClassification''',
          '''TFDistilBertMainLayer''',
          '''TFDistilBertModel''',
          '''TFDistilBertPreTrainedModel''',
      ]

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __A    	=   [
          '''FlaxDistilBertForMaskedLM''',
          '''FlaxDistilBertForMultipleChoice''',
          '''FlaxDistilBertForQuestionAnswering''',
          '''FlaxDistilBertForSequenceClassification''',
          '''FlaxDistilBertForTokenClassification''',
          '''FlaxDistilBertModel''',
          '''FlaxDistilBertPreTrainedModel''',
      ]


if TYPE_CHECKING:
      from .configuration_distilbert import (
          DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
          DistilBertConfig,
          DistilBertOnnxConfig,
      )
      from .tokenization_distilbert import DistilBertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_distilbert_fast import DistilBertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_distilbert import (
                DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                DistilBertForMaskedLM,
                DistilBertForMultipleChoice,
                DistilBertForQuestionAnswering,
                DistilBertForSequenceClassification,
                DistilBertForTokenClassification,
                DistilBertModel,
                DistilBertPreTrainedModel,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_distilbert import (
                TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFDistilBertForMaskedLM,
                TFDistilBertForMultipleChoice,
                TFDistilBertForQuestionAnswering,
                TFDistilBertForSequenceClassification,
                TFDistilBertForTokenClassification,
                TFDistilBertMainLayer,
                TFDistilBertModel,
                TFDistilBertPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_distilbert import (
                FlaxDistilBertForMaskedLM,
                FlaxDistilBertForMultipleChoice,
                FlaxDistilBertForQuestionAnswering,
                FlaxDistilBertForSequenceClassification,
                FlaxDistilBertForTokenClassification,
                FlaxDistilBertModel,
                FlaxDistilBertPreTrainedModel,
            )

else:
      import sys

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