
'''simple docstring'''





import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import ConditionalDetrImageProcessor







class        lowerCAmelCase__      (   unittest.TestCase	):

						def __init__(			self       ,							a       ,							a=7       ,							a=3       ,							a=30       ,							a=4_00       ,							a=True       ,							a=None       ,							a=True       ,							a=[0.5, 0.5, 0.5]       ,							a=[0.5, 0.5, 0.5]       ,							a=True       ,							a=1 / 2_55       ,							a=True       ,							)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	size if size is not None else {"shortest_edge": 18, "longest_edge": 13_33}
								_UpperCamelCase						    =	parent
								_UpperCamelCase						    =	batch_size
								_UpperCamelCase						    =	num_channels
								_UpperCamelCase						    =	min_resolution
								_UpperCamelCase						    =	max_resolution
								_UpperCamelCase						    =	do_resize
								_UpperCamelCase						    =	size
								_UpperCamelCase						    =	do_normalize
								_UpperCamelCase						    =	image_mean
								_UpperCamelCase						    =	image_std
								_UpperCamelCase						    =	do_rescale
								_UpperCamelCase						    =	rescale_factor
								_UpperCamelCase						    =	do_pad

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


								'''simple docstring'''

								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_rescale": self.do_rescale,
								    "rescale_factor": self.rescale_factor,
								    "do_pad": self.do_pad,
								}







						def  A_				(			self       ,							a       ,							a=False				)					->      Optional[int]:


								'''simple docstring'''

								if not batched:
										_UpperCamelCase						    =	image_inputs[0]
										if isinstance(a       ,							Image.Image				):
												_UpperCamelCase						    =	image.size
										else:
												_UpperCamelCase						    =	image.shape[1], image.shape[2]
										if w < h:
												_UpperCamelCase						    =	int(self.size["""shortest_edge"""] * h / w				)
												_UpperCamelCase						    =	self.size["shortest_edge"]
										elif w > h:
												_UpperCamelCase						    =	self.size["shortest_edge"]
												_UpperCamelCase						    =	int(self.size["""shortest_edge"""] * w / h				)
										else:
												_UpperCamelCase						    =	self.size["shortest_edge"]
												_UpperCamelCase						    =	self.size["shortest_edge"]

								else:
										_UpperCamelCase						    =	[]
										for image in image_inputs:
												_UpperCamelCase						    =	self.get_expected_values([image]				)
												expected_values.append((expected_height, expected_width)				)
										_UpperCamelCase						    =	max(a       ,							key=lambda a				: item[0]				)[0]
										_UpperCamelCase						    =	max(a       ,							key=lambda a				: item[1]				)[1]

								return expected_height, expected_width







@require_torch
@require_vision
class        lowerCAmelCase__      (   _UpperCamelCase		,	unittest.TestCase	):
						UpperCamelCase_							: Optional[int]	=		ConditionalDetrImageProcessor if is_vision_available() else None

						def  A_				(			self				)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	ConditionalDetrImageProcessingTester(self				)

						@property
						def  A_				(			self				)					->      Any:


								'''simple docstring'''

								return self.image_processor_tester.prepare_image_processor_dict()

						def  A_				(			self				)					->      List[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(a       ,							"""image_mean"""				)				)
								self.assertTrue(hasattr(a       ,							"""image_std"""				)				)
								self.assertTrue(hasattr(a       ,							"""do_normalize"""				)				)
								self.assertTrue(hasattr(a       ,							"""do_resize"""				)				)
								self.assertTrue(hasattr(a       ,							"""size"""				)				)

						def  A_				(			self				)					->      Optional[int]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.image_processing_class.from_dict(self.image_processor_dict				)
								self.assertEqual(image_processor.size       ,							{"""shortest_edge""": 18, """longest_edge""": 13_33}				)
								self.assertEqual(image_processor.do_pad       ,							a				)

								_UpperCamelCase						    =	self.image_processing_class.from_dict(
								    self.image_processor_dict       ,							size=42       ,							max_size=84       ,							pad_and_return_pixel_mask=a				)
								self.assertEqual(image_processor.size       ,							{"""shortest_edge""": 42, """longest_edge""": 84}				)
								self.assertEqual(image_processor.do_pad       ,							a				)

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


								'''simple docstring'''

								pass

						def  A_				(			self				)					->      Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								_UpperCamelCase						    =	prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=a				)
								for image in image_inputs:
										self.assertIsInstance(a       ,							Image.Image				)

								# Test not batched input
								_UpperCamelCase						    =	image_processing(image_inputs[0]       ,							return_tensors="""pt"""				).pixel_values

								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a				)

								self.assertEqual(
								    encoded_images.shape       ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,							)

								# Test batched
								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a       ,							batched=a				)

								_UpperCamelCase						    =	image_processing(a       ,							return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape       ,							(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )       ,							)

						def  A_				(			self				)					->      Optional[Any]:


								'''simple docstring'''

								_UpperCamelCase						    =	self.image_processing_class(**self.image_processor_dict				)
								# create random numpy tensors
								_UpperCamelCase						    =	prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=a       ,							numpify=a				)
								for image in image_inputs:
										self.assertIsInstance(a       ,							np.ndarray				)

								# Test not batched input
								_UpperCamelCase						    =	image_processing(image_inputs[0]       ,							return_tensors="""pt"""				).pixel_values

								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a				)

								self.assertEqual(
								    encoded_images.shape       ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,							)

								# Test batched
								_UpperCamelCase						    =	image_processing(a       ,							return_tensors="""pt"""				).pixel_values

								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a       ,							batched=a				)

								self.assertEqual(
								    encoded_images.shape       ,							(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )       ,							)

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


								'''simple docstring'''

								_UpperCamelCase						    =	self.image_processing_class(**self.image_processor_dict				)
								# create random PyTorch tensors
								_UpperCamelCase						    =	prepare_image_inputs(self.image_processor_tester       ,							equal_resolution=a       ,							torchify=a				)
								for image in image_inputs:
										self.assertIsInstance(a       ,							torch.Tensor				)

								# Test not batched input
								_UpperCamelCase						    =	image_processing(image_inputs[0]       ,							return_tensors="""pt"""				).pixel_values

								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a				)

								self.assertEqual(
								    encoded_images.shape       ,							(1, self.image_processor_tester.num_channels, expected_height, expected_width)       ,							)

								# Test batched
								_UpperCamelCase						    =	image_processing(a       ,							return_tensors="""pt"""				).pixel_values

								_UpperCamelCase						    =	self.image_processor_tester.get_expected_values(a       ,							batched=a				)

								self.assertEqual(
								    encoded_images.shape       ,							(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        expected_height,
								        expected_width,
								    )       ,							)

						@slow
						def  A_				(			self				)					->      str:


								'''simple docstring'''

								_UpperCamelCase						    =	Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""				)
								with open("""./tests/fixtures/tests_samples/COCO/coco_annotations.txt"""       ,							"""r"""				) as f:
										_UpperCamelCase						    =	json.loads(f.read()				)

								_UpperCamelCase						    =	{"image_id": 3_97_69, "annotations": target}

								# encode them
								_UpperCamelCase						    =	ConditionalDetrImageProcessor.from_pretrained("""microsoft/conditional-detr-resnet-50"""				)
								_UpperCamelCase						    =	image_processing(images=a       ,							annotations=a       ,							return_tensors="""pt"""				)

								# verify pixel values
								_UpperCamelCase						    =	torch.Size([1, 3, 8_00, 10_66]				)
								self.assertEqual(encoding["""pixel_values"""].shape       ,							a				)

								_UpperCamelCase						    =	torch.tensor([0.2796, 0.3138, 0.3481]				)
								self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]       ,							a       ,							atol=1e-4				)				)

								# verify area
								_UpperCamelCase						    =	torch.tensor([58_87.96_00, 1_12_50.20_61, 48_93_53.84_38, 83_71_22.75_00, 14_79_67.51_56, 16_57_32.34_38]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]       ,							a				)				)
								# verify boxes
								_UpperCamelCase						    =	torch.Size([6, 4]				)
								self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape       ,							a				)
								_UpperCamelCase						    =	torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]       ,							a       ,							atol=1e-3				)				)
								# verify image_id
								_UpperCamelCase						    =	torch.tensor([3_97_69]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]       ,							a				)				)
								# verify is_crowd
								_UpperCamelCase						    =	torch.tensor([0, 0, 0, 0, 0, 0]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]       ,							a				)				)
								# verify class_labels
								_UpperCamelCase						    =	torch.tensor([75, 75, 63, 65, 17, 17]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]       ,							a				)				)
								# verify orig_size
								_UpperCamelCase						    =	torch.tensor([4_80, 6_40]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]       ,							a				)				)
								# verify size
								_UpperCamelCase						    =	torch.tensor([8_00, 10_66]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]       ,							a				)				)







						@slow
						def  A_				(			self				)					->      int:


								'''simple docstring'''

								_UpperCamelCase						    =	Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""				)
								with open("""./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt"""       ,							"""r"""				) as f:
										_UpperCamelCase						    =	json.loads(f.read()				)

								_UpperCamelCase						    =	{"file_name": "000000039769.png", "image_id": 3_97_69, "segments_info": target}

								_UpperCamelCase						    =	pathlib.Path("""./tests/fixtures/tests_samples/COCO/coco_panoptic"""				)

								# encode them
								_UpperCamelCase						    =	ConditionalDetrImageProcessor(format="""coco_panoptic"""				)
								_UpperCamelCase						    =	image_processing(images=a       ,							annotations=a       ,							masks_path=a       ,							return_tensors="""pt"""				)

								# verify pixel values
								_UpperCamelCase						    =	torch.Size([1, 3, 8_00, 10_66]				)
								self.assertEqual(encoding["""pixel_values"""].shape       ,							a				)

								_UpperCamelCase						    =	torch.tensor([0.2796, 0.3138, 0.3481]				)
								self.assertTrue(torch.allclose(encoding["""pixel_values"""][0, 0, 0, :3]       ,							a       ,							atol=1e-4				)				)

								# verify area
								_UpperCamelCase						    =	torch.tensor([14_79_79.68_75, 16_55_27.04_69, 48_46_38.59_38, 1_12_92.93_75, 58_79.65_62, 76_34.11_47]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""area"""]       ,							a				)				)
								# verify boxes
								_UpperCamelCase						    =	torch.Size([6, 4]				)
								self.assertEqual(encoding["""labels"""][0]["""boxes"""].shape       ,							a				)
								_UpperCamelCase						    =	torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""boxes"""][0]       ,							a       ,							atol=1e-3				)				)
								# verify image_id
								_UpperCamelCase						    =	torch.tensor([3_97_69]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""image_id"""]       ,							a				)				)
								# verify is_crowd
								_UpperCamelCase						    =	torch.tensor([0, 0, 0, 0, 0, 0]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""iscrowd"""]       ,							a				)				)
								# verify class_labels
								_UpperCamelCase						    =	torch.tensor([17, 17, 63, 75, 75, 93]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""class_labels"""]       ,							a				)				)
								# verify masks
								_UpperCamelCase						    =	82_28_73
								self.assertEqual(encoding["""labels"""][0]["""masks"""].sum().item()       ,							a				)
								# verify orig_size
								_UpperCamelCase						    =	torch.tensor([4_80, 6_40]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""orig_size"""]       ,							a				)				)
								# verify size
								_UpperCamelCase						    =	torch.tensor([8_00, 10_66]				)
								self.assertTrue(torch.allclose(encoding["""labels"""][0]["""size"""]       ,							a				)				)





import argparse
import os
import re

import tensorflow as tf
import torch

from transformers import BertConfig, BertModel
from transformers.utils import logging


logging.set_verbosity_info()
lowerCamelCase__	=							logging.get_logger(__name__)


def 							__A(lowerCAmelCase						,  lowerCAmelCase						,  lowerCAmelCase )		->				Any:

		"""simple docstring"""






		_UpperCamelCase						    =	os.path.abspath(lowerCAmelCase )
		logger.info(F'Converting TensorFlow checkpoint from {tf_path}' )
		# Load weights from TF model
		_UpperCamelCase						    =	tf.train.list_variables(lowerCAmelCase )
		_UpperCamelCase						    =	[]
		_UpperCamelCase						    =	[]
		_UpperCamelCase						    =	[]
		for full_name, shape in init_vars:
				# logger.info(f"Loading TF weight {name} with shape {shape}")
				_UpperCamelCase						    =	full_name.split("""/""" )
				if full_name == "_CHECKPOINTABLE_OBJECT_GRAPH" or name[0] in ["global_step", "save_counter"]:
						logger.info(F'Skipping non-model layer {full_name}' )
						continue
				if "optimizer" in full_name:
						logger.info(F'Skipping optimization layer {full_name}' )
						continue
				if name[0] == "model":
						# ignore initial 'model'
						_UpperCamelCase						    =	name[1:]
				# figure out how many levels deep the name is
				_UpperCamelCase						    =	0
				for _name in name:
						if _name.startswith("""layer_with_weights""" ):
								depth += 1
						else:
								break
				layer_depth.append(lowerCAmelCase )
				# read data
				_UpperCamelCase						    =	tf.train.load_variable(lowerCAmelCase						,  lowerCAmelCase )
				names.append("""/""".join(lowerCAmelCase ) )
				arrays.append(lowerCAmelCase )
		logger.info(F'Read a total of {len(lowerCAmelCase ):,} layers' )

		# Sanity check
		if len(set(lowerCAmelCase ) ) != 1:
				raise ValueError(F'Found layer names with different depths (layer depth {list(set(lowerCAmelCase ) )})' )
		_UpperCamelCase						    =	list(set(lowerCAmelCase ) )[0]
		if layer_depth != 1:
				raise ValueError(
				    """The model contains more than just the embedding/encoder layers. This script does not handle MLM/NSP"""
				    """ heads.""" )

		# convert layers
		logger.info("""Converting weights...""" )
		for full_name, array in zip(lowerCAmelCase						,  lowerCAmelCase ):
				_UpperCamelCase						    =	full_name.split("""/""" )
				_UpperCamelCase						    =	model
				_UpperCamelCase						    =	[]
				for i, m_name in enumerate(lowerCAmelCase ):
						if m_name == ".ATTRIBUTES":
								# variable names end with .ATTRIBUTES/VARIABLE_VALUE
								break
						if m_name.startswith("""layer_with_weights""" ):
								_UpperCamelCase						    =	int(m_name.split("""-""" )[-1] )
								if layer_num <= 2:
										# embedding layers
										# layer_num 0: word_embeddings
										# layer_num 1: position_embeddings
										# layer_num 2: token_type_embeddings
										continue
								elif layer_num == 3:
										# embedding LayerNorm
										trace.extend(["""embeddings""", """LayerNorm"""] )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """embeddings""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """LayerNorm""" )
								elif layer_num > 3 and layer_num < config.num_hidden_layers + 4:
										# encoder layers
										trace.extend(["""encoder""", """layer""", str(layer_num - 4 )] )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """encoder""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """layer""" )
										_UpperCamelCase						    =	pointer[layer_num - 4]
								elif layer_num == config.num_hidden_layers + 4:
										# pooler layer
										trace.extend(["""pooler""", """dense"""] )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """pooler""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """dense""" )
						elif m_name == "embeddings":
								trace.append("""embeddings""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """embeddings""" )
								if layer_num == 0:
										trace.append("""word_embeddings""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """word_embeddings""" )
								elif layer_num == 1:
										trace.append("""position_embeddings""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """position_embeddings""" )
								elif layer_num == 2:
										trace.append("""token_type_embeddings""" )
										_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """token_type_embeddings""" )
								else:
										raise ValueError(F'Unknown embedding layer with name {full_name}' )
								trace.append("""weight""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """weight""" )
						elif m_name == "_attention_layer":
								# self-attention layer
								trace.extend(["""attention""", """self"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """attention""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """self""" )
						elif m_name == "_attention_layer_norm":
								# output attention norm
								trace.extend(["""attention""", """output""", """LayerNorm"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """attention""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """output""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """LayerNorm""" )
						elif m_name == "_attention_output_dense":
								# output attention dense
								trace.extend(["""attention""", """output""", """dense"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """attention""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """output""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """dense""" )
						elif m_name == "_output_dense":
								# output dense
								trace.extend(["""output""", """dense"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """output""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """dense""" )
						elif m_name == "_output_layer_norm":
								# output dense
								trace.extend(["""output""", """LayerNorm"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """output""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """LayerNorm""" )
						elif m_name == "_key_dense":
								# attention key
								trace.append("""key""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """key""" )
						elif m_name == "_query_dense":
								# attention query
								trace.append("""query""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """query""" )
						elif m_name == "_value_dense":
								# attention value
								trace.append("""value""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """value""" )
						elif m_name == "_intermediate_dense":
								# attention intermediate dense
								trace.extend(["""intermediate""", """dense"""] )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """intermediate""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """dense""" )
						elif m_name == "_output_layer_norm":
								# output layer norm
								trace.append("""output""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """output""" )
						# weights & biases
						elif m_name in ["bias", "beta"]:
								trace.append("""bias""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """bias""" )
						elif m_name in ["kernel", "gamma"]:
								trace.append("""weight""" )
								_UpperCamelCase						    =	getattr(lowerCAmelCase						,  """weight""" )
						else:
								logger.warning(F'Ignored {m_name}' )
        # for certain layers reshape is necessary
				_UpperCamelCase						    =	""".""".join(lowerCAmelCase )
				if re.match(R"""(\S+)\.attention\.self\.(key|value|query)\.(bias|weight)"""						,  lowerCAmelCase ) or re.match(
				    R"""(\S+)\.attention\.output\.dense\.weight"""						,  lowerCAmelCase ):
						_UpperCamelCase						    =	array.reshape(pointer.data.shape )
				if "kernel" in full_name:
						_UpperCamelCase						    =	array.transpose()
				if pointer.shape == array.shape:
						_UpperCamelCase						    =	torch.from_numpy(lowerCAmelCase )
				else:
						raise ValueError(
						    F'Shape mismatch in layer {full_name}: Model expects shape {pointer.shape} but layer contains shape:'
						    F' {array.shape}' )
				logger.info(F'Successfully set variable {full_name} to PyTorch layer {trace}' )
		return model


def 							__A(lowerCAmelCase						,  lowerCAmelCase						,  lowerCAmelCase )		->				Tuple:

		"""simple docstring"""






		logger.info(F'Loading model based on config from {config_path}...' )
		_UpperCamelCase						    =	BertConfig.from_json_file(lowerCAmelCase )
		_UpperCamelCase						    =	BertModel(lowerCAmelCase )

		# Load weights from checkpoint
		logger.info(F'Loading weights from checkpoint {tf_checkpoint_path}...' )
		load_tfa_weights_in_bert(lowerCAmelCase						,  lowerCAmelCase						,  lowerCAmelCase )

		# Save pytorch-model
		logger.info(F'Saving PyTorch model to {pytorch_dump_path}...' )
		torch.save(model.state_dict()						,  lowerCAmelCase )


if __name__ == "__main__":
		lowerCamelCase__	=							argparse.ArgumentParser()
		parser.add_argument(
		    "--tf_checkpoint_path", type=str, required=True, help="Path to the TensorFlow 2.x checkpoint path."
		)
		parser.add_argument(
		    "--bert_config_file",
		    type=str,
		    required=True,
		    help="The config json file corresponding to the BERT model. This specifies the model architecture.",
		)
		parser.add_argument(
		    "--pytorch_dump_path",
		    type=str,
		    required=True,
		    help="Path to the output PyTorch model (must include filename).",
		)
		lowerCamelCase__	=							parser.parse_args()
		convert_tfa_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)



