


"""simple docstring"""




import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


lowercase_	   =     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')
lowercase_	   =     parser.parse_args()


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

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

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

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

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

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

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





import datasets


lowercase_	   =     '\\n@InProceedings{conneau2018xnli,\n  author = "Conneau, Alexis\n                 and Rinott, Ruty\n                 and Lample, Guillaume\n                 and Williams, Adina\n                 and Bowman, Samuel R.\n                 and Schwenk, Holger\n                 and Stoyanov, Veselin",\n  title = "XNLI: Evaluating Cross-lingual Sentence Representations",\n  booktitle = "Proceedings of the 2018 Conference on Empirical Methods\n               in Natural Language Processing",\n  year = "2018",\n  publisher = "Association for Computational Linguistics",\n  location = "Brussels, Belgium",\n}\n'

lowercase_	   =     '\\nXNLI is a subset of a few thousand examples from MNLI which has been translated\ninto a 14 different languages (some low-ish resource). As with MNLI, the goal is\nto predict textual entailment (does sentence A imply/contradict/neither sentence\nB) and is a classification task (given two sentences, predict one of three\nlabels).\n'

lowercase_	   =     '\nComputes XNLI score which is just simple accuracy.\nArgs:\n    predictions: Predicted labels.\n    references: Ground truth labels.\nReturns:\n    \'accuracy\': accuracy\nExamples:\n\n    >>> predictions = [0, 1]\n    >>> references = [0, 1]\n    >>> xnli_metric = datasets.load_metric("xnli")\n    >>> results = xnli_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0}\n'
def 				UpperCamelCase__					(  SCREAMING_SNAKE_CASE__      ,	SCREAMING_SNAKE_CASE__						):
 return (preds == labels).mean()



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,				_KWARGS_DESCRIPTION   )
class 	A_ (	datasets.Metric   ):




      '''simple docstring'''


      def 					_snake_case     (    self:	Union[str, Any]    ):
       return datasets.MetricInfo(
           description=_DESCRIPTION						,				citation=_CITATION						,				inputs_description=_KWARGS_DESCRIPTION						,				features=datasets.Features(
               {
                   'predictions': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'    ),
                   'references': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'    ),
               }    )						,				codebase_urls=[]						,				reference_urls=[]						,				format='numpy'						,				)




      def 					_snake_case     (    self:	int						,				a:	Optional[Any]						,				a:	Optional[Any]    ):
       return {"accuracy": simple_accuracy(a						,				a    )}

