


'''simple docstring'''
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    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				42



class    lowercase	(							A__	,		A__					):

		"""simple docstring"""

		@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__()
							UpperCamelCase__   :int												= num_attention_heads
							UpperCamelCase__   :Optional[Any]												= attention_head_dim
							UpperCamelCase__   :Union[str, Any]												= num_attention_heads * attention_head_dim

							UpperCamelCase__   :Tuple												= in_channels

							UpperCamelCase__   :Tuple												= torch.nn.GroupNorm(num_groups=UpperCamelCase_    ,   num_channels=UpperCamelCase_    ,   eps=1e-6    ,   affine=UpperCamelCase_							)
							UpperCamelCase__   :int												= nn.Linear(UpperCamelCase_    ,   UpperCamelCase_							)

							# 3. Define transformers blocks
							UpperCamelCase__   :Any												= 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_							)
							    ]							)

							UpperCamelCase__   :str												= nn.Linear(UpperCamelCase_    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_=None    ,   UpperCamelCase_=None    ,   UpperCamelCase_=None    ,   UpperCamelCase_=1    ,   UpperCamelCase_=None    ,   UpperCamelCase_ = True    ,   ):

							'''simple docstring'''


							UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__   :int												= hidden_states.shape
							UpperCamelCase__   :int												= batch_frames // num_frames

							UpperCamelCase__   :List[str]												= hidden_states

							UpperCamelCase__   :Tuple												= hidden_states[None, :].reshape(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							)
							UpperCamelCase__   :Tuple												= hidden_states.permute(0    ,   2    ,   1    ,   3    ,   4							)

							UpperCamelCase__   :Tuple												= self.norm(UpperCamelCase_							)
							UpperCamelCase__   :Any												= hidden_states.permute(0    ,   3    ,   4    ,   2    ,   1							).reshape(batch_size * height * width    ,   UpperCamelCase_    ,   UpperCamelCase_							)

							UpperCamelCase__   :Optional[int]												= self.proj_in(UpperCamelCase_							)

							# 2. Blocks
							for block in self.transformer_blocks:
												UpperCamelCase__   :Optional[Any]												= block(
												    UpperCamelCase_    ,   encoder_hidden_states=UpperCamelCase_    ,   timestep=UpperCamelCase_    ,   cross_attention_kwargs=UpperCamelCase_    ,   class_labels=UpperCamelCase_    ,   )

							# 3. Output
							UpperCamelCase__   :str												= self.proj_out(UpperCamelCase_							)
							UpperCamelCase__   :str												= (
							    hidden_states[None, None, :]
							    .reshape(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							)
							    .permute(0    ,   3    ,   4    ,   1    ,   2							)
							    .contiguous()
							)
							UpperCamelCase__   :List[str]												= hidden_states.reshape(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							)

							UpperCamelCase__   :Dict												= hidden_states + residual

							if not return_dict:
												return (output,)

							return TransformerTemporalModelOutput(sample=UpperCamelCase_							)



'''simple docstring'''
import unittest
from dataclasses import dataclass

import pytest

from accelerate.commands.config.config_args import SageMakerConfig
from accelerate.utils import ComputeEnvironment
from accelerate.utils.launch import _convert_nargs_to_dict
@dataclass
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				ComputeEnvironment.AMAZON_SAGEMAKER
		_a     =				True
		_a     =				'ml.p3.2xlarge'
		_a     =				'accelerate_sagemaker_execution_role'
		_a     =				'hf-sm'
		_a     =				'us-east-1'
		_a     =				1
		_a     =				'accelerate-sagemaker-1'
		_a     =				'1.6'
		_a     =				'4.4'
		_a     =				'train.py'
		_a     =				[
		    '--model_name_or_path',
		    'bert',
		    '--do_train',
		    'False',
		    '--epochs',
		    '3',
		    '--learning_rate',
		    '5e-5',
		    '--max_steps',
		    '50.5',
		]
		_a     =				[
		    '--model_name_or_path',
		    'bert',
		    '--do_train',
		    '--do_test',
		    'False',
		    '--do_predict',
		    '--epochs',
		    '3',
		    '--learning_rate',
		    '5e-5',
		    '--max_steps',
		    '50.5',
		]



class    lowercase	(							unittest.TestCase					):

		"""simple docstring"""

		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= _convert_nargs_to_dict(MockLaunchConfig.success_training_script_args							)
							assert isinstance(converted_args['''model_name_or_path''']    ,   UpperCamelCase_							)
							assert isinstance(converted_args['''do_train''']    ,   UpperCamelCase_							)
							assert isinstance(converted_args['''epochs''']    ,   UpperCamelCase_							)
							assert isinstance(converted_args['''learning_rate''']    ,   UpperCamelCase_							)
							assert isinstance(converted_args['''max_steps''']    ,   UpperCamelCase_							)

							with pytest.raises(UpperCamelCase_							):
												_convert_nargs_to_dict(MockLaunchConfig.fail_training_script_args							)