






from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow


if is_tf_available():
		import numpy as np
		import tensorflow as tf

		from transformers import TFXLMRobertaModel



@require_tf
@require_sentencepiece
@require_tokenizers
class   lowerCamelCase				(unittest.TestCase      ):







		'''simple docstring'''



		@slow
		def  __UpperCAmelCase      (							self       )     ->							List[Any]:
							UpperCAmelCase_   :				int						=						TFXLMRobertaModel.from_pretrained('jplu/tf-xlm-roberta-base'       )

							UpperCAmelCase_   :				str						=						{
							    'input_ids': tf.convert_to_tensor([[0, 2_6_4_6, 1_0_2_6_9, 8_3, 9_9_9_4_2, 2]]    ,		dtype=tf.intaa       ),  # "My dog is cute"
							    'attention_mask': tf.convert_to_tensor([[1, 1, 1, 1, 1, 1]]    ,		dtype=tf.intaa       ),
							}

							UpperCAmelCase_   :				Optional[Any]						=						model(_UpperCamelCase       )['last_hidden_state']
							UpperCAmelCase_   :				int						=						tf.TensorShape((1, 6, 7_6_8)       )
							self.assertEqual(output.shape    ,		_UpperCamelCase       )
							# compare the actual values for a slice.
							UpperCAmelCase_   :				Tuple						=						tf.convert_to_tensor(
							    [
							        [
							            [0.0_68_17_62, 0.10_89_44_51, 0.06_77_25_04],
							            [-0.06_42_36_68, 0.02_36_66_15, 0.04_32_93_44],
							            [-0.06_05_72_95, 0.09_97_41_35, -0.00_07_05_84],
							        ]
							    ]    ,		dtype=tf.floataa    ,		)

							self.assertTrue(np.allclose(output[:, :3, :3].numpy()    ,		expected_slice.numpy()    ,		atol=1E-4       )       )














import argparse

import torch

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


logging.set_verbosity_info()




def 					lowercase__				(					__snake_case   :							Optional[Any]					,	__snake_case   :							Any					,	__snake_case   :							int  ):


					'''simple docstring'''


					UpperCAmelCase_   :				Union[str, Any]						=						RemBertConfig.from_json_file(__snake_case  )
					print('Building PyTorch model from configuration: {}'.format(str(__snake_case  )  )  )
					UpperCAmelCase_   :				Dict						=						RemBertModel(__snake_case  )

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

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


if __name__ == "__main__":
		__UpperCAmelCase     							=						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.'
		)
		__UpperCAmelCase     							=						parser.parse_args()
		convert_rembert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.rembert_config_file, args.pytorch_dump_path)






