





"""simple docstring"""


import argparse

import torch

from transformers import ChineseCLIPConfig, ChineseCLIPModel





def SCREAMING_SNAKE_CASE_   (       snake_case   :					int						,  snake_case   :					Optional[Any]						,  snake_case   :					str		)->		Optional[int]:
       _lowerCamelCase	,	_lowerCamelCase	,	_lowerCamelCase    	=					pt_weights[f'{prefix}.in_proj_weight'].chunk(3						,  dim=0		)
       _lowerCamelCase	,	_lowerCamelCase	,	_lowerCamelCase    	=					pt_weights[f'{prefix}.in_proj_bias'].chunk(3						,  dim=0		)

       _lowerCamelCase    	=					pt_weights[f'{prefix}.out_proj.weight']
       _lowerCamelCase    	=					pt_weights[f'{prefix}.out_proj.bias']

       _lowerCamelCase    	=					q_proj
       _lowerCamelCase    	=					q_proj_bias

       _lowerCamelCase    	=					k_proj
       _lowerCamelCase    	=					k_proj_bias

       _lowerCamelCase    	=					v_proj
       _lowerCamelCase    	=					v_proj_bias

       _lowerCamelCase    	=					out_proj_weights
       _lowerCamelCase    	=					out_proj_bias





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Dict						,  snake_case   :					int						,  snake_case   :					List[str]		)->		int:
       copy_linear(hf_mlp.fca						,  snake_case						,  f'{prefix}.c_fc'		)
       copy_linear(hf_mlp.fca						,  snake_case						,  f'{prefix}.c_proj'		)





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Any						,  snake_case   :					Union[str, Any]						,  snake_case   :					Dict		)->		Tuple:
       _lowerCamelCase    	=					pt_weights[f'{prefix}.weight'].data
       _lowerCamelCase    	=					pt_weights[f'{prefix}.bias'].data





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Union[str, Any]						,  snake_case   :					Optional[Any]						,  snake_case   :					List[Any]		)->		Any:
       # copy layer norms
       copy_linear(hf_layer.layer_norma						,  snake_case						,  f'{prefix}.ln_1'		)
       copy_linear(hf_layer.layer_norma						,  snake_case						,  f'{prefix}.ln_2'		)

       # copy MLP
       copy_mlp(hf_layer.mlp						,  snake_case						,  f'{prefix}.mlp'		)

       # copy attn
       copy_attn_layer(hf_layer.self_attn						,  snake_case						,  f'{prefix}.attn'		)





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Optional[Any]						,  snake_case   :					str						,  snake_case   :					Any		)->		List[str]:
       for layer_id, hf_layer in enumerate(snake_case		):
              copy_layer(snake_case						,  snake_case						,  f'{prefix}.{layer_id}'		)





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Optional[Any]						,  snake_case   :					Optional[Any]		)->		Tuple:
       # copy projection
       _lowerCamelCase    	=					pt_weights['text_projection'].data.T

       # copy text encoder
       for name, param in hf_model.text_model.named_parameters():
              _lowerCamelCase    	=					pt_weights[f'bert.{name}'].data





def SCREAMING_SNAKE_CASE_   (       snake_case   :					Optional[int]						,  snake_case   :					Any		)->		List[Any]:
       # copy projection
       _lowerCamelCase    	=					pt_weights['visual.proj'].data.T

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

       # copy embeddings
       _lowerCamelCase    	=					pt_weights['visual.conv1.weight'].data
       _lowerCamelCase    	=					pt_weights['visual.class_embedding'].data
       _lowerCamelCase    	=					pt_weights['visual.positional_embedding'].data

       # copy encoder
       copy_layers(hf_model.vision_model.encoder.layers						,  snake_case						,  'visual.transformer.resblocks'		)





@torch.no_grad()
def SCREAMING_SNAKE_CASE_   (       snake_case   :					Optional[Any]						,  snake_case   :					List[Any]						,  snake_case   :					Optional[int]=None		)->		Optional[int]:
       assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
       _lowerCamelCase    	=					ChineseCLIPConfig.from_pretrained(snake_case		)

       _lowerCamelCase    	=					ChineseCLIPModel(snake_case		).eval()

       _lowerCamelCase    	=					torch.load(snake_case						,  map_location='cpu'		)['state_dict']
       _lowerCamelCase    	=					{(name[7:] if name.startswith('module.'		) else name): value for name, value in pt_weights.items()}

       copy_text_model_and_projection(snake_case						,  snake_case		)
       copy_vision_model_and_projection(snake_case						,  snake_case		)
       _lowerCamelCase    	=					pt_weights['logit_scale'].data

       hf_model.save_pretrained(snake_case		)


if __name__ == "__main__":
      A_     :      str								=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_     :      Any								=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"""


A_     :      Dict								=1_0**8





def SCREAMING_SNAKE_CASE_   (       snake_case   :					int		)->		bool:
       if n % 10 == 0:
              return False
       _lowerCamelCase    	=					str(snake_case		)
       return s == s[::-1]





def SCREAMING_SNAKE_CASE_   (       )->		int:
       _lowerCamelCase    	=					set()
       _lowerCamelCase    	=					1
       _lowerCamelCase    	=					5
       while sum_squares < LIMIT:
              _lowerCamelCase    	=					first_square + 1
              while sum_squares < LIMIT:
                     if is_palindrome(snake_case		):
                            answer.add(snake_case		)
                     last_square += 1
                     sum_squares += last_square**2
              first_square += 1
              _lowerCamelCase    	=					first_square**2 + (first_square + 1) ** 2

       return sum(snake_case		)


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






