






from dataclasses import dataclass
from typing import Optional

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .modeling_utils import ModelMixin


@dataclass
class     __SCREAMING_SNAKE_CASE					(   __lowercase):
						_SCREAMING_SNAKE_CASE	:       torch.FloatTensor




class     __SCREAMING_SNAKE_CASE					(   __lowercase		,					__lowercase):






						@register_to_config
						def __init__(	self     ,						_UpperCamelCase = 16     ,						_UpperCamelCase = 88     ,						_UpperCamelCase = None     ,						_UpperCamelCase = None     ,						_UpperCamelCase = 1     ,						_UpperCamelCase = 0.0     ,						_UpperCamelCase = 32     ,						_UpperCamelCase = None     ,						_UpperCamelCase = False     ,						_UpperCamelCase = None     ,						_UpperCamelCase = "geglu"     ,						_UpperCamelCase = True     ,						_UpperCamelCase = True     ,						):






												"""simple docstring"""
												super().__init__()
												lowerCAmelCase__    						=						num_attention_heads
												lowerCAmelCase__    						=						attention_head_dim
												lowerCAmelCase__    						=						num_attention_heads * attention_head_dim

												lowerCAmelCase__    						=						in_channels

												lowerCAmelCase__    						=						torch.nn.GroupNorm(num_groups=_UpperCamelCase     ,						num_channels=_UpperCamelCase     ,						eps=1E-6     ,						affine=_UpperCamelCase   )
												lowerCAmelCase__    						=						nn.Linear(_UpperCamelCase     ,						_UpperCamelCase   )

												# 3. Define transformers blocks
												lowerCAmelCase__    						=						nn.ModuleList(
												    [
												        BasicTransformerBlock(
												            _UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						dropout=_UpperCamelCase     ,						cross_attention_dim=_UpperCamelCase     ,						activation_fn=_UpperCamelCase     ,						attention_bias=_UpperCamelCase     ,						double_self_attention=_UpperCamelCase     ,						norm_elementwise_affine=_UpperCamelCase     ,						)
												        for d in range(_UpperCamelCase   )
												    ]   )

												lowerCAmelCase__    						=						nn.Linear(_UpperCamelCase     ,						_UpperCamelCase   )







						def       UpperCamelCase__      (	self     ,						_UpperCamelCase     ,						_UpperCamelCase=None     ,						_UpperCamelCase=None     ,						_UpperCamelCase=None     ,						_UpperCamelCase=1     ,						_UpperCamelCase=None     ,						_UpperCamelCase = True     ,						):






												"""simple docstring"""
												lowerCAmelCase__						,       lowerCAmelCase__						,       lowerCAmelCase__						,       lowerCAmelCase__    						=						hidden_states.shape
												lowerCAmelCase__    						=						batch_frames // num_frames

												lowerCAmelCase__    						=						hidden_states

												lowerCAmelCase__    						=						hidden_states[None, :].reshape(_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase   )
												lowerCAmelCase__    						=						hidden_states.permute(0     ,						2     ,						1     ,						3     ,						4   )

												lowerCAmelCase__    						=						self.norm(_UpperCamelCase   )
												lowerCAmelCase__    						=						hidden_states.permute(0     ,						3     ,						4     ,						2     ,						1   ).reshape(batch_size * height * width     ,						_UpperCamelCase     ,						_UpperCamelCase   )

												lowerCAmelCase__    						=						self.proj_in(_UpperCamelCase   )

												# 2. Blocks
												for block in self.transformer_blocks:
																		lowerCAmelCase__    						=						block(
																		    _UpperCamelCase     ,						encoder_hidden_states=_UpperCamelCase     ,						timestep=_UpperCamelCase     ,						cross_attention_kwargs=_UpperCamelCase     ,						class_labels=_UpperCamelCase     ,						)

												# 3. Output
												lowerCAmelCase__    						=						self.proj_out(_UpperCamelCase   )
												lowerCAmelCase__    						=						(
												    hidden_states[None, None, :]
												    .reshape(_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase   )
												    .permute(0     ,						3     ,						4     ,						1     ,						2   )
												    .contiguous()
												)
												lowerCAmelCase__    						=						hidden_states.reshape(_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase     ,						_UpperCamelCase   )

												lowerCAmelCase__    						=						hidden_states + residual

												if not return_dict:
																		return (output,)

												return TransformerTemporalModelOutput(sample=_UpperCamelCase   )













from __future__ import annotations

from functools import lru_cache
from math import ceil

__snake_case    :    Union[str, Any]         =     1_00

__snake_case    :    Tuple         =     set(range(3, NUM_PRIMES, 2))
primes.add(2)
__snake_case    :    int

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
					if prime not in primes:
										continue
					primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))







@lru_cache(maxsize=100		)
def 	_UpperCamelCase   (    UpperCamelCase_       :					int		)  ->   set[int]:

						"""simple docstring"""



						if number_to_partition < 0:
												return set()
						elif number_to_partition == 0:
												return {1}

						lowerCAmelCase__    						=						set()
						lowerCAmelCase__    						=						42
						lowerCAmelCase__    						=						42

						for prime in primes:
												if prime > number_to_partition:
																		continue
												for sub in partition(number_to_partition - prime		):
																		ret.add(sub * prime		)

						return ret







def 	_UpperCamelCase   (    UpperCamelCase_       :					int = 5000		)  ->   int | None:

						"""simple docstring"""



						for number_to_partition in range(1    ,       UpperCamelCase_		):
												if len(partition(UpperCamelCase_		)		) > number_unique_partitions:
																		return number_to_partition
						return None


if __name__ == "__main__":
					print(f'{solution() = }')





