

'''simple docstring'''
import flax.linen as nn
import jax.numpy as jnp

from .attention_flax import FlaxTransformeraDModel
from .resnet_flax import FlaxDownsampleaD, FlaxResnetBlockaD, FlaxUpsampleaD


class        a__  (							nn.Module  ):
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					float     	=							0.0
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					bool     	=							True
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					jnp.dtype     	=							jnp.floataa


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[int]      					=       []
      _lowercase      :				Optional[int]      					=       []

      for i in range(self.num_layers  ):
         _lowercase      :				List[Any]      					=       self.in_channels if i == 0 else self.out_channels

         _lowercase      :				int      					=       FlaxResnetBlockaD(
             in_channels=_UpperCamelCase      ,    out_channels=self.out_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
         resnets.append(_UpperCamelCase  )

         _lowercase      :				List[str]      					=       FlaxTransformeraDModel(
             in_channels=self.out_channels      ,    n_heads=self.num_attention_heads      ,    d_head=self.out_channels // self.num_attention_heads      ,    depth=1      ,    use_linear_projection=self.use_linear_projection      ,    only_cross_attention=self.only_cross_attention      ,    use_memory_efficient_attention=self.use_memory_efficient_attention      ,    dtype=self.dtype      ,    )
         attentions.append(_UpperCamelCase  )

      _lowercase      :				Union[str, Any]      					=       resnets
      _lowercase      :				Any      					=       attentions

      if self.add_downsample:
         _lowercase      :				str      					=       FlaxDownsampleaD(self.out_channels      ,    dtype=self.dtype  )






   def __call__(			self      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase=True  ):





      """simple docstring"""





      _lowercase      :				Any      					=       ()

      for resnet, attn in zip(self.resnets      ,    self.attentions  ):
         _lowercase      :				str      					=       resnet(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )
         _lowercase      :				Dict      					=       attn(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )
         output_states += (hidden_states,)

      if self.add_downsample:
         _lowercase      :				Union[str, Any]      					=       self.downsamplers_a(_UpperCamelCase  )
         output_states += (hidden_states,)

      return hidden_states, output_states




class        a__  (							nn.Module  ):
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					float     	=							0.0
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					bool     	=							True
   _SCREAMING_SNAKE_CASE   :					jnp.dtype     	=							jnp.floataa


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Any      					=       []

      for i in range(self.num_layers  ):
         _lowercase      :				Union[str, Any]      					=       self.in_channels if i == 0 else self.out_channels

         _lowercase      :				Tuple      					=       FlaxResnetBlockaD(
             in_channels=_UpperCamelCase      ,    out_channels=self.out_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
         resnets.append(_UpperCamelCase  )
      _lowercase      :				Optional[Any]      					=       resnets

      if self.add_downsample:
         _lowercase      :				Dict      					=       FlaxDownsampleaD(self.out_channels      ,    dtype=self.dtype  )






   def __call__(			self      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase=True  ):





      """simple docstring"""





      _lowercase      :				Dict      					=       ()

      for resnet in self.resnets:
         _lowercase      :				Any      					=       resnet(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )
         output_states += (hidden_states,)

      if self.add_downsample:
         _lowercase      :				Dict      					=       self.downsamplers_a(_UpperCamelCase  )
         output_states += (hidden_states,)

      return hidden_states, output_states




class        a__  (							nn.Module  ):
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					float     	=							0.0
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					bool     	=							True
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					jnp.dtype     	=							jnp.floataa


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Dict      					=       []
      _lowercase      :				Optional[int]      					=       []

      for i in range(self.num_layers  ):
         _lowercase      :				List[str]      					=       self.in_channels if (i == self.num_layers - 1) else self.out_channels
         _lowercase      :				Dict      					=       self.prev_output_channel if i == 0 else self.out_channels

         _lowercase      :				int      					=       FlaxResnetBlockaD(
             in_channels=resnet_in_channels + res_skip_channels      ,    out_channels=self.out_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
         resnets.append(_UpperCamelCase  )

         _lowercase      :				int      					=       FlaxTransformeraDModel(
             in_channels=self.out_channels      ,    n_heads=self.num_attention_heads      ,    d_head=self.out_channels // self.num_attention_heads      ,    depth=1      ,    use_linear_projection=self.use_linear_projection      ,    only_cross_attention=self.only_cross_attention      ,    use_memory_efficient_attention=self.use_memory_efficient_attention      ,    dtype=self.dtype      ,    )
         attentions.append(_UpperCamelCase  )

      _lowercase      :				int      					=       resnets
      _lowercase      :				Optional[int]      					=       attentions

      if self.add_upsample:
         _lowercase      :				Union[str, Any]      					=       FlaxUpsampleaD(self.out_channels      ,    dtype=self.dtype  )






   def __call__(			self      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase=True  ):





      """simple docstring"""





      for resnet, attn in zip(self.resnets      ,    self.attentions  ):
         # pop res hidden states
         _lowercase      :				Any      					=       res_hidden_states_tuple[-1]
         _lowercase      :				Optional[Any]      					=       res_hidden_states_tuple[:-1]
         _lowercase      :				Optional[Any]      					=       jnp.concatenate((hidden_states, res_hidden_states)      ,    axis=-1  )

         _lowercase      :				List[str]      					=       resnet(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )
         _lowercase      :				int      					=       attn(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )

      if self.add_upsample:
         _lowercase      :				Optional[Any]      					=       self.upsamplers_a(_UpperCamelCase  )

      return hidden_states




class        a__  (							nn.Module  ):
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					float     	=							0.0
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					bool     	=							True
   _SCREAMING_SNAKE_CASE   :					jnp.dtype     	=							jnp.floataa


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       []

      for i in range(self.num_layers  ):
         _lowercase      :				Optional[Any]      					=       self.in_channels if (i == self.num_layers - 1) else self.out_channels
         _lowercase      :				str      					=       self.prev_output_channel if i == 0 else self.out_channels

         _lowercase      :				Tuple      					=       FlaxResnetBlockaD(
             in_channels=resnet_in_channels + res_skip_channels      ,    out_channels=self.out_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
         resnets.append(_UpperCamelCase  )

      _lowercase      :				List[str]      					=       resnets

      if self.add_upsample:
         _lowercase      :				List[Any]      					=       FlaxUpsampleaD(self.out_channels      ,    dtype=self.dtype  )






   def __call__(			self      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase=True  ):





      """simple docstring"""





      for resnet in self.resnets:
         # pop res hidden states
         _lowercase      :				Optional[int]      					=       res_hidden_states_tuple[-1]
         _lowercase      :				Tuple      					=       res_hidden_states_tuple[:-1]
         _lowercase      :				Any      					=       jnp.concatenate((hidden_states, res_hidden_states)      ,    axis=-1  )

         _lowercase      :				Optional[Any]      					=       resnet(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )

      if self.add_upsample:
         _lowercase      :				Any      					=       self.upsamplers_a(_UpperCamelCase  )

      return hidden_states




class        a__  (							nn.Module  ):
   _SCREAMING_SNAKE_CASE   :					int
   _SCREAMING_SNAKE_CASE   :					float     	=							0.0
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					int     	=							1
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					bool     	=							False
   _SCREAMING_SNAKE_CASE   :					jnp.dtype     	=							jnp.floataa


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Dict      					=       [
          FlaxResnetBlockaD(
              in_channels=self.in_channels      ,    out_channels=self.in_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
      ]

      _lowercase      :				Optional[int]      					=       []

      for _ in range(self.num_layers  ):
         _lowercase      :				Any      					=       FlaxTransformeraDModel(
             in_channels=self.in_channels      ,    n_heads=self.num_attention_heads      ,    d_head=self.in_channels // self.num_attention_heads      ,    depth=1      ,    use_linear_projection=self.use_linear_projection      ,    use_memory_efficient_attention=self.use_memory_efficient_attention      ,    dtype=self.dtype      ,    )
         attentions.append(_UpperCamelCase  )

         _lowercase      :				int      					=       FlaxResnetBlockaD(
             in_channels=self.in_channels      ,    out_channels=self.in_channels      ,    dropout_prob=self.dropout      ,    dtype=self.dtype      ,    )
         resnets.append(_UpperCamelCase  )

      _lowercase      :				Tuple      					=       resnets
      _lowercase      :				Optional[int]      					=       attentions






   def __call__(			self      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase      ,    _UpperCamelCase=True  ):





      """simple docstring"""





      _lowercase      :				List[Any]      					=       self.resnets[0](_UpperCamelCase      ,    _UpperCamelCase  )
      for attn, resnet in zip(self.attentions      ,    self.resnets[1:]  ):
         _lowercase      :				Tuple      					=       attn(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )
         _lowercase      :				Optional[Any]      					=       resnet(_UpperCamelCase      ,    _UpperCamelCase      ,    deterministic=_UpperCamelCase  )

      return hidden_states









'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case         =  logging.get_logger(__name__)

_snake_case         =  {
    'weiweishi/roc-bert-base-zh': 'https://huggingface.co/weiweishi/roc-bert-base-zh/resolve/main/config.json',
}


class        a__  (							lowerCamelCase_  ):
   _SCREAMING_SNAKE_CASE   :					Any     	=							'roc_bert'


   def __init__(			self      ,    _UpperCamelCase=30522      ,    _UpperCamelCase=768      ,    _UpperCamelCase=12      ,    _UpperCamelCase=12      ,    _UpperCamelCase=3072      ,    _UpperCamelCase="gelu"      ,    _UpperCamelCase=0.1      ,    _UpperCamelCase=0.1      ,    _UpperCamelCase=512      ,    _UpperCamelCase=2      ,    _UpperCamelCase=0.0_2      ,    _UpperCamelCase=1E-1_2      ,    _UpperCamelCase=True      ,    _UpperCamelCase=0      ,    _UpperCamelCase="absolute"      ,    _UpperCamelCase=None      ,    _UpperCamelCase=True      ,    _UpperCamelCase=True      ,    _UpperCamelCase=768      ,    _UpperCamelCase=910      ,    _UpperCamelCase=512      ,    _UpperCamelCase=24858      ,    _UpperCamelCase=True      ,    **_UpperCamelCase      ,    ):





      """simple docstring"""





      _lowercase      :				str      					=       vocab_size
      _lowercase      :				List[str]      					=       max_position_embeddings
      _lowercase      :				List[Any]      					=       hidden_size
      _lowercase      :				Dict      					=       num_hidden_layers
      _lowercase      :				str      					=       num_attention_heads
      _lowercase      :				int      					=       intermediate_size
      _lowercase      :				Optional[Any]      					=       hidden_act
      _lowercase      :				Union[str, Any]      					=       hidden_dropout_prob
      _lowercase      :				Dict      					=       attention_probs_dropout_prob
      _lowercase      :				Dict      					=       initializer_range
      _lowercase      :				List[Any]      					=       type_vocab_size
      _lowercase      :				Tuple      					=       layer_norm_eps
      _lowercase      :				Optional[int]      					=       use_cache
      _lowercase      :				Tuple      					=       enable_pronunciation
      _lowercase      :				Optional[int]      					=       enable_shape
      _lowercase      :				int      					=       pronunciation_embed_dim
      _lowercase      :				List[str]      					=       pronunciation_vocab_size
      _lowercase      :				int      					=       shape_embed_dim
      _lowercase      :				str      					=       shape_vocab_size
      _lowercase      :				str      					=       concat_input
      _lowercase      :				Dict      					=       position_embedding_type
      _lowercase      :				Optional[Any]      					=       classifier_dropout
      super().__init__(pad_token_id=_UpperCamelCase      ,    **_UpperCamelCase  )






