






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     _a							(	UpperCAmelCase__     ):






  """simple docstring"""





  A_						       = 42




class     _a							(	UpperCAmelCase__    ,							UpperCAmelCase__     ):






  """simple docstring"""





  @register_to_config
  def __init__(  self		,		_UpperCAmelCase = 32		,		_UpperCAmelCase = 64		,		_UpperCAmelCase = 20		,		_UpperCAmelCase = 768		,		_UpperCAmelCase=77		,		_UpperCAmelCase=4		,		_UpperCAmelCase = 0.0		,		_UpperCAmelCase = "silu"		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = "linear"		,		_UpperCAmelCase = "prd"		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		)      ->			Any:
     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(_UpperCAmelCase		,		_UpperCAmelCase		,		0			)
     UpperCamelCase_						=  TimestepEmbedding(_UpperCAmelCase		,		_UpperCAmelCase		,		out_dim=_UpperCAmelCase		,		act_fn=_UpperCAmelCase			)

     UpperCamelCase_						=  nn.Linear(_UpperCAmelCase		,		_UpperCAmelCase			)

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

     UpperCamelCase_						=  nn.Linear(_UpperCAmelCase		,		_UpperCAmelCase			)

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

     UpperCamelCase_						=  nn.Parameter(torch.zeros(1		,		num_embeddings + additional_embeddings		,		_UpperCAmelCase			)			)

     if added_emb_type == "prd":
        UpperCamelCase_						=  nn.Parameter(torch.zeros(1		,		1		,		_UpperCAmelCase			)			)
     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(
                 _UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		dropout=_UpperCAmelCase		,		activation_fn='gelu'		,		attention_bias=_UpperCAmelCase		,		)
             for d in range(_UpperCAmelCase			)
         ]			)

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

     UpperCamelCase_						=  nn.LayerNorm(_UpperCAmelCase			)

     UpperCamelCase_						=  nn.Linear(_UpperCAmelCase		,		_UpperCAmelCase			)

     UpperCamelCase_						=  torch.full(
         [num_embeddings + additional_embeddings, num_embeddings + additional_embeddings]		,		-1_0_0_0_0.0			)
     causal_attention_mask.triu_(1			)
     UpperCamelCase_						=  causal_attention_mask[None, ...]
     self.register_buffer('causal_attention_mask'		,		_UpperCAmelCase		,		persistent=_UpperCAmelCase			)

     UpperCamelCase_						=  nn.Parameter(torch.zeros(1		,		_UpperCAmelCase			)			)
     UpperCamelCase_						=  nn.Parameter(torch.zeros(1		,		_UpperCAmelCase			)			)




  @property
  # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
  def  _UpperCAmelCase  (  self			)      ->			Dict[str, AttentionProcessor]:
     UpperCamelCase_						=  {}

     def fn_recursive_add_processors(_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase			):
        if hasattr(_UpperCAmelCase		,		'set_processor'			):
           UpperCamelCase_						=  module.processor

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

        return processors

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

     return processors




  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase			)      ->			List[Any]:
     UpperCamelCase_						=  len(self.attn_processors.keys()			)

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

     def fn_recursive_attn_processor(_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase			):
        if hasattr(_UpperCAmelCase		,		'set_processor'			):
           if not isinstance(_UpperCAmelCase		,		_UpperCAmelCase			):
              module.set_processor(_UpperCAmelCase			)
           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}"""		,		_UpperCAmelCase		,		_UpperCAmelCase			)

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




  def  _UpperCAmelCase  (  self			)      ->			Dict:
     self.set_attn_processor(AttnProcessor()			)




  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase		,		_UpperCAmelCase = None		,		_UpperCAmelCase = None		,		_UpperCAmelCase = True		,		)      ->			Union[str, Any]:
     UpperCamelCase_						=  hidden_states.shape[0]

     UpperCamelCase_						=  timestep
     if not torch.is_tensor(_UpperCAmelCase			):
        UpperCamelCase_						=  torch.tensor([timesteps]		,		dtype=torch.long		,		device=hidden_states.device			)
     elif torch.is_tensor(_UpperCAmelCase			) 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(_UpperCAmelCase		,		dtype=timesteps.dtype		,		device=timesteps.device			)

     UpperCamelCase_						=  self.time_proj(_UpperCAmelCase			)

     # 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(_UpperCAmelCase			)

     if self.embedding_proj_norm is not None:
        UpperCamelCase_						=  self.embedding_proj_norm(_UpperCAmelCase			)

     UpperCamelCase_						=  self.embedding_proj(_UpperCAmelCase			)
     if self.encoder_hidden_states_proj is not None and encoder_hidden_states is not None:
        UpperCamelCase_						=  self.encoder_hidden_states_proj(_UpperCAmelCase			)
     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(_UpperCAmelCase			)

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

     UpperCamelCase_						=  []
     UpperCamelCase_						=  0

     if encoder_hidden_states is not None:
        additional_embeds.append(_UpperCAmelCase			)
        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(_UpperCAmelCase		,		-1		,		-1			)
        additional_embeds.append(_UpperCAmelCase			)

     UpperCamelCase_						=  torch.cat(
         _UpperCAmelCase		,		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(
            _UpperCAmelCase		,		(
                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			)) * -1_0_0_0_0.0
        UpperCamelCase_						=  F.pad(_UpperCAmelCase		,		(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(_UpperCAmelCase			)

     for block in self.transformer_blocks:
        UpperCamelCase_						=  block(_UpperCAmelCase		,		attention_mask=_UpperCAmelCase			)

     UpperCamelCase_						=  self.norm_out(_UpperCAmelCase			)

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

     UpperCamelCase_						=  self.proj_to_clip_embeddings(_UpperCAmelCase			)

     if not return_dict:
        return (predicted_image_embedding,)

     return PriorTransformerOutput(predicted_image_embedding=_UpperCAmelCase			)




  def  _UpperCAmelCase  (  self		,		_UpperCAmelCase			)      ->			Tuple:
     UpperCamelCase_						=  (prior_latents * self.clip_std) + self.clip_mean
     return prior_latents













import math
from datetime import datetime, timedelta






def      _snake_case     (__lowercase):
   UpperCamelCase_						=  year % 19
   UpperCamelCase_						=  year % 4
   UpperCamelCase_						=  year % 7
   UpperCamelCase_						=  math.floor(year / 100)
   UpperCamelCase_						=  math.floor((13 + 8 * leap_day_inhibits) / 25)
   UpperCamelCase_						=  leap_day_inhibits / 4
   UpperCamelCase_						=  (
       15 - lunar_orbit_correction + leap_day_inhibits - leap_day_reinstall_number
   ) % 30
   UpperCamelCase_						=  (4 + leap_day_inhibits - leap_day_reinstall_number) % 7

   # days to be added to March 21
   UpperCamelCase_						=  (19 * metonic_cycle + secular_moon_shift) % 30

   # PHM -> Paschal Full Moon
   UpperCamelCase_						=  (
       2 * julian_leap_year
       + 4 * non_leap_year
       + 6 * days_to_add
       + century_starting_point
   ) % 7

   if days_to_add == 29 and days_from_phm_to_sunday == 6:
      return datetime(__lowercase     ,   4     ,   19)
   elif days_to_add == 28 and days_from_phm_to_sunday == 6:
      return datetime(__lowercase     ,   4     ,   18)
   else:
      return datetime(__lowercase     ,   3     ,   22) + timedelta(
          days=int(days_to_add + days_from_phm_to_sunday))


if __name__ == "__main__":
 for year in (1_9_9_4, 2_0_0_0, 2_0_1_0, 2_0_2_1, 2_0_2_3):
  snake_case__   :						Dict													=   """will be""" if year > datetime.now().year else """was"""
  print(f'Easter in {year} {tense} {gauss_easter(year)}')





