
"""simple docstring"""



import importlib
import inspect
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
_snake_case          =						'''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
_snake_case          =						importlib.util.spec_from_file_location(
    '''transformers''',
    os.path.join(PATH_TO_TRANSFORMERS, '''__init__.py'''),
    submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
_snake_case          =						spec.loader.load_module()

_snake_case          =						transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
_snake_case          =						re.compile('''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


_snake_case          =						{
    '''CLIPConfigMixin''',
    '''DecisionTransformerConfigMixin''',
    '''EncoderDecoderConfigMixin''',
    '''RagConfigMixin''',
    '''SpeechEncoderDecoderConfigMixin''',
    '''VisionEncoderDecoderConfigMixin''',
    '''VisionTextDualEncoderConfigMixin''',
}






def 	__snake_case  (    ):






							"""simple docstring"""



							_lowerCAmelCase  	=			[]

							for config_class in list(CONFIG_MAPPING.values()						):
														_lowerCAmelCase  	=			False

														# source code of `config_class`
														_lowerCAmelCase  	=			inspect.getsource(SCREAMING_SNAKE_CASE						)
														_lowerCAmelCase  	=			_re_checkpoint.findall(SCREAMING_SNAKE_CASE						)

														for checkpoint in checkpoints:
																					# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
																					# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
																					_lowerCAmelCase	,		_lowerCAmelCase  	=			checkpoint

																					# verify the checkpoint name corresponds to the checkpoint link
																					_lowerCAmelCase  	=			f"""https://huggingface.co/{ckpt_name}"""
																					if ckpt_link == ckpt_link_from_name:
																												_lowerCAmelCase  	=			True
																												break

														_lowerCAmelCase  	=			config_class.__name__
														if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
																					configs_without_checkpoint.append(SCREAMING_SNAKE_CASE						)

							if len(SCREAMING_SNAKE_CASE						) > 0:
														_lowerCAmelCase  	=			'\n'.join(sorted(SCREAMING_SNAKE_CASE						)						)
														raise ValueError(f"""The following configurations don't contain any valid checkpoint:\n{message}"""						)


if __name__ == "__main__":
	check_config_docstrings_have_checkpoints()








"""simple docstring"""



import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


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


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

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

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

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

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

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

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






