

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 						__UpperCamelCase    (					_snake_case						):
	SCREAMING_SNAKE_CASE__    				=     42


class 						__UpperCamelCase    (					_snake_case     ,     _snake_case						):




	@register_to_config
	def __init__(		self	:						Optional[int]		,	lowerCAmelCase	:						int = 16		,	lowerCAmelCase	:						int = 88		,	lowerCAmelCase	:						Optional[int] = None		,	lowerCAmelCase	:						Optional[int] = None		,	lowerCAmelCase	:						int = 1		,	lowerCAmelCase	:						float = 0.0		,	lowerCAmelCase	:						int = 32		,	lowerCAmelCase	:						Optional[int] = None		,	lowerCAmelCase	:						bool = False		,	lowerCAmelCase	:						Optional[int] = None		,	lowerCAmelCase	:						str = "geglu"		,	lowerCAmelCase	:						bool = True		,	lowerCAmelCase	:						bool = True		,	):


		'''simple docstring'''







		super().__init__()
		UpperCAmelCase_       				=			num_attention_heads
		UpperCAmelCase_       				=			attention_head_dim
		UpperCAmelCase_       				=			num_attention_heads * attention_head_dim

		UpperCAmelCase_       				=			in_channels

		UpperCAmelCase_       				=			torch.nn.GroupNorm(num_groups=lowerCAmelCase		,	num_channels=lowerCAmelCase		,	eps=1e-6		,	affine=lowerCAmelCase							)
		UpperCAmelCase_       				=			nn.Linear(lowerCAmelCase		,	lowerCAmelCase							)

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

		UpperCAmelCase_       				=			nn.Linear(lowerCAmelCase		,	lowerCAmelCase							)




	def       __A					(		self	:						Dict		,	lowerCAmelCase	:						Tuple		,	lowerCAmelCase	:						Optional[int]=None		,	lowerCAmelCase	:						int=None		,	lowerCAmelCase	:						Dict=None		,	lowerCAmelCase	:						str=1		,	lowerCAmelCase	:						int=None		,	lowerCAmelCase	:						bool = True		,	):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_       				=			hidden_states.shape
		UpperCAmelCase_       				=			batch_frames // num_frames

		UpperCAmelCase_       				=			hidden_states

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

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

		UpperCAmelCase_       				=			self.proj_in(lowerCAmelCase							)

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

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

		UpperCAmelCase_       				=			hidden_states + residual

		if not return_dict:
			return (output,)

		return TransformerTemporalModelOutput(sample=lowerCAmelCase							)


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_a:    List[str] 							=			{
    """configuration_encodec""": [
        """ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """EncodecConfig""",
    ],
    """feature_extraction_encodec""": ["""EncodecFeatureExtractor"""],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_a:    List[Any] 							=			[
				    """ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST""",
				    """EncodecModel""",
				    """EncodecPreTrainedModel""",
				]

if TYPE_CHECKING:
				from .configuration_encodec import (
				    ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    EncodecConfig,
				)
				from .feature_extraction_encodec import EncodecFeatureExtractor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_encodec import (
								    ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST,
								    EncodecModel,
								    EncodecPreTrainedModel,
								)

else:
				import sys

				_a:    int 							=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)