



"""simple docstring"""

from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import numpy as np
							import tensorflow as tf

							from transformers import (
							    TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
							    FlaubertConfig,
							    TFFlaubertForMultipleChoice,
							    TFFlaubertForQuestionAnsweringSimple,
							    TFFlaubertForSequenceClassification,
							    TFFlaubertForTokenClassification,
							    TFFlaubertModel,
							    TFFlaubertWithLMHeadModel,
							)
class     lowerCAmelCase__						:


	'''simple docstring'''







	def __init__(      self				:       str     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     parent
					SCREAMING_SNAKE_CASE						:							List[Any]							=     13
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     7
					SCREAMING_SNAKE_CASE						:							Any							=     True
					SCREAMING_SNAKE_CASE						:							List[str]							=     True
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     True
					SCREAMING_SNAKE_CASE						:							int							=     True
					SCREAMING_SNAKE_CASE						:							List[str]							=     True
					SCREAMING_SNAKE_CASE						:							List[str]							=     False
					SCREAMING_SNAKE_CASE						:							int							=     False
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     False
					SCREAMING_SNAKE_CASE						:							Tuple							=     2
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     99
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     0
					SCREAMING_SNAKE_CASE						:							str							=     32
					SCREAMING_SNAKE_CASE						:							List[Any]							=     2
					SCREAMING_SNAKE_CASE						:							int							=     4
					SCREAMING_SNAKE_CASE						:							Dict							=     0.1
					SCREAMING_SNAKE_CASE						:							Tuple							=     0.1
					SCREAMING_SNAKE_CASE						:							Any							=     512
					SCREAMING_SNAKE_CASE						:							Tuple							=     16
					SCREAMING_SNAKE_CASE						:							Tuple							=     2
					SCREAMING_SNAKE_CASE						:							List[str]							=     0.0_2
					SCREAMING_SNAKE_CASE						:							List[str]							=     3
					SCREAMING_SNAKE_CASE						:							Tuple							=     4
					SCREAMING_SNAKE_CASE						:							int							=     'last'
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     True
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     None
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     0





	def 			_lowerCAmelCase     (      self				:       Union[str, Any]    )						->	Optional[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     ids_tensor([self.batch_size, self.seq_length]     ,       self.vocab_size    )
					SCREAMING_SNAKE_CASE						:							int							=     random_attention_mask([self.batch_size, self.seq_length]     ,       dtype=tf.floataa    )

					SCREAMING_SNAKE_CASE						:							Dict							=     None
					if self.use_input_lengths:
									SCREAMING_SNAKE_CASE						:							Tuple							=     (
									    ids_tensor([self.batch_size]     ,       vocab_size=2    ) + self.seq_length - 2
									)  # small variation of seq_length

					SCREAMING_SNAKE_CASE						:							Tuple							=     None
					if self.use_token_type_ids:
									SCREAMING_SNAKE_CASE						:							str							=     ids_tensor([self.batch_size, self.seq_length]     ,       self.n_langs    )

					SCREAMING_SNAKE_CASE						:							Dict							=     None
					SCREAMING_SNAKE_CASE						:							List[str]							=     None
					SCREAMING_SNAKE_CASE						:							Dict							=     None
					if self.use_labels:
									SCREAMING_SNAKE_CASE						:							Tuple							=     ids_tensor([self.batch_size]     ,       self.type_sequence_label_size    )
									SCREAMING_SNAKE_CASE						:							Optional[int]							=     ids_tensor([self.batch_size, self.seq_length]     ,       self.num_labels    )
									SCREAMING_SNAKE_CASE						:							Optional[int]							=     ids_tensor([self.batch_size]     ,       2     ,       dtype=tf.floataa    )
									SCREAMING_SNAKE_CASE						:							int							=     ids_tensor([self.batch_size]     ,       self.num_choices    )

					SCREAMING_SNAKE_CASE						:							Any							=     FlaubertConfig(
					    vocab_size=self.vocab_size     ,       n_special=self.n_special     ,       emb_dim=self.hidden_size     ,       n_layers=self.num_hidden_layers     ,       n_heads=self.num_attention_heads     ,       dropout=self.hidden_dropout_prob     ,       attention_dropout=self.attention_probs_dropout_prob     ,       gelu_activation=self.gelu_activation     ,       sinusoidal_embeddings=self.sinusoidal_embeddings     ,       asm=self.asm     ,       causal=self.causal     ,       n_langs=self.n_langs     ,       max_position_embeddings=self.max_position_embeddings     ,       initializer_range=self.initializer_range     ,       summary_type=self.summary_type     ,       use_proj=self.use_proj     ,       bos_token_id=self.bos_token_id     ,       )

					return (
					    config,
					    input_ids,
					    token_type_ids,
					    input_lengths,
					    sequence_labels,
					    token_labels,
					    is_impossible_labels,
					    choice_labels,
					    input_mask,
					)





	def 			_lowerCAmelCase     (      self				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							int							=     TFFlaubertModel(config=_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     {'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     model(_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     [input_ids, input_mask]
					SCREAMING_SNAKE_CASE						:							int							=     model(_SCREAMING_SNAKE_CASE    )
					self.parent.assertEqual(result.last_hidden_state.shape     ,       (self.batch_size, self.seq_length, self.hidden_size)    )





	def 			_lowerCAmelCase     (      self				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]     ,       _SCREAMING_SNAKE_CASE				:       Optional[int]     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     TFFlaubertWithLMHeadModel(_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Tuple							=     {'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
					SCREAMING_SNAKE_CASE						:							Dict							=     model(_SCREAMING_SNAKE_CASE    )

					self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.seq_length, self.vocab_size)    )





	def 			_lowerCAmelCase     (      self				:       Any     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       int     ,       )						->	Any:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     TFFlaubertForQuestionAnsweringSimple(_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     {'input_ids': input_ids, 'lengths': input_lengths}

					SCREAMING_SNAKE_CASE						:							Tuple							=     model(_SCREAMING_SNAKE_CASE    )

					self.parent.assertEqual(result.start_logits.shape     ,       (self.batch_size, self.seq_length)    )
					self.parent.assertEqual(result.end_logits.shape     ,       (self.batch_size, self.seq_length)    )





	def 			_lowerCAmelCase     (      self				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       Dict     ,       )						->	int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     TFFlaubertForSequenceClassification(_SCREAMING_SNAKE_CASE    )

					SCREAMING_SNAKE_CASE						:							Optional[int]							=     {'input_ids': input_ids, 'lengths': input_lengths}

					SCREAMING_SNAKE_CASE						:							List[Any]							=     model(_SCREAMING_SNAKE_CASE    )

					self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.type_sequence_label_size)    )





	def 			_lowerCAmelCase     (      self				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       str     ,       )						->	List[str]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     self.num_labels
					SCREAMING_SNAKE_CASE						:							Tuple							=     TFFlaubertForTokenClassification(config=_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							str							=     {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     model(_SCREAMING_SNAKE_CASE    )
					self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.seq_length, self.num_labels)    )





	def 			_lowerCAmelCase     (      self				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       List[Any]     ,       _SCREAMING_SNAKE_CASE				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       )						->	str:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     self.num_choices
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     TFFlaubertForMultipleChoice(config=_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE     ,       1    )     ,       (1, self.num_choices, 1)    )
					SCREAMING_SNAKE_CASE						:							str							=     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE     ,       1    )     ,       (1, self.num_choices, 1)    )
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     tf.tile(tf.expand_dims(_SCREAMING_SNAKE_CASE     ,       1    )     ,       (1, self.num_choices, 1)    )
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     {
					    'input_ids': multiple_choice_inputs_ids,
					    'attention_mask': multiple_choice_input_mask,
					    'token_type_ids': multiple_choice_token_type_ids,
					}
					SCREAMING_SNAKE_CASE						:							List[str]							=     model(_SCREAMING_SNAKE_CASE    )
					self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.num_choices)    )







	def 			_lowerCAmelCase     (      self				:       Union[str, Any]    )						->	Tuple:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Dict							=     self.prepare_config_and_inputs()
					(
					    (
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						(
					    SCREAMING_SNAKE_CASE
					)				,						
					)						:							Any							=     config_and_inputs
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     {
					    'input_ids': input_ids,
					    'token_type_ids': token_type_ids,
					    'langs': token_type_ids,
					    'lengths': input_lengths,
					}
					return config, inputs_dict




@require_tf
class     lowerCAmelCase__						(	_lowerCamelCase							,							_lowerCamelCase							,							unittest.TestCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		int  						= (
	    (
	        TFFlaubertModel,
	        TFFlaubertWithLMHeadModel,
	        TFFlaubertForSequenceClassification,
	        TFFlaubertForQuestionAnsweringSimple,
	        TFFlaubertForTokenClassification,
	        TFFlaubertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	_SCREAMING_SNAKE_CASE	:		List[str]  						= (
	    (TFFlaubertWithLMHeadModel,) if is_tf_available() else ()
	)  # TODO (PVP): Check other models whether language generation is also applicable
	_SCREAMING_SNAKE_CASE	:		Optional[int]  						= (
	    {
	        '''feature-extraction''': TFFlaubertModel,
	        '''fill-mask''': TFFlaubertWithLMHeadModel,
	        '''question-answering''': TFFlaubertForQuestionAnsweringSimple,
	        '''text-classification''': TFFlaubertForSequenceClassification,
	        '''token-classification''': TFFlaubertForTokenClassification,
	        '''zero-shot''': TFFlaubertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	_SCREAMING_SNAKE_CASE	:		Optional[int]  						= False
	_SCREAMING_SNAKE_CASE	:		Optional[Any]  						= False





	def 			_lowerCAmelCase     (      self				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       Any     ,       _SCREAMING_SNAKE_CASE				:       int     ,       _SCREAMING_SNAKE_CASE				:       List[str]     ,       _SCREAMING_SNAKE_CASE				:       List[str]    )						->	Dict:





					"""simple docstring"""


					if (
					    pipeline_test_casse_name == "QAPipelineTests"
					    and tokenizer_name is not None
					    and not tokenizer_name.endswith('Fast'    )
					):
									# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
									# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
									# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
									return True

					return False





	def 			_lowerCAmelCase     (      self				:       List[Any]    )						->	Tuple:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Dict							=     TFFlaubertModelTester(self    )
					SCREAMING_SNAKE_CASE						:							List[str]							=     ConfigTester(self     ,       config_class=_SCREAMING_SNAKE_CASE     ,       emb_dim=37    )





	def 			_lowerCAmelCase     (      self				:       Optional[Any]    )						->	List[str]:





					"""simple docstring"""


					self.config_tester.run_common_tests()





	def 			_lowerCAmelCase     (      self				:       str    )						->	Optional[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_model(*_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       Union[str, Any]    )						->	int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_lm_head(*_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       List[str]    )						->	int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_qa(*_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       List[Any]    )						->	Optional[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_sequence_classif(*_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       List[str]    )						->	List[str]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Any							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_for_token_classification(*_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       Optional[Any]    )						->	List[str]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_flaubert_for_multiple_choice(*_SCREAMING_SNAKE_CASE    )







	@slow
	def 			_lowerCAmelCase     (      self				:       Any    )						->	List[str]:





					"""simple docstring"""


					for model_name in TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE						:							Optional[int]							=     TFFlaubertModel.from_pretrained(_SCREAMING_SNAKE_CASE    )
									self.assertIsNotNone(_SCREAMING_SNAKE_CASE    )




@require_tf
@require_sentencepiece
@require_tokenizers
class     lowerCAmelCase__						(	unittest.TestCase ):


	'''simple docstring'''







	@slow
	def 			_lowerCAmelCase     (      self				:       int    )						->	Dict:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							int							=     TFFlaubertModel.from_pretrained('jplu/tf-flaubert-small-cased'    )

					SCREAMING_SNAKE_CASE						:							List[Any]							=     tf.convert_to_tensor(
					    [[0, 158, 735, 2_592, 1_424, 6_727, 82, 1]]     ,       dtype=tf.intaa     ,       )  # "J'aime flaubert !"

					SCREAMING_SNAKE_CASE						:							Tuple							=     model(_SCREAMING_SNAKE_CASE    )[0]
					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     tf.TensorShape((1, 8, 512)    )
					self.assertEqual(output.shape     ,       _SCREAMING_SNAKE_CASE    )
					# compare the actual values for a slice.
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     tf.convert_to_tensor(
					    [
					        [
					            [-1.8_7_6_8_7_7_3, -1.5_6_6_5_5_5, 0.2_7_0_7_2_4_1_8],
					            [-1.6_9_2_0_0_3_8, -0.5_8_7_3_5_0_5, 1.9_3_2_9_5_9_9],
					            [-2.9_5_6_3_9_8_5, -1.6_9_9_3_8_3_5, 1.7_9_7_2_0_5_2],
					        ]
					    ]     ,       dtype=tf.floataa     ,       )

					self.assertTrue(np.allclose(output[:, :3, :3].numpy()     ,       expected_slice.numpy()     ,       atol=1E-4    )    )










"""simple docstring"""

import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


A_						:    List[Any]				=      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_						:    Tuple				=      parser.parse_args()


A_						:    Optional[int]				=      'cpu'
A_						:    Dict				=      'a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'

A_						:    List[str]				=      'path-to-your-trained-model'
A_						:    Any				=      StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
							A_						:    Tuple				=      DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
A_						:    Tuple				=      pipe.to(device)

# to channels last
A_						:    List[str]				=      pipe.unet.to(memory_format=torch.channels_last)
A_						:    List[str]				=      pipe.vae.to(memory_format=torch.channels_last)
A_						:    Optional[int]				=      pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
							A_						:    Union[str, Any]				=      pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
A_						:    List[Any]				=      torch.randn(2, 4, 64, 64)
A_						:    int				=      torch.rand(1) * 999
A_						:    int				=      torch.randn(2, 77, 768)
A_						:    Tuple				=      (sample, timestep, encoder_hidden_status)
try:
							A_						:    Any				=      ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
							A_						:    List[str]				=      ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
A_						:    str				=      ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
A_						:    Optional[int]				=      ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
							A_						:    List[str]				=      ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
A_						:    Union[str, Any]				=      666
A_						:    Optional[Any]				=      torch.Generator(device).manual_seed(seed)
A_						:    Union[str, Any]				=      {'generator': generator}
if args.steps is not None:
							A_						:    int				=      args.steps

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

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





