



"""simple docstring"""
import argparse

import torch

from transformers import ChineseCLIPConfig, ChineseCLIPModel
def   A_    (     _lowercase,   _lowercase,   _lowercase      ):







						'''simple docstring'''


						snake_case_,			snake_case_,			snake_case_					:Optional[Any]		=     pt_weights[f"""{prefix}.in_proj_weight"""].chunk(3,   dim=0      )
						snake_case_,			snake_case_,			snake_case_					:Dict		=     pt_weights[f"""{prefix}.in_proj_bias"""].chunk(3,   dim=0      )

						snake_case_					:Optional[Any]		=     pt_weights[f"""{prefix}.out_proj.weight"""]
						snake_case_					:Tuple		=     pt_weights[f"""{prefix}.out_proj.bias"""]

						snake_case_					:int		=     q_proj
						snake_case_					:str		=     q_proj_bias

						snake_case_					:Tuple		=     k_proj
						snake_case_					:Optional[int]		=     k_proj_bias

						snake_case_					:Any		=     v_proj
						snake_case_					:Optional[int]		=     v_proj_bias

						snake_case_					:Optional[Any]		=     out_proj_weights
						snake_case_					:Dict		=     out_proj_bias
def   A_    (     _lowercase,   _lowercase,   _lowercase      ):







						'''simple docstring'''


						copy_linear(hf_mlp.fca,   _lowercase,   f"""{prefix}.c_fc"""      )
						copy_linear(hf_mlp.fca,   _lowercase,   f"""{prefix}.c_proj"""      )
def   A_    (     _lowercase,   _lowercase,   _lowercase      ):







						'''simple docstring'''


						snake_case_					:Tuple		=     pt_weights[f"""{prefix}.weight"""].data
						snake_case_					:str		=     pt_weights[f"""{prefix}.bias"""].data
def   A_    (     _lowercase,   _lowercase,   _lowercase      ):







						'''simple docstring'''


						copy_linear(hf_layer.layer_norma,   _lowercase,   f"""{prefix}.ln_1"""      )
						copy_linear(hf_layer.layer_norma,   _lowercase,   f"""{prefix}.ln_2"""      )

						# copy MLP
						copy_mlp(hf_layer.mlp,   _lowercase,   f"""{prefix}.mlp"""      )

						# copy attn
						copy_attn_layer(hf_layer.self_attn,   _lowercase,   f"""{prefix}.attn"""      )
def   A_    (     _lowercase,   _lowercase,   _lowercase      ):







						'''simple docstring'''


						for layer_id, hf_layer in enumerate(_lowercase      ):
												copy_layer(_lowercase,   _lowercase,   f"""{prefix}.{layer_id}"""      )
def   A_    (     _lowercase,   _lowercase      ):







						'''simple docstring'''


						snake_case_					:Union[str, Any]		=     pt_weights["""text_projection"""].data.T

						# copy text encoder
						for name, param in hf_model.text_model.named_parameters():
												snake_case_					:Tuple		=     pt_weights[f"""bert.{name}"""].data
def   A_    (     _lowercase,   _lowercase      ):







						'''simple docstring'''


						snake_case_					:str		=     pt_weights["""visual.proj"""].data.T

						# copy layer norms
						copy_linear(hf_model.vision_model.pre_layrnorm,   _lowercase,   """visual.ln_pre"""      )
						copy_linear(hf_model.vision_model.post_layernorm,   _lowercase,   """visual.ln_post"""      )

						# copy embeddings
						snake_case_					:int		=     pt_weights["""visual.conv1.weight"""].data
						snake_case_					:Union[str, Any]		=     pt_weights["""visual.class_embedding"""].data
						snake_case_					:Tuple		=     pt_weights["""visual.positional_embedding"""].data

						# copy encoder
						copy_layers(hf_model.vision_model.encoder.layers,   _lowercase,   """visual.transformer.resblocks"""      )
@torch.no_grad()
def   A_    (     _lowercase,   _lowercase,   _lowercase=None      ):







						'''simple docstring'''


						assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
						snake_case_					:List[Any]		=     ChineseCLIPConfig.from_pretrained(_lowercase      )

						snake_case_					:int		=     ChineseCLIPModel(_lowercase      ).eval()

						snake_case_					:Dict		=     torch.load(_lowercase,   map_location="""cpu"""      )["""state_dict"""]
						snake_case_					:Union[str, Any]		=     {(name[7:] if name.startswith("""module."""      ) else name): value for name, value in pt_weights.items()}

						copy_text_model_and_projection(_lowercase,   _lowercase      )
						copy_vision_model_and_projection(_lowercase,   _lowercase      )
						snake_case_					:Dict		=     pt_weights["""logit_scale"""].data

						hf_model.save_pretrained(_lowercase      )


if __name__ == "__main__":
						__a           =							argparse.ArgumentParser()
						parser.add_argument(
						    "--pytorch_dump_folder_path",
						    default=None,
						    type=str,
						    help="Path to the output folder storing converted hf PyTorch model.",
						)
						parser.add_argument(
						    "--checkpoint_path", default=None, type=str, help="Path to original github format ChineseCLIP checkpoint."
						)
						parser.add_argument(
						    "--config_path", default=None, required=True, type=str, help="Path to hf config.json of model to convert."
						)
						__a           =							parser.parse_args()

						convert_chinese_clip_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)
						print("The conversion is finished!")





"""simple docstring"""
import os
def   A_    (     ):







						'''simple docstring'''


						snake_case_					:Optional[Any]		=     os.path.dirname(os.path.realpath(_lowercase      )      )
						snake_case_					:int		=     os.path.join(_lowercase,   """triangle.txt"""      )

						with open(_lowercase      ) as in_file:
												snake_case_					:List[Any]		=     [[int(_lowercase      ) for i in line.split()] for line in in_file]

						while len(_lowercase      ) != 1:
												snake_case_					:str		=     triangle.pop()
												snake_case_					:int		=     triangle[-1]
												for j in range(len(_lowercase      ) - 1      ):
																		curr_row[j] += max(last_row[j],   last_row[j + 1]      )
						return triangle[0][0]


if __name__ == "__main__":
						print(solution())
