



import pprint

import requests

SCREAMING_SNAKE_CASE     				=						"https://zenquotes.io/api"


def snake_case__  (			)		->							Any:
		return requests.get(API_ENDPOINT_URL + "/today" ).json()


def snake_case__  (			)		->							int:
		return requests.get(API_ENDPOINT_URL + "/random" ).json()


if __name__ == "__main__":
			SCREAMING_SNAKE_CASE     				=						random_quotes()
			pprint.pprint(response)






from dataclasses import dataclass
from typing import Dict, Optional, Union

import torch
import torch.nn.functional as F
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .attention_processor import AttentionProcessor, AttnProcessor
from .embeddings import TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin



@dataclass
class 	lowerCamelCase      (						lowercase__  ):







					'''simple docstring'''







					lowerCAmelCase_				:    torch.FloatTensor





class 	lowerCamelCase      (						lowercase__,     lowercase__  ):







					'''simple docstring'''







					@register_to_config
					def __init__(			self    ,	lowerCAmelCase = 32    ,	lowerCAmelCase = 64    ,	lowerCAmelCase = 20    ,	lowerCAmelCase = 768    ,	lowerCAmelCase=77    ,	lowerCAmelCase=4    ,	lowerCAmelCase = 0.0    ,	lowerCAmelCase = "silu"    ,	lowerCAmelCase = None    ,	lowerCAmelCase = None    ,	lowerCAmelCase = "linear"    ,	lowerCAmelCase = "prd"    ,	lowerCAmelCase = None    ,	lowerCAmelCase = None    ,	lowerCAmelCase = None    ,	):
							super().__init__()
							UpperCAmelCase_						=				num_attention_heads
							UpperCAmelCase_						=				attention_head_dim
							UpperCAmelCase_						=				num_attention_heads * attention_head_dim
							UpperCAmelCase_						=				additional_embeddings

							UpperCAmelCase_						=				time_embed_dim or inner_dim
							UpperCAmelCase_						=				embedding_proj_dim or embedding_dim
							UpperCAmelCase_						=				clip_embed_dim or embedding_dim

							UpperCAmelCase_						=				Timesteps(lowerCAmelCase    ,	lowerCAmelCase    ,	0     )
							UpperCAmelCase_						=				TimestepEmbedding(lowerCAmelCase    ,	lowerCAmelCase    ,	out_dim=lowerCAmelCase    ,	act_fn=lowerCAmelCase     )

							UpperCAmelCase_						=				nn.Linear(lowerCAmelCase    ,	lowerCAmelCase     )

							if embedding_proj_norm_type is None:
									UpperCAmelCase_						=				None
							elif embedding_proj_norm_type == "layer":
									UpperCAmelCase_						=				nn.LayerNorm(lowerCAmelCase     )
							else:
									raise ValueError(f'''unsupported embedding_proj_norm_type: {embedding_proj_norm_type}'''     )

							UpperCAmelCase_						=				nn.Linear(lowerCAmelCase    ,	lowerCAmelCase     )

							if encoder_hid_proj_type is None:
									UpperCAmelCase_						=				None
							elif encoder_hid_proj_type == "linear":
									UpperCAmelCase_						=				nn.Linear(lowerCAmelCase    ,	lowerCAmelCase     )
							else:
									raise ValueError(f'''unsupported encoder_hid_proj_type: {encoder_hid_proj_type}'''     )

							UpperCAmelCase_						=				nn.Parameter(torch.zeros(1    ,	num_embeddings + additional_embeddings    ,	lowerCAmelCase     )     )

							if added_emb_type == "prd":
									UpperCAmelCase_						=				nn.Parameter(torch.zeros(1    ,	1    ,	lowerCAmelCase     )     )
							elif added_emb_type is None:
									UpperCAmelCase_						=				None
							else:
									raise ValueError(
									    f'''`added_emb_type`: {added_emb_type} is not supported. Make sure to choose one of `\'prd\'` or `None`.'''     )

							UpperCAmelCase_						=				nn.ModuleList(
							    [
							        BasicTransformerBlock(
							            lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	dropout=lowerCAmelCase    ,	activation_fn="gelu"    ,	attention_bias=lowerCAmelCase    ,	)
							        for d in range(lowerCAmelCase     )
							    ]     )

							if norm_in_type == "layer":
									UpperCAmelCase_						=				nn.LayerNorm(lowerCAmelCase     )
							elif norm_in_type is None:
									UpperCAmelCase_						=				None
							else:
									raise ValueError(f'''Unsupported norm_in_type: {norm_in_type}.'''     )

							UpperCAmelCase_						=				nn.LayerNorm(lowerCAmelCase     )

							UpperCAmelCase_						=				nn.Linear(lowerCAmelCase    ,	lowerCAmelCase     )

							UpperCAmelCase_						=				torch.full(
							    [num_embeddings + additional_embeddings, num_embeddings + additional_embeddings]    ,	-10000.0     )
							causal_attention_mask.triu_(1     )
							UpperCAmelCase_						=				causal_attention_mask[None, ...]
							self.register_buffer("causal_attention_mask"    ,	lowerCAmelCase    ,	persistent=lowerCAmelCase     )

							UpperCAmelCase_						=				nn.Parameter(torch.zeros(1    ,	lowerCAmelCase     )     )
							UpperCAmelCase_						=				nn.Parameter(torch.zeros(1    ,	lowerCAmelCase     )     )



					@property
					# Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
					def    A__		(			self     ):
							UpperCAmelCase_						=				{}

							def fn_recursive_add_processors(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase     ):
									if hasattr(lowerCAmelCase    ,	"set_processor"     ):
											UpperCAmelCase_						=				module.processor

									for sub_name, child in module.named_children():
											fn_recursive_add_processors(f'''{name}.{sub_name}'''    ,	lowerCAmelCase    ,	lowerCAmelCase     )

									return processors

							for name, module in self.named_children():
									fn_recursive_add_processors(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase     )

							return processors



					def    A__		(			self    ,	lowerCAmelCase     ):
							UpperCAmelCase_						=				len(self.attn_processors.keys()     )

							if isinstance(lowerCAmelCase    ,	lowerCAmelCase     ) and len(lowerCAmelCase     ) != count:
									raise ValueError(
									    f'''A dict of processors was passed, but the number of processors {len(lowerCAmelCase     )} does not match the'''
									    f''' number of attention layers: {count}. Please make sure to pass {count} processor classes.'''     )

							def fn_recursive_attn_processor(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase     ):
									if hasattr(lowerCAmelCase    ,	"set_processor"     ):
											if not isinstance(lowerCAmelCase    ,	lowerCAmelCase     ):
													module.set_processor(lowerCAmelCase     )
											else:
													module.set_processor(processor.pop(f'''{name}.processor'''     )     )

									for sub_name, child in module.named_children():
											fn_recursive_attn_processor(f'''{name}.{sub_name}'''    ,	lowerCAmelCase    ,	lowerCAmelCase     )

							for name, module in self.named_children():
									fn_recursive_attn_processor(lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase     )



					def    A__		(			self     ):
							self.set_attn_processor(AttnProcessor()     )



					def    A__		(			self    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase    ,	lowerCAmelCase = None    ,	lowerCAmelCase = None    ,	lowerCAmelCase = True    ,	):
							UpperCAmelCase_						=				hidden_states.shape[0]

							UpperCAmelCase_						=				timestep
							if not torch.is_tensor(lowerCAmelCase     ):
									UpperCAmelCase_						=				torch.tensor([timesteps]    ,	dtype=torch.long    ,	device=hidden_states.device     )
							elif torch.is_tensor(lowerCAmelCase     ) and len(timesteps.shape     ) == 0:
									UpperCAmelCase_						=				timesteps[None].to(hidden_states.device     )

							# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
							UpperCAmelCase_						=				timesteps * torch.ones(lowerCAmelCase    ,	dtype=timesteps.dtype    ,	device=timesteps.device     )

							UpperCAmelCase_						=				self.time_proj(lowerCAmelCase     )

							# timesteps does not contain any weights and will always return f32 tensors
							# but time_embedding might be fp16, so we need to cast here.
							UpperCAmelCase_						=				timesteps_projected.to(dtype=self.dtype     )
							UpperCAmelCase_						=				self.time_embedding(lowerCAmelCase     )

							if self.embedding_proj_norm is not None:
									UpperCAmelCase_						=				self.embedding_proj_norm(lowerCAmelCase     )

							UpperCAmelCase_						=				self.embedding_proj(lowerCAmelCase     )
							if self.encoder_hidden_states_proj is not None and encoder_hidden_states is not None:
									UpperCAmelCase_						=				self.encoder_hidden_states_proj(lowerCAmelCase     )
							elif self.encoder_hidden_states_proj is not None and encoder_hidden_states is None:
									raise ValueError("`encoder_hidden_states_proj` requires `encoder_hidden_states` to be set"     )

							UpperCAmelCase_						=				self.proj_in(lowerCAmelCase     )

							UpperCAmelCase_						=				self.positional_embedding.to(hidden_states.dtype     )

							UpperCAmelCase_						=				[]
							UpperCAmelCase_						=				0

							if encoder_hidden_states is not None:
									additional_embeds.append(lowerCAmelCase     )
									additional_embeddings_len += encoder_hidden_states.shape[1]

							if len(proj_embeddings.shape     ) == 2:
									UpperCAmelCase_						=				proj_embeddings[:, None, :]

							if len(hidden_states.shape     ) == 2:
									UpperCAmelCase_						=				hidden_states[:, None, :]

							UpperCAmelCase_						=				additional_embeds + [
							    proj_embeddings,
							    time_embeddings[:, None, :],
							    hidden_states,
							]

							if self.prd_embedding is not None:
									UpperCAmelCase_						=				self.prd_embedding.to(hidden_states.dtype     ).expand(lowerCAmelCase    ,	-1    ,	-1     )
									additional_embeds.append(lowerCAmelCase     )

							UpperCAmelCase_						=				torch.cat(
							    lowerCAmelCase    ,	dim=1    ,	)

							# Allow positional_embedding to not include the `addtional_embeddings` and instead pad it with zeros for these additional tokens
							UpperCAmelCase_						=				additional_embeddings_len + proj_embeddings.shape[1] + 1
							if positional_embeddings.shape[1] < hidden_states.shape[1]:
									UpperCAmelCase_						=				F.pad(
									    lowerCAmelCase    ,	(
									        0,
									        0,
									        additional_embeddings_len,
									        self.prd_embedding.shape[1] if self.prd_embedding is not None else 0,
									    )    ,	value=0.0    ,	)

							UpperCAmelCase_						=				hidden_states + positional_embeddings

							if attention_mask is not None:
									UpperCAmelCase_						=				(1 - attention_mask.to(hidden_states.dtype     )) * -10000.0
									UpperCAmelCase_						=				F.pad(lowerCAmelCase    ,	(0, self.additional_embeddings)    ,	value=0.0     )
									UpperCAmelCase_						=				(attention_mask[:, None, :] + self.causal_attention_mask).to(hidden_states.dtype     )
									UpperCAmelCase_						=				attention_mask.repeat_interleave(self.config.num_attention_heads    ,	dim=0     )

							if self.norm_in is not None:
									UpperCAmelCase_						=				self.norm_in(lowerCAmelCase     )

							for block in self.transformer_blocks:
									UpperCAmelCase_						=				block(lowerCAmelCase    ,	attention_mask=lowerCAmelCase     )

							UpperCAmelCase_						=				self.norm_out(lowerCAmelCase     )

							if self.prd_embedding is not None:
									UpperCAmelCase_						=				hidden_states[:, -1]
							else:
									UpperCAmelCase_						=				hidden_states[:, additional_embeddings_len:]

							UpperCAmelCase_						=				self.proj_to_clip_embeddings(lowerCAmelCase     )

							if not return_dict:
									return (predicted_image_embedding,)

							return PriorTransformerOutput(predicted_image_embedding=lowerCAmelCase     )



					def    A__		(			self    ,	lowerCAmelCase     ):
							UpperCAmelCase_						=				(prior_latents * self.clip_std) + self.clip_mean
							return prior_latents

