code: 
  
  
  '''simple docstring'''
  
  
  
  import argparse
  
  import torch
  
  from transformers import ChineseCLIPConfig, ChineseCLIPModel
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     List[Any]		,   _SCREAMING_SNAKE_CASE   :     List[str]		,   _SCREAMING_SNAKE_CASE   :     List[str]     ):
  					__a    : Union[str, Any]      					=						pt_weights[F"""{prefix}.in_proj_weight"""].chunk(3		,   dim=0     )
  					__a    : int      					=						pt_weights[F"""{prefix}.in_proj_bias"""].chunk(3		,   dim=0     )
  
  					__a    : Union[str, Any]      					=						pt_weights[F"""{prefix}.out_proj.weight"""]
  					__a    : List[Any]      					=						pt_weights[F"""{prefix}.out_proj.bias"""]
  
  					__a    : Dict      					=						q_proj
  					__a    : Any      					=						q_proj_bias
  
  					__a    : str      					=						k_proj
  					__a    : Tuple      					=						k_proj_bias
  
  					__a    : List[Any]      					=						v_proj
  					__a    : Tuple      					=						v_proj_bias
  
  					__a    : List[Any]      					=						out_proj_weights
  					__a    : Optional[Any]      					=						out_proj_bias
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     Optional[int]		,   _SCREAMING_SNAKE_CASE   :     Tuple		,   _SCREAMING_SNAKE_CASE   :     Optional[Any]     ):
  					copy_linear(hf_mlp.fca		,   UpperCAmelCase_		,   F"""{prefix}.c_fc"""     )
  					copy_linear(hf_mlp.fca		,   UpperCAmelCase_		,   F"""{prefix}.c_proj"""     )
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     List[str]		,   _SCREAMING_SNAKE_CASE   :     List[Any]		,   _SCREAMING_SNAKE_CASE   :     Dict     ):
  					__a    : str      					=						pt_weights[F"""{prefix}.weight"""].data
  					__a    : Union[str, Any]      					=						pt_weights[F"""{prefix}.bias"""].data
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     Union[str, Any]		,   _SCREAMING_SNAKE_CASE   :     Union[str, Any]		,   _SCREAMING_SNAKE_CASE   :     List[Any]     ):
  					copy_linear(hf_layer.layer_norma		,   UpperCAmelCase_		,   F"""{prefix}.ln_1"""     )
  					copy_linear(hf_layer.layer_norma		,   UpperCAmelCase_		,   F"""{prefix}.ln_2"""     )
  
  					# copy MLP
  					copy_mlp(hf_layer.mlp		,   UpperCAmelCase_		,   F"""{prefix}.mlp"""     )
  
  					# copy attn
  					copy_attn_layer(hf_layer.self_attn		,   UpperCAmelCase_		,   F"""{prefix}.attn"""     )
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     Any		,   _SCREAMING_SNAKE_CASE   :     Dict		,   _SCREAMING_SNAKE_CASE   :     Dict     ):
  
  
  
  
  
  
  					for layer_id, hf_layer in enumerate(UpperCAmelCase_     ):
  										copy_layer(UpperCAmelCase_		,   UpperCAmelCase_		,   F"""{prefix}.{layer_id}"""     )
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     str		,   _SCREAMING_SNAKE_CASE   :     List[str]     ):
  					__a    : Any      					=						pt_weights['''text_projection'''].data.T
  
  					# copy text encoder
  					for name, param in hf_model.text_model.named_parameters():
  										__a    : List[Any]      					=						pt_weights[F"""bert.{name}"""].data
  
  
  
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     List[str]		,   _SCREAMING_SNAKE_CASE   :     Optional[Any]     ):
  					__a    : List[Any]      					=						pt_weights['''visual.proj'''].data.T
  
  					# copy layer norms
  					copy_linear(hf_model.vision_model.pre_layrnorm		,   UpperCAmelCase_		,   'visual.ln_pre'     )
  					copy_linear(hf_model.vision_model.post_layernorm		,   UpperCAmelCase_		,   'visual.ln_post'     )
  
  					# copy embeddings
  					__a    : Union[str, Any]      					=						pt_weights['''visual.conv1.weight'''].data
  					__a    : Dict      					=						pt_weights['''visual.class_embedding'''].data
  					__a    : Optional[int]      					=						pt_weights['''visual.positional_embedding'''].data
  
  					# copy encoder
  					copy_layers(hf_model.vision_model.encoder.layers		,   UpperCAmelCase_		,   'visual.transformer.resblocks'     )
  
  
  
  
  
  
  @torch.no_grad()
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     Optional[Any]		,   _SCREAMING_SNAKE_CASE   :     Tuple		,   _SCREAMING_SNAKE_CASE   :     List[str]=None     ):
  					assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
  					__a    : Dict      					=						ChineseCLIPConfig.from_pretrained(UpperCAmelCase_     )
  
  					__a    : List[Any]      					=						ChineseCLIPModel(UpperCAmelCase_     ).eval()
  
  					__a    : Dict      					=						torch.load(UpperCAmelCase_		,   map_location='cpu'     )['''state_dict''']
  					__a    : Any      					=						{(name[7:] if name.startswith('module.'     ) else name): value for name, value in pt_weights.items()}
  
  					copy_text_model_and_projection(UpperCAmelCase_		,   UpperCAmelCase_     )
  					copy_vision_model_and_projection(UpperCAmelCase_		,   UpperCAmelCase_     )
  					__a    : Union[str, Any]      					=						pt_weights['''logit_scale'''].data
  
  					hf_model.save_pretrained(UpperCAmelCase_     )
  
  
  if __name__ == "__main__":
  	__lowercase			:		Optional[Any] =			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.'
  	)
  	__lowercase			:		Tuple =			parser.parse_args()
  
  	convert_chinese_clip_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)
  	print('The conversion is finished!')
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  def 						lowerCamelCase							(_SCREAMING_SNAKE_CASE   :     set		,   _SCREAMING_SNAKE_CASE   :     set     ):
  					assert isinstance(_SCREAMING_SNAKE_CASE		,   _SCREAMING_SNAKE_CASE     ), F"""The input value of [set_a={set_a}] is not a set"""
  					assert isinstance(_SCREAMING_SNAKE_CASE		,   _SCREAMING_SNAKE_CASE     ), F"""The input value of [set_b={set_b}] is not a set"""
  
  					return {a + b for a in set_a for b in set_b}
  
  
  if __name__ == "__main__":
  	from doctest import testmod
  
  	testmod()
  
  
  
  