



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



class        lowerCAmelCase__					(  nn.Module       ):
				A_   :     int
				A_   :     jnp.dtype								=     jnp.floataa


				def __UpperCamelCase						(							self      :  str       )		->     Any:
											A      						=    nn.Conv(
											    self.out_channels						, kernel_size=(3, 3)						, strides=(1, 1)						, padding=((1, 1), (1, 1))						, dtype=self.dtype						, )


				def __call__(							self      :  Tuple						, __UpperCamelCase      :  Dict       )		->     List[Any]:
											A						,   A						,   A						,   A      						=    hidden_states.shape
											A      						=    jax.image.resize(
											    __UpperCamelCase						, shape=(batch, height * 2, width * 2, channels)						, method='nearest'						, )
											A      						=    self.conv(__UpperCamelCase       )
											return hidden_states





class        lowerCAmelCase__					(  nn.Module       ):
				A_   :     int
				A_   :     jnp.dtype								=     jnp.floataa


				def __UpperCamelCase						(							self      :  int       )		->     Tuple:
											A      						=    nn.Conv(
											    self.out_channels						, kernel_size=(3, 3)						, strides=(2, 2)						, padding=((1, 1), (1, 1))						, dtype=self.dtype						, )


				def __call__(							self      :  Dict						, __UpperCamelCase      :  Tuple       )		->     int:
											# pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
											# hidden_states = jnp.pad(hidden_states, pad_width=pad)
											A      						=    self.conv(__UpperCamelCase       )
											return hidden_states





class        lowerCAmelCase__					(  nn.Module       ):
				A_   :     int
				A_   :     int								=     None
				A_   :     float								=     0.0
				A_   :     bool								=     None
				A_   :     jnp.dtype								=     jnp.floataa


				def __UpperCamelCase						(							self      :  int       )		->     Optional[Any]:
											A      						=    self.in_channels if self.out_channels is None else self.out_channels

											A      						=    nn.GroupNorm(num_groups=32						, epsilon=1e-5       )
											A      						=    nn.Conv(
											    __UpperCamelCase						, kernel_size=(3, 3)						, strides=(1, 1)						, padding=((1, 1), (1, 1))						, dtype=self.dtype						, )

											A      						=    nn.Dense(__UpperCamelCase						, dtype=self.dtype       )

											A      						=    nn.GroupNorm(num_groups=32						, epsilon=1e-5       )
											A      						=    nn.Dropout(self.dropout_prob       )
											A      						=    nn.Conv(
											    __UpperCamelCase						, kernel_size=(3, 3)						, strides=(1, 1)						, padding=((1, 1), (1, 1))						, dtype=self.dtype						, )

											A      						=    self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

											A      						=    None
											if use_nin_shortcut:
																		A      						=    nn.Conv(
																		    __UpperCamelCase						, kernel_size=(1, 1)						, strides=(1, 1)						, padding='VALID'						, dtype=self.dtype						, )


				def __call__(							self      :  str						, __UpperCamelCase      :  str						, __UpperCamelCase      :  int						, __UpperCamelCase      :  List[Any]=True       )		->     Optional[Any]:
											A      						=    hidden_states
											A      						=    self.norma(__UpperCamelCase       )
											A      						=    nn.swish(__UpperCamelCase       )
											A      						=    self.conva(__UpperCamelCase       )

											A      						=    self.time_emb_proj(nn.swish(__UpperCamelCase       )       )
											A      						=    jnp.expand_dims(jnp.expand_dims(__UpperCamelCase						, 1       )						, 1       )
											A      						=    hidden_states + temb

											A      						=    self.norma(__UpperCamelCase       )
											A      						=    nn.swish(__UpperCamelCase       )
											A      						=    self.dropout(__UpperCamelCase						, __UpperCamelCase       )
											A      						=    self.conva(__UpperCamelCase       )

											if self.conv_shortcut is not None:
																		A      						=    self.conv_shortcut(__UpperCamelCase       )

											return hidden_states + residual






import argparse

import torch

from transformers import RemBertConfig, RemBertModel, load_tf_weights_in_rembert
from transformers.utils import logging


logging.set_verbosity_info()


def       UpperCamelCase__(			UpperCamelCase__     :			Any					,	UpperCamelCase__     :			int					,	UpperCamelCase__     :			List[Any]    )->Optional[int]:
       # Initialise PyTorch model
       A__		   =		RemBertConfig.from_json_file(UpperCamelCase__    )
       print('''Building PyTorch model from configuration: {}'''.format(str(UpperCamelCase__    )    )    )
       A__		   =		RemBertModel(UpperCamelCase__    )

       # Load weights from tf checkpoint
       load_tf_weights_in_rembert(UpperCamelCase__					,	UpperCamelCase__					,	UpperCamelCase__    )

       # Save pytorch-model
       print('''Save PyTorch model to {}'''.format(UpperCamelCase__    )    )
       torch.save(model.state_dict()					,	UpperCamelCase__    )


if __name__ == "__main__":
       a__: List[Any]							   =						argparse.ArgumentParser()
       # Required parameters
       parser.add_argument(
           '--tf_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
       )
       parser.add_argument(
           '--rembert_config_file',
           default=None,
           type=str,
           required=True,
           help=(
               'The config json file corresponding to the pre-trained RemBERT model. \n'
               'This specifies the model architecture.'
           ),
       )
       parser.add_argument(
           '--pytorch_dump_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
       )
       a__: Union[str, Any]							   =						parser.parse_args()
       convert_rembert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.rembert_config_file, args.pytorch_dump_path)





