
import argparse

import torch

from diffusers import UNetaDConditionModel
def     UpperCAmelCase__							(       __magic_name__						:     Optional[Any]							,  __magic_name__						:     int							,  __magic_name__						:     Dict							,  __magic_name__						:     str=None							,  __magic_name__						:     List[Any]=None							,  __magic_name__						:     Tuple=None  ):


					'''simple docstring'''

					assert isinstance(__A							,  __A  ), "Paths should be a list of dicts containing 'old' and 'new' keys."

					# Splits the attention layers into three variables.
					if attention_paths_to_split is not None:
										for path, path_map in attention_paths_to_split.items():
															lowerCAmelCase		:					Union[str, Any]  	=     old_checkpoint[path]
															lowerCAmelCase		:					List[str]  	=     old_tensor.shape[0] // 3

															lowerCAmelCase		:					Optional[Any]  	=     (-1, channels) if len(old_tensor.shape  ) == 3 else (-1)

															lowerCAmelCase		:					str  	=     old_tensor.shape[0] // config['''num_head_channels'''] // 3

															lowerCAmelCase		:					int  	=     old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:]  )
															lowerCAmelCase	,							lowerCAmelCase	,							lowerCAmelCase		:					Optional[Any]  	=     old_tensor.split(channels // num_heads							,  dim=1  )

															lowerCAmelCase		:					Any  	=     query.reshape(__A  )
															lowerCAmelCase		:					List[Any]  	=     key.reshape(__A  )
															lowerCAmelCase		:					List[Any]  	=     value.reshape(__A  )

					for path in paths:
										lowerCAmelCase		:					Any  	=     path['''new''']

										# These have already been assigned
										if attention_paths_to_split is not None and new_path in attention_paths_to_split:
															continue

										if additional_replacements is not None:
															for replacement in additional_replacements:
																				lowerCAmelCase		:					Dict  	=     new_path.replace(replacement['''old''']							,  replacement['''new''']  )

																				    # proj_attn.weight has to be converted from conv 1D to linear
										lowerCAmelCase		:					List[Any]  	=     old_checkpoint[path['''old''']]
										lowerCAmelCase		:					Dict  	=     ['''proj_attn.weight''']
										lowerCAmelCase		:					Tuple  	=     ['''proj_out.weight''', '''proj_in.weight''']
										if any(k in new_path for k in names  ):
															lowerCAmelCase		:					Union[str, Any]  	=     weight[:, :, 0]
										elif any(k in new_path for k in names_a  ) and len(weight.shape  ) > 2 and ".attentions." not in new_path:
															lowerCAmelCase		:					List[Any]  	=     weight[:, :, 0]
										else:
															lowerCAmelCase		:					Tuple  	=     weight
def     UpperCAmelCase__							(       __magic_name__						:     Optional[Any]							,  __magic_name__						:     List[Any]=0  ):


					'''simple docstring'''

					lowerCAmelCase		:					str  	=     []
					for old_item in old_list:
										lowerCAmelCase		:					Tuple  	=     old_item

										#         new_item = new_item.replace('norm.weight', 'group_norm.weight')
										#         new_item = new_item.replace('norm.bias', 'group_norm.bias')

										#         new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
										#         new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')

										#         new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)

										mapping.append({'''old''': old_item, '''new''': new_item}  )

					return mapping
def     UpperCAmelCase__							(       __magic_name__						:     List[str]							,  __magic_name__						:     Union[str, Any]=1  ):


					'''simple docstring'''

					if n_shave_prefix_segments >= 0:
										return ".".join(path.split('''.'''  )[n_shave_prefix_segments:]  )
					else:
										return ".".join(path.split('''.'''  )[:n_shave_prefix_segments]  )
def     UpperCAmelCase__							(       __magic_name__						:     str							,  __magic_name__						:     Any=0  ):


					'''simple docstring'''

					lowerCAmelCase		:					Optional[Any]  	=     []
					for old_item in old_list:
										mapping.append({'''old''': old_item, '''new''': old_item}  )

					return mapping
def     UpperCAmelCase__							(       __magic_name__						:     int							,  __magic_name__						:     Union[str, Any]=0  ):


					'''simple docstring'''

					lowerCAmelCase		:					List[Any]  	=     []
					for old_item in old_list:
										lowerCAmelCase		:					List[Any]  	=     old_item.replace('''in_layers.0'''							,  '''norm1'''  )
										lowerCAmelCase		:					List[Any]  	=     new_item.replace('''in_layers.2'''							,  '''conv1'''  )

										lowerCAmelCase		:					Optional[Any]  	=     new_item.replace('''out_layers.0'''							,  '''norm2'''  )
										lowerCAmelCase		:					str  	=     new_item.replace('''out_layers.3'''							,  '''conv2'''  )

										lowerCAmelCase		:					int  	=     new_item.replace('''emb_layers.1'''							,  '''time_emb_proj'''  )
										lowerCAmelCase		:					Dict  	=     new_item.replace('''skip_connection'''							,  '''conv_shortcut'''  )

										lowerCAmelCase		:					Tuple  	=     shave_segments(__A							,  n_shave_prefix_segments=__A  )

										if "temopral_conv" not in old_item:
															mapping.append({'''old''': old_item, '''new''': new_item}  )

					return mapping
def     UpperCAmelCase__							(       __magic_name__						:     Dict							,  __magic_name__						:     Tuple							,  __magic_name__						:     List[Any]=None							,  __magic_name__						:     Tuple=False  ):


					'''simple docstring'''

					lowerCAmelCase		:					Optional[Any]  	=     {}
					lowerCAmelCase		:					Union[str, Any]  	=     list(checkpoint.keys()  )

					lowerCAmelCase		:					List[str]  	=     '''model.diffusion_model.'''

					# at least a 100 parameters have to start with `model_ema` in order for the checkpoint to be EMA
					if sum(k.startswith('''model_ema'''  ) for k in keys  ) > 1_00 and extract_ema:
										print(f'''Checkpoint {path} has both EMA and non-EMA weights.'''  )
										print(
										    '''In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA'''
										    ''' weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag.'''  )
										for key in keys:
															if key.startswith('''model.diffusion_model'''  ):
																				lowerCAmelCase		:					int  	=     '''model_ema.''' + ''''''.join(key.split('''.'''  )[1:]  )
																				lowerCAmelCase		:					int  	=     checkpoint.pop(__A  )
					else:
										if sum(k.startswith('''model_ema'''  ) for k in keys  ) > 1_00:
															print(
															    '''In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA'''
															    ''' weights (usually better for inference), please make sure to add the `--extract_ema` flag.'''  )

										for key in keys:
															lowerCAmelCase		:					Any  	=     checkpoint.pop(__A  )

					lowerCAmelCase		:					Optional[Any]  	=     {}

					lowerCAmelCase		:					Tuple  	=     unet_state_dict['''time_embed.0.weight''']
					lowerCAmelCase		:					List[Any]  	=     unet_state_dict['''time_embed.0.bias''']
					lowerCAmelCase		:					Dict  	=     unet_state_dict['''time_embed.2.weight''']
					lowerCAmelCase		:					Optional[int]  	=     unet_state_dict['''time_embed.2.bias''']

					if config["class_embed_type"] is None:
										# No parameters to port
										...
					elif config["class_embed_type"] == "timestep" or config["class_embed_type"] == "projection":
										lowerCAmelCase		:					int  	=     unet_state_dict['''label_emb.0.0.weight''']
										lowerCAmelCase		:					Any  	=     unet_state_dict['''label_emb.0.0.bias''']
										lowerCAmelCase		:					int  	=     unet_state_dict['''label_emb.0.2.weight''']
										lowerCAmelCase		:					Optional[int]  	=     unet_state_dict['''label_emb.0.2.bias''']
					else:
										raise NotImplementedError(f'''Not implemented `class_embed_type`: {config["class_embed_type"]}'''  )

					lowerCAmelCase		:					List[str]  	=     unet_state_dict['''input_blocks.0.0.weight''']
					lowerCAmelCase		:					Dict  	=     unet_state_dict['''input_blocks.0.0.bias''']

					lowerCAmelCase		:					Any  	=     [v for v in unet_state_dict if v.startswith('''input_blocks.0.1'''  )]
					lowerCAmelCase		:					List[str]  	=     renew_attention_paths(__A  )
					lowerCAmelCase		:					List[str]  	=     {'''old''': '''input_blocks.0.1''', '''new''': '''transformer_in'''}
					assign_to_checkpoint(__A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

					lowerCAmelCase		:					Tuple  	=     unet_state_dict['''out.0.weight''']
					lowerCAmelCase		:					List[str]  	=     unet_state_dict['''out.0.bias''']
					lowerCAmelCase		:					Dict  	=     unet_state_dict['''out.2.weight''']
					lowerCAmelCase		:					str  	=     unet_state_dict['''out.2.bias''']

					# Retrieves the keys for the input blocks only
					lowerCAmelCase		:					Tuple  	=     len({'''.'''.join(layer.split('''.'''  )[:2]  ) for layer in unet_state_dict if '''input_blocks''' in layer}  )
					lowerCAmelCase		:					Union[str, Any]  	=     {
					    layer_id: [key for key in unet_state_dict if f'''input_blocks.{layer_id}''' in key]
					    for layer_id in range(__A  )
					}

					# Retrieves the keys for the middle blocks only
					lowerCAmelCase		:					List[Any]  	=     len({'''.'''.join(layer.split('''.'''  )[:2]  ) for layer in unet_state_dict if '''middle_block''' in layer}  )
					lowerCAmelCase		:					Optional[Any]  	=     {
					    layer_id: [key for key in unet_state_dict if f'''middle_block.{layer_id}''' in key]
					    for layer_id in range(__A  )
					}

					# Retrieves the keys for the output blocks only
					lowerCAmelCase		:					Tuple  	=     len({'''.'''.join(layer.split('''.'''  )[:2]  ) for layer in unet_state_dict if '''output_blocks''' in layer}  )
					lowerCAmelCase		:					int  	=     {
					    layer_id: [key for key in unet_state_dict if f'''output_blocks.{layer_id}''' in key]
					    for layer_id in range(__A  )
					}

					for i in range(1							,  __A  ):
										lowerCAmelCase		:					Optional[Any]  	=     (i - 1) // (config['''layers_per_block'''] + 1)
										lowerCAmelCase		:					List[str]  	=     (i - 1) % (config['''layers_per_block'''] + 1)

										lowerCAmelCase		:					Optional[Any]  	=     [
										    key for key in input_blocks[i] if f'''input_blocks.{i}.0''' in key and f'''input_blocks.{i}.0.op''' not in key
										]
										lowerCAmelCase		:					Dict  	=     [key for key in input_blocks[i] if f'''input_blocks.{i}.1''' in key]
										lowerCAmelCase		:					str  	=     [key for key in input_blocks[i] if f'''input_blocks.{i}.2''' in key]

										if f'''input_blocks.{i}.op.weight''' in unet_state_dict:
															lowerCAmelCase		:					Optional[int]  	=     unet_state_dict.pop(
															    f'''input_blocks.{i}.op.weight'''  )
															lowerCAmelCase		:					Tuple  	=     unet_state_dict.pop(
															    f'''input_blocks.{i}.op.bias'''  )

										lowerCAmelCase		:					Dict  	=     renew_resnet_paths(__A  )
										lowerCAmelCase		:					int  	=     {'''old''': f'''input_blocks.{i}.0''', '''new''': f'''down_blocks.{block_id}.resnets.{layer_in_block_id}'''}
										assign_to_checkpoint(
										    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

										lowerCAmelCase		:					Optional[Any]  	=     [key for key in resnets if '''temopral_conv''' in key]
										lowerCAmelCase		:					int  	=     renew_temp_conv_paths(__A  )
										lowerCAmelCase		:					List[str]  	=     {
										    '''old''': f'''input_blocks.{i}.0.temopral_conv''',
										    '''new''': f'''down_blocks.{block_id}.temp_convs.{layer_in_block_id}''',
										}
										assign_to_checkpoint(
										    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

										if len(__A  ):
															lowerCAmelCase		:					List[Any]  	=     renew_attention_paths(__A  )
															lowerCAmelCase		:					List[Any]  	=     {'''old''': f'''input_blocks.{i}.1''', '''new''': f'''down_blocks.{block_id}.attentions.{layer_in_block_id}'''}
															assign_to_checkpoint(
															    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

										if len(__A  ):
															lowerCAmelCase		:					int  	=     renew_attention_paths(__A  )
															lowerCAmelCase		:					str  	=     {
															    '''old''': f'''input_blocks.{i}.2''',
															    '''new''': f'''down_blocks.{block_id}.temp_attentions.{layer_in_block_id}''',
															}
															assign_to_checkpoint(
															    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

					lowerCAmelCase		:					Dict  	=     middle_blocks[0]
					lowerCAmelCase		:					Dict  	=     [key for key in resnet_a if '''temopral_conv''' in key]
					lowerCAmelCase		:					List[Any]  	=     middle_blocks[1]
					lowerCAmelCase		:					int  	=     middle_blocks[2]
					lowerCAmelCase		:					Optional[int]  	=     middle_blocks[3]
					lowerCAmelCase		:					Tuple  	=     [key for key in resnet_a if '''temopral_conv''' in key]

					lowerCAmelCase		:					List[Any]  	=     renew_resnet_paths(__A  )
					lowerCAmelCase		:					Optional[int]  	=     {'''old''': '''middle_block.0''', '''new''': '''mid_block.resnets.0'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  config=__A							,  additional_replacements=[meta_path]  )

					lowerCAmelCase		:					Optional[int]  	=     renew_temp_conv_paths(__A  )
					lowerCAmelCase		:					Union[str, Any]  	=     {'''old''': '''middle_block.0.temopral_conv''', '''new''': '''mid_block.temp_convs.0'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  config=__A							,  additional_replacements=[meta_path]  )

					lowerCAmelCase		:					Optional[Any]  	=     renew_resnet_paths(__A  )
					lowerCAmelCase		:					Any  	=     {'''old''': '''middle_block.3''', '''new''': '''mid_block.resnets.1'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  config=__A							,  additional_replacements=[meta_path]  )

					lowerCAmelCase		:					List[Any]  	=     renew_temp_conv_paths(__A  )
					lowerCAmelCase		:					Tuple  	=     {'''old''': '''middle_block.3.temopral_conv''', '''new''': '''mid_block.temp_convs.1'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  config=__A							,  additional_replacements=[meta_path]  )

					lowerCAmelCase		:					str  	=     renew_attention_paths(__A  )
					lowerCAmelCase		:					Optional[Any]  	=     {'''old''': '''middle_block.1''', '''new''': '''mid_block.attentions.0'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

					lowerCAmelCase		:					Optional[int]  	=     renew_attention_paths(__A  )
					lowerCAmelCase		:					Dict  	=     {'''old''': '''middle_block.2''', '''new''': '''mid_block.temp_attentions.0'''}
					assign_to_checkpoint(
					    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

					for i in range(__A  ):
										lowerCAmelCase		:					List[str]  	=     i // (config['''layers_per_block'''] + 1)
										lowerCAmelCase		:					Tuple  	=     i % (config['''layers_per_block'''] + 1)
										lowerCAmelCase		:					Dict  	=     [shave_segments(__A							,  2  ) for name in output_blocks[i]]
										lowerCAmelCase		:					Tuple  	=     {}

										for layer in output_block_layers:
															lowerCAmelCase	,							lowerCAmelCase		:					List[str]  	=     layer.split('''.'''  )[0], shave_segments(__A							,  1  )
															if layer_id in output_block_list:
																				output_block_list[layer_id].append(__A  )
															else:
																				lowerCAmelCase		:					List[Any]  	=     [layer_name]

										if len(__A  ) > 1:
															lowerCAmelCase		:					Tuple  	=     [key for key in output_blocks[i] if f'''output_blocks.{i}.0''' in key]
															lowerCAmelCase		:					Any  	=     [key for key in output_blocks[i] if f'''output_blocks.{i}.1''' in key]
															lowerCAmelCase		:					List[Any]  	=     [key for key in output_blocks[i] if f'''output_blocks.{i}.2''' in key]

															lowerCAmelCase		:					List[Any]  	=     renew_resnet_paths(__A  )
															lowerCAmelCase		:					Optional[Any]  	=     renew_resnet_paths(__A  )

															lowerCAmelCase		:					int  	=     {'''old''': f'''output_blocks.{i}.0''', '''new''': f'''up_blocks.{block_id}.resnets.{layer_in_block_id}'''}
															assign_to_checkpoint(
															    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

															lowerCAmelCase		:					List[str]  	=     [key for key in resnets if '''temopral_conv''' in key]
															lowerCAmelCase		:					Optional[int]  	=     renew_temp_conv_paths(__A  )
															lowerCAmelCase		:					Dict  	=     {
															    '''old''': f'''output_blocks.{i}.0.temopral_conv''',
															    '''new''': f'''up_blocks.{block_id}.temp_convs.{layer_in_block_id}''',
															}
															assign_to_checkpoint(
															    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

															lowerCAmelCase		:					int  	=     {k: sorted(__A  ) for k, v in output_block_list.items()}
															if ["conv.bias", "conv.weight"] in output_block_list.values():
																				lowerCAmelCase		:					Union[str, Any]  	=     list(output_block_list.values()  ).index(['''conv.bias''', '''conv.weight''']  )
																				lowerCAmelCase		:					List[Any]  	=     unet_state_dict[
																				    f'''output_blocks.{i}.{index}.conv.weight'''
																				]
																				lowerCAmelCase		:					str  	=     unet_state_dict[
																				    f'''output_blocks.{i}.{index}.conv.bias'''
																				]

																				# Clear attentions as they have been attributed above.
																				if len(__A  ) == 2:
																									lowerCAmelCase		:					List[Any]  	=     []

															if len(__A  ):
																				lowerCAmelCase		:					Union[str, Any]  	=     renew_attention_paths(__A  )
																				lowerCAmelCase		:					int  	=     {
																				    '''old''': f'''output_blocks.{i}.1''',
																				    '''new''': f'''up_blocks.{block_id}.attentions.{layer_in_block_id}''',
																				}
																				assign_to_checkpoint(
																				    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )

															if len(__A  ):
																				lowerCAmelCase		:					Union[str, Any]  	=     renew_attention_paths(__A  )
																				lowerCAmelCase		:					List[Any]  	=     {
																				    '''old''': f'''output_blocks.{i}.2''',
																				    '''new''': f'''up_blocks.{block_id}.temp_attentions.{layer_in_block_id}''',
																				}
																				assign_to_checkpoint(
																				    __A							,  __A							,  __A							,  additional_replacements=[meta_path]							,  config=__A  )
										else:
															lowerCAmelCase		:					str  	=     renew_resnet_paths(__A							,  n_shave_prefix_segments=1  )
															for path in resnet_0_paths:
																				lowerCAmelCase		:					List[str]  	=     '''.'''.join(['''output_blocks''', str(__A  ), path['''old''']]  )
																				lowerCAmelCase		:					Optional[int]  	=     '''.'''.join(['''up_blocks''', str(__A  ), '''resnets''', str(__A  ), path['''new''']]  )
																				lowerCAmelCase		:					Union[str, Any]  	=     unet_state_dict[old_path]

															lowerCAmelCase		:					int  	=     [l for l in output_block_layers if '''temopral_conv''' in l]
															for path in temopral_conv_paths:
																				lowerCAmelCase		:					List[str]  	=     path.split('''temopral_conv.'''  )[-1]
																				lowerCAmelCase		:					Optional[int]  	=     '''.'''.join(['''output_blocks''', str(__A  ), str(__A  ), '''temopral_conv''', pruned_path]  )
																				lowerCAmelCase		:					Optional[Any]  	=     '''.'''.join(['''up_blocks''', str(__A  ), '''temp_convs''', str(__A  ), pruned_path]  )
																				lowerCAmelCase		:					Optional[Any]  	=     unet_state_dict[old_path]

					return new_checkpoint


if __name__ == "__main__":
		__SCREAMING_SNAKE_CASE			:   str         =     argparse.ArgumentParser()

		parser.add_argument(
		    '--checkpoint_path', default=None, type=str, required=True, help='Path to the checkpoint to convert.'
		)
		parser.add_argument('--dump_path', default=None, type=str, required=True, help='Path to the output model.')
		__SCREAMING_SNAKE_CASE			:   List[Any]         =     parser.parse_args()

		__SCREAMING_SNAKE_CASE			:   int         =     torch.load(args.checkpoint_path, map_location='cpu')
		__SCREAMING_SNAKE_CASE			:   int         =     UNetaDConditionModel()

		__SCREAMING_SNAKE_CASE			:   List[str]         =     convert_ldm_unet_checkpoint(unet_checkpoint, unet.config)

		__SCREAMING_SNAKE_CASE			:   List[Any]         =     set(unet.state_dict().keys()) - set(converted_ckpt.keys())
		__SCREAMING_SNAKE_CASE			:   List[str]         =     set(converted_ckpt.keys()) - set(unet.state_dict().keys())

		assert len(diff_a) == len(diff_a) == 0, "Converted weights don't match"

		# load state_dict
		unet.load_state_dict(converted_ckpt)

		unet.save_pretrained(args.dump_path)

		# -- finish converting the unet --


import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard


class 		__magic_name__   (						unittest.TestCase    ):





		def       _A							(							self    :	Dict				):
							lowerCAmelCase		:					List[Any]  	=     {
							    '''model_details''': {
							        '''Organization''': '''testing''',
							        '''Model date''': '''today''',
							        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
							        '''Architecture''': '''Convolutional Neural Network.''',
							    },
							    '''metrics''': '''BLEU and ROUGE-1''',
							    '''evaluation_data''': {
							        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
							        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
							    },
							    '''training_data''': {
							        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
							        '''Preprocessing''': (
							            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
							            ''' https://arxiv.org/pdf/1810.03993.pdf'''
							        ),
							    },
							    '''quantitative_analyses''': {'''BLEU''': 5_5.1, '''ROUGE-1''': 7_6},
							}





		def       _A							(							self    :	str				):
							lowerCAmelCase		:					Dict  	=     ModelCard.from_dict(self.inputs_dict				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''model_details'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''intended_use'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''factors'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''metrics'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''evaluation_data'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''training_data'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''quantitative_analyses'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''ethical_considerations'''				)				)
							self.assertTrue(hasattr(lowerCamelCase__						,  '''caveats_and_recommendations'''				)				)





		def       _A							(							self    :	Optional[Any]				):
							lowerCAmelCase		:					Tuple  	=     ModelCard.from_dict(self.inputs_dict				)
							lowerCAmelCase		:					Dict  	=     json.loads(modelcard.to_json_string()				)
							for key, value in self.inputs_dict.items():
												self.assertEqual(obj[key]						,  lowerCamelCase__				)





		def       _A							(							self    :	Tuple				):
							lowerCAmelCase		:					Tuple  	=     ModelCard.from_dict(self.inputs_dict				)

							with tempfile.TemporaryDirectory() as tmpdirname:
												lowerCAmelCase		:					str  	=     os.path.join(lowerCamelCase__						,  '''modelcard.json'''				)
												model_card_first.to_json_file(lowerCamelCase__				)
												lowerCAmelCase		:					Dict  	=     ModelCard.from_json_file(lowerCamelCase__				)

							self.assertEqual(model_card_second.to_dict()						,  model_card_first.to_dict()				)





		def       _A							(							self    :	Union[str, Any]				):
							lowerCAmelCase		:					int  	=     ModelCard.from_dict(self.inputs_dict				)

							with tempfile.TemporaryDirectory() as tmpdirname:
												model_card_first.save_pretrained(lowerCamelCase__				)
												lowerCAmelCase		:					Any  	=     ModelCard.from_pretrained(lowerCamelCase__				)

							self.assertEqual(model_card_second.to_dict()						,  model_card_first.to_dict()				)
