




import inspect
from typing import Optional, Union

import numpy as np
import PIL
import torch
from torch.nn import functional as F
from torchvision import transforms
from transformers import CLIPFeatureExtractor, CLIPModel, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    DPMSolverMultistepScheduler,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion import StableDiffusionPipelineOutput
from diffusers.utils import (
    PIL_INTERPOLATION,
    randn_tensor,
)






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__   )			->							Tuple:





					'''simple docstring'''


					if isinstance(__magic_name__			,		torch.Tensor   ):
										return image
					elif isinstance(__magic_name__			,		PIL.Image.Image   ):
										lowercase :       List[Any]       =			[image]

					if isinstance(image[0]			,		PIL.Image.Image   ):
										lowercase :       str       =			[np.array(i.resize((w, h)			,		resample=PIL_INTERPOLATION['''lanczos''']   )   )[None, :] for i in image]
										lowercase :       List[Any]       =			np.concatenate(__magic_name__			,		axis=0   )
										lowercase :       Tuple       =			np.array(__magic_name__   ).astype(np.floataa   ) / 2_55.0
										lowercase :       Optional[int]       =			image.transpose(0			,		3			,		1			,		2   )
										lowercase :       Dict       =			2.0 * image - 1.0
										lowercase :       Dict       =			torch.from_numpy(__magic_name__   )
					elif isinstance(image[0]			,		torch.Tensor   ):
										lowercase :       List[Any]       =			torch.cat(__magic_name__			,		dim=0   )
					return image






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__=0.9_9_9_5   )			->							Union[str, Any]:





					'''simple docstring'''


					if not isinstance(__magic_name__			,		np.ndarray   ):
										lowercase :       Dict       =			True
										lowercase :       Optional[int]       =			va.device
										lowercase :       str       =			va.cpu().numpy()
										lowercase :       int       =			va.cpu().numpy()

					lowercase :       Union[str, Any]       =			np.sum(va * va / (np.linalg.norm(__magic_name__   ) * np.linalg.norm(__magic_name__   ))   )
					if np.abs(__magic_name__   ) > DOT_THRESHOLD:
										lowercase :       Any       =			(1 - t) * va + t * va
					else:
										lowercase :       List[Any]       =			np.arccos(__magic_name__   )
										lowercase :       List[str]       =			np.sin(__magic_name__   )
										lowercase :       List[Any]       =			theta_a * t
										lowercase :       Tuple       =			np.sin(__magic_name__   )
										lowercase :       Union[str, Any]       =			np.sin(theta_a - theta_t   ) / sin_theta_a
										lowercase :       int       =			sin_theta_t / sin_theta_a
										lowercase :       Union[str, Any]       =			sa * va + sa * va

					if inputs_are_torch:
										lowercase :       List[str]       =			torch.from_numpy(__magic_name__   ).to(__magic_name__   )

					return va






def  snake_case(    __magic_name__			,		__magic_name__   )			->							Optional[int]:





					'''simple docstring'''


					lowercase :       int       =			F.normalize(__magic_name__			,		dim=-1   )
					lowercase :       Optional[Any]       =			F.normalize(__magic_name__			,		dim=-1   )
					return (x - y).norm(dim=-1   ).div(2   ).arcsin().pow(2   ).mul(2   )






def  snake_case(    __magic_name__			,		__magic_name__   )			->							Union[str, Any]:





					'''simple docstring'''


					for param in model.parameters():
										lowercase :       Union[str, Any]       =			value



class 						_A (  _lowerCamelCase				):






		def __init__(  self		:     Tuple				,						_A		:     AutoencoderKL				,						_A		:     CLIPTextModel				,						_A		:     CLIPModel				,						_A		:     CLIPTokenizer				,						_A		:     UNetaDConditionModel				,						_A		:     Union[PNDMScheduler, LMSDiscreteScheduler, DDIMScheduler, DPMSolverMultistepScheduler]				,						_A		:     CLIPFeatureExtractor				,						_A		:     Tuple=None				,						_A		:     Union[str, Any]=None				,						_A		:     Dict=None				,						)		->   List[str]:






							"""simple docstring"""







							super().__init__()
							self.register_modules(
							    vae=_A				,						text_encoder=_A				,						clip_model=_A				,						tokenizer=_A				,						unet=_A				,						scheduler=_A				,						feature_extractor=_A				,						coca_model=_A				,						coca_tokenizer=_A				,						coca_transform=_A				,						)
							lowercase :       Dict       =			(
							    feature_extractor.size
							    if isinstance(feature_extractor.size				,						_A				)
							    else feature_extractor.size['''shortest_edge''']
							)
							lowercase :       Tuple       =			transforms.Normalize(mean=feature_extractor.image_mean				,						std=feature_extractor.image_std				)
							set_requires_grad(self.text_encoder				,						_A				)
							set_requires_grad(self.clip_model				,						_A				)






		def  __a      (  self		:     str				,						_A		:     Optional[Union[str, int]] = "auto"				)		->   List[Any]:






							"""simple docstring"""







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






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






							"""simple docstring"""







							self.enable_attention_slicing(_A				)






		def  __a      (  self		:     int				)		->   Tuple:






							"""simple docstring"""







							set_requires_grad(self.vae				,						_A				)






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






							"""simple docstring"""







							set_requires_grad(self.vae				,						_A				)






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






							"""simple docstring"""







							set_requires_grad(self.unet				,						_A				)






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






							"""simple docstring"""







							set_requires_grad(self.unet				,						_A				)






		def  __a      (  self		:     Tuple				,						_A		:     str				,						_A		:     List[str]				,						_A		:     Any				)		->   Dict:






							"""simple docstring"""







							lowercase :       Tuple       =			min(int(num_inference_steps * strength				)				,						_A				)

							lowercase :       Tuple       =			max(num_inference_steps - init_timestep				,						0				)
							lowercase :       str       =			self.scheduler.timesteps[t_start:]

							return timesteps, num_inference_steps - t_start






		def  __a      (  self		:     str				,						_A		:     Tuple				,						_A		:     List[str]				,						_A		:     Optional[int]				,						_A		:     int				,						_A		:     List[str]				,						_A		:     Any=None				)		->   Optional[int]:






							"""simple docstring"""







							if not isinstance(_A				,						torch.Tensor				):
												raise ValueError(f"""`image` has to be of type `torch.Tensor` but is {type(_A				)}"""				)

							lowercase :       int       =			image.to(device=_A				,						dtype=_A				)

							if isinstance(_A				,						_A				):
												lowercase :       str       =			[
												    self.vae.encode(image[i : i + 1]				).latent_dist.sample(generator[i]				) for i in range(_A				)
												]
												lowercase :       Tuple       =			torch.cat(_A				,						dim=0				)
							else:
												lowercase :       Tuple       =			self.vae.encode(_A				).latent_dist.sample(_A				)

							# Hardcode 0.18215 because stable-diffusion-2-base has not self.vae.config.scaling_factor
							lowercase :       Optional[int]       =			0.18_215 * init_latents
							lowercase :       Dict       =			init_latents.repeat_interleave(_A				,						dim=0				)

							lowercase :       Any       =			randn_tensor(init_latents.shape				,						generator=_A				,						device=_A				,						dtype=_A				)

							# get latents
							lowercase :       Dict       =			self.scheduler.add_noise(_A				,						_A				,						_A				)
							lowercase :       Dict       =			init_latents

							return latents






		def  __a      (  self		:     List[Any]				,						_A		:     Union[str, Any]				)		->   Tuple:






							"""simple docstring"""







							lowercase :       int       =			self.coca_transform(_A				).unsqueeze(0				)
							with torch.no_grad(), torch.cuda.amp.autocast():
												lowercase :       List[Any]       =			self.coca_model.generate(transformed_image.to(device=self.device				,						dtype=self.coca_model.dtype				)				)
							lowercase :       List[Any]       =			self.coca_tokenizer.decode(generated[0].cpu().numpy()				)
							return generated.split('''<end_of_text>'''				)[0].replace('''<start_of_text>'''				,						''''''				).rstrip(''' .,'''				)






		def  __a      (  self		:     Tuple				,						_A		:     int				,						_A		:     Any				)		->   str:






							"""simple docstring"""







							lowercase :       Any       =			self.feature_extractor.preprocess(_A				)
							lowercase :       Union[str, Any]       =			torch.from_numpy(clip_image_input['''pixel_values'''][0]				).unsqueeze(0				).to(self.device				).half()
							lowercase :       int       =			self.clip_model.get_image_features(_A				)
							lowercase :       str       =			image_embeddings_clip / image_embeddings_clip.norm(p=2				,						dim=-1				,						keepdim=_A				)
							lowercase :       Any       =			image_embeddings_clip.repeat_interleave(_A				,						dim=0				)
							return image_embeddings_clip






		@torch.enable_grad()
		def  __a      (  self		:     List[Any]				,						_A		:     Any				,						_A		:     str				,						_A		:     str				,						_A		:     int				,						_A		:     List[str]				,						_A		:     int				,						_A		:     List[str]				,						)		->   Optional[Any]:






							"""simple docstring"""







							lowercase :       Any       =			latents.detach().requires_grad_()

							lowercase :       Any       =			self.scheduler.scale_model_input(_A				,						_A				)

							# predict the noise residual
							lowercase :       Tuple       =			self.unet(_A				,						_A				,						encoder_hidden_states=_A				).sample

							if isinstance(self.scheduler				,						(PNDMScheduler, DDIMScheduler, DPMSolverMultistepScheduler)				):
												lowercase :       Dict       =			self.scheduler.alphas_cumprod[timestep]
												lowercase :       List[str]       =			1 - alpha_prod_t
												# compute predicted original sample from predicted noise also called
												# "predicted x_0" of formula (12) from https://arxiv.org/pdf/2010.02502.pdf
												lowercase :       Union[str, Any]       =			(latents - beta_prod_t ** 0.5 * noise_pred) / alpha_prod_t ** 0.5

												lowercase :       int       =			torch.sqrt(_A				)
												lowercase :       Tuple       =			pred_original_sample * (fac) + latents * (1 - fac)
							elif isinstance(self.scheduler				,						_A				):
												lowercase :       List[str]       =			self.scheduler.sigmas[index]
												lowercase :       str       =			latents - sigma * noise_pred
							else:
												raise ValueError(f"""scheduler type {type(self.scheduler				)} not supported"""				)

							# Hardcode 0.18215 because stable-diffusion-2-base has not self.vae.config.scaling_factor
							lowercase :       Dict       =			1 / 0.18_215 * sample
							lowercase :       Dict       =			self.vae.decode(_A				).sample
							lowercase :       List[Any]       =			(image / 2 + 0.5).clamp(0				,						1				)

							lowercase :       Optional[int]       =			transforms.Resize(self.feature_extractor_size				)(_A				)
							lowercase :       Tuple       =			self.normalize(_A				).to(latents.dtype				)

							lowercase :       Dict       =			self.clip_model.get_image_features(_A				)
							lowercase :       Union[str, Any]       =			image_embeddings_clip / image_embeddings_clip.norm(p=2				,						dim=-1				,						keepdim=_A				)

							lowercase :       Union[str, Any]       =			spherical_dist_loss(_A				,						_A				).mean() * clip_guidance_scale

							lowercase :       Dict       =			-torch.autograd.grad(_A				,						_A				)[0]

							if isinstance(self.scheduler				,						_A				):
												lowercase :       Tuple       =			latents.detach() + grads * (sigma**2)
												lowercase :       List[Any]       =			noise_pred_original
							else:
												lowercase :       str       =			noise_pred_original - torch.sqrt(_A				) * grads
							return noise_pred, latents






		@torch.no_grad()
		def __call__(  self		:     Optional[int]				,						_A		:     Union[torch.FloatTensor, PIL.Image.Image]				,						_A		:     Union[torch.FloatTensor, PIL.Image.Image]				,						_A		:     Optional[str] = None				,						_A		:     Optional[str] = None				,						_A		:     Optional[int] = 512				,						_A		:     Optional[int] = 512				,						_A		:     float = 0.6				,						_A		:     Optional[int] = 50				,						_A		:     Optional[float] = 7.5				,						_A		:     Optional[int] = 1				,						_A		:     float = 0.0				,						_A		:     Optional[float] = 100				,						_A		:     Optional[torch.Generator] = None				,						_A		:     Optional[str] = "pil"				,						_A		:     bool = True				,						_A		:     float = 0.8				,						_A		:     float = 0.1				,						_A		:     float = 0.1				,						)		->   int:






							"""simple docstring"""







							if isinstance(_A				,						_A				) and len(_A				) != batch_size:
												raise ValueError(f"""You have passed {batch_size} batch_size, but only {len(_A				)} generators."""				)

							if height % 8 != 0 or width % 8 != 0:
												raise ValueError(f"""`height` and `width` have to be divisible by 8 but are {height} and {width}."""				)

							if isinstance(_A				,						torch.Generator				) and batch_size > 1:
												lowercase :       Dict       =			[generator] + [None] * (batch_size - 1)

							lowercase :       Any       =			[
							    ('''model''', self.coca_model is None),
							    ('''tokenizer''', self.coca_tokenizer is None),
							    ('''transform''', self.coca_transform is None),
							]
							lowercase :       Any       =			[x[0] for x in coca_is_none if x[1]]
							lowercase :       Tuple       =			''', '''.join(_A				)
							# generate prompts with coca model if prompt is None
							if content_prompt is None:
												if len(_A				):
																	raise ValueError(
																	    f"""Content prompt is None and CoCa [{coca_is_none_str}] is None."""
																	    f"""Set prompt or pass Coca [{coca_is_none_str}] to DiffusionPipeline."""				)
												lowercase :       Dict       =			self.get_image_description(_A				)
							if style_prompt is None:
												if len(_A				):
																	raise ValueError(
																	    f"""Style prompt is None and CoCa [{coca_is_none_str}] is None."""
																	    f""" Set prompt or pass Coca [{coca_is_none_str}] to DiffusionPipeline."""				)
												lowercase :       Union[str, Any]       =			self.get_image_description(_A				)

							# get prompt text embeddings for content and style
							lowercase :       List[Any]       =			self.tokenizer(
							    _A				,						padding='''max_length'''				,						max_length=self.tokenizer.model_max_length				,						truncation=_A				,						return_tensors='''pt'''				,						)
							lowercase :       Tuple       =			self.text_encoder(content_text_input.input_ids.to(self.device				)				)[0]

							lowercase :       Union[str, Any]       =			self.tokenizer(
							    _A				,						padding='''max_length'''				,						max_length=self.tokenizer.model_max_length				,						truncation=_A				,						return_tensors='''pt'''				,						)
							lowercase :       str       =			self.text_encoder(style_text_input.input_ids.to(self.device				)				)[0]

							lowercase :       Union[str, Any]       =			slerp(_A				,						_A				,						_A				)

							# duplicate text embeddings for each generation per prompt
							lowercase :       List[Any]       =			text_embeddings.repeat_interleave(_A				,						dim=0				)

							# set timesteps
							lowercase :       List[str]       =			'''offset''' in set(inspect.signature(self.scheduler.set_timesteps				).parameters.keys()				)
							lowercase :       Dict       =			{}
							if accepts_offset:
												lowercase :       Dict       =			1

							self.scheduler.set_timesteps(_A				,						**_A				)
							# Some schedulers like PNDM have timesteps as arrays
							# It's more optimized to move all timesteps to correct device beforehand
							self.scheduler.timesteps.to(self.device				)

							lowercase :       List[str]       =			self.get_timesteps(_A				,						_A				,						self.device				)
							lowercase :       Optional[Any]       =			timesteps[:1].repeat(_A				)

							# Preprocess image
							lowercase :       Optional[int]       =			preprocess(_A				,						_A				,						_A				)
							lowercase :       Optional[int]       =			self.prepare_latents(
							    _A				,						_A				,						_A				,						text_embeddings.dtype				,						self.device				,						_A				)

							lowercase :       List[str]       =			preprocess(_A				,						_A				,						_A				)
							lowercase :       int       =			self.prepare_latents(
							    _A				,						_A				,						_A				,						text_embeddings.dtype				,						self.device				,						_A				)

							lowercase :       List[str]       =			slerp(_A				,						_A				,						_A				)

							if clip_guidance_scale > 0:
												lowercase :       Tuple       =			self.get_clip_image_embeddings(_A				,						_A				)
												lowercase :       Tuple       =			self.get_clip_image_embeddings(_A				,						_A				)
												lowercase :       int       =			slerp(
												    _A				,						_A				,						_A				)

							# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
							# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
							# corresponds to doing no classifier free guidance.
							lowercase :       str       =			guidance_scale > 1.0
							# get unconditional embeddings for classifier free guidance
							if do_classifier_free_guidance:
												lowercase :       Optional[Any]       =			content_text_input.input_ids.shape[-1]
												lowercase :       Tuple       =			self.tokenizer(['''''']				,						padding='''max_length'''				,						max_length=_A				,						return_tensors='''pt'''				)
												lowercase :       List[str]       =			self.text_encoder(uncond_input.input_ids.to(self.device				)				)[0]
												# duplicate unconditional embeddings for each generation per prompt
												lowercase :       str       =			uncond_embeddings.repeat_interleave(_A				,						dim=0				)

												# For classifier free guidance, we need to do two forward passes.
												# Here we concatenate the unconditional and text embeddings into a single batch
												# to avoid doing two forward passes
												lowercase :       Any       =			torch.cat([uncond_embeddings, text_embeddings]				)

							# get the initial random noise unless the user supplied it

							# Unlike in other pipelines, latents need to be generated in the target device
							# for 1-to-1 results reproducibility with the CompVis implementation.
							# However this currently doesn't work in `mps`.
							lowercase :       Any       =			(batch_size, self.unet.config.in_channels, height // 8, width // 8)
							lowercase :       Optional[Any]       =			text_embeddings.dtype
							if latents is None:
												if self.device.type == "mps":
																	# randn does not work reproducibly on mps
																	lowercase :       Tuple       =			torch.randn(_A				,						generator=_A				,						device='''cpu'''				,						dtype=_A				).to(
																	    self.device				)
												else:
																	lowercase :       Dict       =			torch.randn(_A				,						generator=_A				,						device=self.device				,						dtype=_A				)
							else:
												if latents.shape != latents_shape:
																	raise ValueError(f"""Unexpected latents shape, got {latents.shape}, expected {latents_shape}"""				)
												lowercase :       Union[str, Any]       =			latents.to(self.device				)

							# scale the initial noise by the standard deviation required by the scheduler
							lowercase :       Any       =			latents * self.scheduler.init_noise_sigma

							# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
							# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.
							# eta corresponds to η in DDIM paper: https://arxiv.org/abs/2010.02502
							# and should be between [0, 1]
							lowercase :       str       =			'''eta''' in set(inspect.signature(self.scheduler.step				).parameters.keys()				)
							lowercase :       Optional[Any]       =			{}
							if accepts_eta:
												lowercase :       str       =			eta

							# check if the scheduler accepts generator
							lowercase :       str       =			'''generator''' in set(inspect.signature(self.scheduler.step				).parameters.keys()				)
							if accepts_generator:
												lowercase :       Dict       =			generator

							with self.progress_bar(total=_A				):
												for i, t in enumerate(_A				):
																	# expand the latents if we are doing classifier free guidance
																	lowercase :       Tuple       =			torch.cat([latents] * 2				) if do_classifier_free_guidance else latents
																	lowercase :       List[str]       =			self.scheduler.scale_model_input(_A				,						_A				)

																	# predict the noise residual
																	lowercase :       Optional[Any]       =			self.unet(_A				,						_A				,						encoder_hidden_states=_A				).sample

																	# perform classifier free guidance
																	if do_classifier_free_guidance:
																						lowercase :       Any       =			noise_pred.chunk(2				)
																						lowercase :       List[Any]       =			noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)

																	# perform clip guidance
																	if clip_guidance_scale > 0:
																						lowercase :       Union[str, Any]       =			(
																						    text_embeddings.chunk(2				)[1] if do_classifier_free_guidance else text_embeddings
																						)
																						lowercase :       str       =			self.cond_fn(
																						    _A				,						_A				,						_A				,						_A				,						_A				,						_A				,						_A				,						)

																	# compute the previous noisy sample x_t -> x_t-1
																	lowercase :       int       =			self.scheduler.step(_A				,						_A				,						_A				,						**_A				).prev_sample

        # Hardcode 0.18215 because stable-diffusion-2-base has not self.vae.config.scaling_factor
							lowercase :       Any       =			1 / 0.18_215 * latents
							lowercase :       str       =			self.vae.decode(_A				).sample

							lowercase :       List[Any]       =			(image / 2 + 0.5).clamp(0				,						1				)
							lowercase :       List[str]       =			image.cpu().permute(0				,						2				,						3				,						1				).numpy()

							if output_type == "pil":
												lowercase :       int       =			self.numpy_to_pil(_A				)

							if not return_dict:
												return (image, None)

							return StableDiffusionPipelineOutput(images=_A				,						nsfw_content_detected=_A				)





import os
import sys
import unittest


lowerCAmelCase_						=			os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowerCAmelCase_						=			os.path.join(git_repo_path, 'src', 'diffusers')
class 						_A (  unittest.TestCase				):






  def  __a      (  self		:     Any				)		->   str:






       """simple docstring"""







       lowercase :       List[str]       =			find_backend('''    if not is_torch_available():'''				)
       self.assertEqual(_A				,						'''torch'''				)

       # backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
       # self.assertEqual(backend_with_underscore, "tensorflow_text")

       lowercase :       str       =			find_backend('''    if not (is_torch_available() and is_transformers_available()):'''				)
       self.assertEqual(_A				,						'''torch_and_transformers'''				)

       # double_backend_with_underscore = find_backend(
       #    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
       # )
       # self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

       lowercase :       str       =			find_backend(
           '''    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):'''				)
       self.assertEqual(_A				,						'''torch_and_transformers_and_onnx'''				)






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






       """simple docstring"""







       lowercase :       Dict       =			read_init()
       # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
       self.assertIn('''torch'''				,						_A				)
       self.assertIn('''torch_and_transformers'''				,						_A				)
       self.assertIn('''flax_and_transformers'''				,						_A				)
       self.assertIn('''torch_and_transformers_and_onnx'''				,						_A				)

       # Likewise, we can't assert on the exact content of a key
       self.assertIn('''UNet2DModel'''				,						objects['''torch''']				)
       self.assertIn('''FlaxUNet2DConditionModel'''				,						objects['''flax''']				)
       self.assertIn('''StableDiffusionPipeline'''				,						objects['''torch_and_transformers''']				)
       self.assertIn('''FlaxStableDiffusionPipeline'''				,						objects['''flax_and_transformers''']				)
       self.assertIn('''LMSDiscreteScheduler'''				,						objects['''torch_and_scipy''']				)
       self.assertIn('''OnnxStableDiffusionPipeline'''				,						objects['''torch_and_transformers_and_onnx''']				)






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






       """simple docstring"""







       lowercase :       List[str]       =			create_dummy_object('''CONSTANT'''				,						'''\'torch\''''				)
       self.assertEqual(_A				,						'''\nCONSTANT = None\n'''				)

       lowercase :       List[Any]       =			create_dummy_object('''function'''				,						'''\'torch\''''				)
       self.assertEqual(
           _A				,						'''\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n'''				)

       lowercase :       Tuple       =			'''
class FakeClass(metaclass=DummyObject):
    _backends = \'torch\'

    def __init__(self, *args, **kwargs):
        requires_backends(self, \'torch\')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')
'''
       lowercase :       List[Any]       =			create_dummy_object('''FakeClass'''				,						'''\'torch\''''				)
       self.assertEqual(_A				,						_A				)






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






       """simple docstring"""







       lowercase :       Optional[int]       =			'''# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, ["torch"])


class FakeClass(metaclass=DummyObject):
    _backends = ["torch"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, ["torch"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])
'''
       lowercase :       int       =			create_dummy_files({'''torch''': ['''CONSTANT''', '''function''', '''FakeClass''']}				)
       self.assertEqual(dummy_files['''torch''']				,						_A				)