



"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


__snake_case    :		List[Any]  =logging.get_logger(__name__)

__snake_case    :		int  ={
    'google/vivit-b-16x2-kinetics400': (
        'https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json'
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}



class 	lowerCamelCase__      (							lowerCamelCase__):




		'''simple docstring'''



		snake_case_     ="""vivit"""



		def __init__(self		,__lowerCamelCase=2_24		,__lowerCamelCase=32		,__lowerCamelCase=[2, 16, 16]		,__lowerCamelCase=3		,__lowerCamelCase=7_68		,__lowerCamelCase=12		,__lowerCamelCase=12		,__lowerCamelCase=30_72		,__lowerCamelCase="gelu_fast"		,__lowerCamelCase=0.0		,__lowerCamelCase=0.0		,__lowerCamelCase=0.02		,__lowerCamelCase=1e-06		,__lowerCamelCase=True		,**__lowerCamelCase		,)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    str												=					hidden_size
						lowerCAmelCase__					:    Tuple												=					num_hidden_layers
						lowerCAmelCase__					:    str												=					num_attention_heads
						lowerCAmelCase__					:    str												=					intermediate_size
						lowerCAmelCase__					:    str												=					hidden_act
						lowerCAmelCase__					:    Any												=					hidden_dropout_prob
						lowerCAmelCase__					:    Optional[int]												=					attention_probs_dropout_prob
						lowerCAmelCase__					:    Optional[int]												=					initializer_range
						lowerCAmelCase__					:    Union[str, Any]												=					layer_norm_eps

						lowerCAmelCase__					:    Any												=					image_size
						lowerCAmelCase__					:    Tuple												=					num_frames
						lowerCAmelCase__					:    Optional[int]												=					tubelet_size
						lowerCAmelCase__					:    Any												=					num_channels
						lowerCAmelCase__					:    List[str]												=					qkv_bias

						super().__init__(**__lowerCamelCase			)






import flax.linen as nn
import jax
import jax.numpy as jnp



class 	lowerCamelCase__      (							nn.Module):




		'''simple docstring'''



		snake_case_     =42
		snake_case_     =jnp.floataa



		def 		lowerCAmelCase__				(self			)					->      List[str]:

						"""simple docstring"""






						lowerCAmelCase__					:    Dict												=					nn.Conv(
						    self.out_channels		,kernel_size=(3, 3)		,strides=(1, 1)		,padding=((1, 1), (1, 1))		,dtype=self.dtype		,)



		def __call__(self		,__lowerCamelCase			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__						,		lowerCAmelCase__						,		lowerCAmelCase__						,		lowerCAmelCase__					:    Dict												=					hidden_states.shape
						lowerCAmelCase__					:    Dict												=					jax.image.resize(
						    __lowerCamelCase		,shape=(batch, height * 2, width * 2, channels)		,method='''nearest'''		,)
						lowerCAmelCase__					:    Dict												=					self.conv(__lowerCamelCase			)
						return hidden_states



class 	lowerCamelCase__      (							nn.Module):




		'''simple docstring'''



		snake_case_     =42
		snake_case_     =jnp.floataa



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    List[Any]												=					nn.Conv(
						    self.out_channels		,kernel_size=(3, 3)		,strides=(2, 2)		,padding=((1, 1), (1, 1))		,dtype=self.dtype		,)



		def __call__(self		,__lowerCamelCase			)					->      Any:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[int]												=					self.conv(__lowerCamelCase			)
						return hidden_states



class 	lowerCamelCase__      (							nn.Module):




		'''simple docstring'''



		snake_case_     =42
		snake_case_     =None
		snake_case_     =0.0
		snake_case_     =None
		snake_case_     =jnp.floataa



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    List[str]												=					self.in_channels if self.out_channels is None else self.out_channels

						lowerCAmelCase__					:    Union[str, Any]												=					nn.GroupNorm(num_groups=32		,epsilon=1e-5			)
						lowerCAmelCase__					:    Union[str, Any]												=					nn.Conv(
						    __lowerCamelCase		,kernel_size=(3, 3)		,strides=(1, 1)		,padding=((1, 1), (1, 1))		,dtype=self.dtype		,)

						lowerCAmelCase__					:    int												=					nn.Dense(__lowerCamelCase		,dtype=self.dtype			)

						lowerCAmelCase__					:    List[Any]												=					nn.GroupNorm(num_groups=32		,epsilon=1e-5			)
						lowerCAmelCase__					:    Union[str, Any]												=					nn.Dropout(self.dropout_prob			)
						lowerCAmelCase__					:    Optional[int]												=					nn.Conv(
						    __lowerCamelCase		,kernel_size=(3, 3)		,strides=(1, 1)		,padding=((1, 1), (1, 1))		,dtype=self.dtype		,)

						lowerCAmelCase__					:    str												=					self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

						lowerCAmelCase__					:    Union[str, Any]												=					None
						if use_nin_shortcut:
										lowerCAmelCase__					:    Optional[Any]												=					nn.Conv(
										    __lowerCamelCase		,kernel_size=(1, 1)		,strides=(1, 1)		,padding='''VALID'''		,dtype=self.dtype		,)



		def __call__(self		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase=True			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Tuple												=					hidden_states
						lowerCAmelCase__					:    Dict												=					self.norma(__lowerCamelCase			)
						lowerCAmelCase__					:    Union[str, Any]												=					nn.swish(__lowerCamelCase			)
						lowerCAmelCase__					:    List[Any]												=					self.conva(__lowerCamelCase			)

						lowerCAmelCase__					:    List[Any]												=					self.time_emb_proj(nn.swish(__lowerCamelCase			)			)
						lowerCAmelCase__					:    Dict												=					jnp.expand_dims(jnp.expand_dims(__lowerCamelCase		,1			)		,1			)
						lowerCAmelCase__					:    Optional[int]												=					hidden_states + temb

						lowerCAmelCase__					:    Optional[int]												=					self.norma(__lowerCamelCase			)
						lowerCAmelCase__					:    Optional[int]												=					nn.swish(__lowerCamelCase			)
						lowerCAmelCase__					:    int												=					self.dropout(__lowerCamelCase		,__lowerCamelCase			)
						lowerCAmelCase__					:    List[Any]												=					self.conva(__lowerCamelCase			)

						if self.conv_shortcut is not None:
										lowerCAmelCase__					:    Optional[int]												=					self.conv_shortcut(__lowerCamelCase			)

						return hidden_states + residual

