



"""simple docstring"""
import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput
@dataclass
class 							lowerCamelCase    (     _lowerCAmelCase							):






					'''simple docstring'''





					_A						:     Union[List[PIL.Image.Image], np.ndarray]

class 							lowerCamelCase    (     unittest.TestCase							):






					'''simple docstring'''





					def   lowerCAmelCase_							(			self:				Any		)  ->      Optional[Any]:
											snake_case_					:int		=     CustomOutput(images=np.random.rand(1		,	3		,	4		,	4		)		)

											# check every way of getting the attribute
											assert isinstance(outputs.images		,	np.ndarray		)
											assert outputs.images.shape == (1, 3, 4, 4)
											assert isinstance(outputs["""images"""]		,	np.ndarray		)
											assert outputs["images"].shape == (1, 3, 4, 4)
											assert isinstance(outputs[0]		,	np.ndarray		)
											assert outputs[0].shape == (1, 3, 4, 4)

											# test with a non-tensor attribute
											snake_case_					:Tuple		=     CustomOutput(images=[PIL.Image.new("""RGB"""		,	(4, 4)		)]		)

											# check every way of getting the attribute
											assert isinstance(outputs.images		,	snake_case		)
											assert isinstance(outputs.images[0]		,	PIL.Image.Image		)
											assert isinstance(outputs["""images"""]		,	snake_case		)
											assert isinstance(outputs["""images"""][0]		,	PIL.Image.Image		)
											assert isinstance(outputs[0]		,	snake_case		)
											assert isinstance(outputs[0][0]		,	PIL.Image.Image		)






					def   lowerCAmelCase_							(			self:				str		)  ->      Union[str, Any]:
											# test output reinitialization with a `dict` for compatibility with `accelerate`
											snake_case_					:Tuple		=     CustomOutput({"""images""": np.random.rand(1		,	3		,	4		,	4		)}		)

											# check every way of getting the attribute
											assert isinstance(outputs.images		,	np.ndarray		)
											assert outputs.images.shape == (1, 3, 4, 4)
											assert isinstance(outputs["""images"""]		,	np.ndarray		)
											assert outputs["images"].shape == (1, 3, 4, 4)
											assert isinstance(outputs[0]		,	np.ndarray		)
											assert outputs[0].shape == (1, 3, 4, 4)

											# test with a non-tensor attribute
											snake_case_					:str		=     CustomOutput({"""images""": [PIL.Image.new("""RGB"""		,	(4, 4)		)]}		)

											# check every way of getting the attribute
											assert isinstance(outputs.images		,	snake_case		)
											assert isinstance(outputs.images[0]		,	PIL.Image.Image		)
											assert isinstance(outputs["""images"""]		,	snake_case		)
											assert isinstance(outputs["""images"""][0]		,	PIL.Image.Image		)
											assert isinstance(outputs[0]		,	snake_case		)
											assert isinstance(outputs[0][0]		,	PIL.Image.Image		)



"""simple docstring"""
import argparse

from transformers import TaConfig, TaForConditionalGeneration, load_tf_weights_in_ta
from transformers.utils import logging


logging.set_verbosity_info()







def       UpperCamelCase_					(     lowerCamelCase							:					List[str]     , lowerCamelCase							:					Optional[int]     , lowerCamelCase							:					List[str]   )						->     Optional[int]:



       """simple docstring"""







       __magic_name__			:		int        =     TaConfig.from_json_file(lowerCamelCase   )
       print(f"""Building PyTorch model from configuration: {config}"""   )
       __magic_name__			:		Union[str, Any]        =     TaForConditionalGeneration(lowerCamelCase   )

       # Load weights from tf checkpoint
       load_tf_weights_in_ta(lowerCamelCase     , lowerCamelCase     , lowerCamelCase   )

       # Save pytorch-model
       print(f"""Save PyTorch model to {pytorch_dump_path}"""   )
       model.save_pretrained(lowerCamelCase   )


if __name__ == "__main__":
 A									=						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(
     """--config_file""",
     default=None,
     type=str,
     required=True,
     help=(
         """The config json file corresponding to the pre-trained T5 model. \nThis specifies the model architecture."""
     ),
 )
 parser.add_argument(
     """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
 )
 A									=						parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)
