code: 
  
  import argparse
  
  import torch
  
  from transformers import ChineseCLIPConfig, ChineseCLIPModel
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     str:
  
  
  
  
  
  
      '''simple docstring'''
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.in_proj_weight'''].chunk(3       ,   dim=0      )
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.in_proj_bias'''].chunk(3       ,   dim=0      )
  
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.out_proj.weight''']
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.out_proj.bias''']
  
      __UpperCAmelCase									=			q_proj
      __UpperCAmelCase									=			q_proj_bias
  
      __UpperCAmelCase									=			k_proj
      __UpperCAmelCase									=			k_proj_bias
  
      __UpperCAmelCase									=			v_proj
      __UpperCAmelCase									=			v_proj_bias
  
      __UpperCAmelCase									=			out_proj_weights
      __UpperCAmelCase									=			out_proj_bias
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     str:
  
  
  
  
  
  
      '''simple docstring'''
      copy_linear(hf_mlp.fca       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.c_fc'''      )
      copy_linear(hf_mlp.fca       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.c_proj'''      )
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     Optional[Any]:
  
  
  
  
  
  
      '''simple docstring'''
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.weight'''].data
      __UpperCAmelCase									=			pt_weights[f'''{prefix}.bias'''].data
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     Union[str, Any]:
  
  
  
  
  
  
      '''simple docstring'''
      # copy layer norms
      copy_linear(hf_layer.layer_norma       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.ln_1'''      )
      copy_linear(hf_layer.layer_norma       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.ln_2'''      )
  
      # copy MLP
      copy_mlp(hf_layer.mlp       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.mlp'''      )
  
      # copy attn
      copy_attn_layer(hf_layer.self_attn       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.attn'''      )
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     Dict:
  
  
  
  
  
  
      '''simple docstring'''
      for layer_id, hf_layer in enumerate(SCREAMING_SNAKE_CASE      ):
          copy_layer(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   f'''{prefix}.{layer_id}'''      )
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     Union[str, Any]:
  
  
  
  
  
  
      '''simple docstring'''
      # copy projection
      __UpperCAmelCase									=			pt_weights["""text_projection"""].data.T
  
      # copy text encoder
      for name, param in hf_model.text_model.named_parameters():
          __UpperCAmelCase									=			pt_weights[f'''bert.{name}'''].data
  
  
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )      ->     Dict:
  
  
  
  
  
  
      '''simple docstring'''
      # copy projection
      __UpperCAmelCase									=			pt_weights["""visual.proj"""].data.T
  
      # copy layer norms
      copy_linear(hf_model.vision_model.pre_layrnorm       ,   SCREAMING_SNAKE_CASE       ,   '''visual.ln_pre'''      )
      copy_linear(hf_model.vision_model.post_layernorm       ,   SCREAMING_SNAKE_CASE       ,   '''visual.ln_post'''      )
  
      # copy embeddings
      __UpperCAmelCase									=			pt_weights["""visual.conv1.weight"""].data
      __UpperCAmelCase									=			pt_weights["""visual.class_embedding"""].data
      __UpperCAmelCase									=			pt_weights["""visual.positional_embedding"""].data
  
      # copy encoder
      copy_layers(hf_model.vision_model.encoder.layers       ,   SCREAMING_SNAKE_CASE       ,   '''visual.transformer.resblocks'''      )
  
  
  @torch.no_grad()
  def       __a       (   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE=None      )      ->     Optional[Any]:
  
  
  
  
  
  
      '''simple docstring'''
      assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
      __UpperCAmelCase									=			ChineseCLIPConfig.from_pretrained(SCREAMING_SNAKE_CASE      )
  
      __UpperCAmelCase									=			ChineseCLIPModel(SCREAMING_SNAKE_CASE      ).eval()
  
      __UpperCAmelCase									=			torch.load(SCREAMING_SNAKE_CASE       ,   map_location='''cpu'''      )["""state_dict"""]
      __UpperCAmelCase									=			{(name[7:] if name.startswith('''module.'''      ) else name): value for name, value in pt_weights.items()}
  
      copy_text_model_and_projection(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )
      copy_vision_model_and_projection(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )
      __UpperCAmelCase									=			pt_weights["""logit_scale"""].data
  
      hf_model.save_pretrained(SCREAMING_SNAKE_CASE      )
  
  
  if __name__ == "__main__":
         A_		:			Dict										=   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_		:			List[str]										=   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: 
  
  import numpy as np
  
  
  def       __a       (   SCREAMING_SNAKE_CASE      )      ->     Tuple:
  
  
  
  
  
  
      '''simple docstring'''
      __UpperCAmelCase					,     __UpperCAmelCase									=			a.shape
      __UpperCAmelCase									=			min(SCREAMING_SNAKE_CASE       ,   SCREAMING_SNAKE_CASE      )
      __UpperCAmelCase									=			np.eye(SCREAMING_SNAKE_CASE      )
      __UpperCAmelCase									=			a.copy()
  
      for k in range(t - 1      ):
          # select a column of modified matrix A':
          __UpperCAmelCase									=			r[k:, [k]]
          # construct first basis vector
          __UpperCAmelCase									=			np.zeros_like(SCREAMING_SNAKE_CASE      )
          __UpperCAmelCase									=			1.0
          # determine scaling factor
          __UpperCAmelCase									=			np.linalg.norm(SCREAMING_SNAKE_CASE      )
          # construct vector v for Householder reflection
          __UpperCAmelCase									=			x + np.sign(x[0]      ) * alpha * ea
          v /= np.linalg.norm(SCREAMING_SNAKE_CASE      )
  
          # construct the Householder matrix
          __UpperCAmelCase									=			np.eye(m - k      ) - 2.0 * v @ v.T
          # pad with ones and zeros as necessary
          __UpperCAmelCase									=			np.block([[np.eye(SCREAMING_SNAKE_CASE      ), np.zeros((k, m - k)      )], [np.zeros((m - k, k)      ), q_k]]      )
  
          __UpperCAmelCase									=			q @ q_k.T
          __UpperCAmelCase									=			q_k @ r
  
      return q, r
  
  
  if __name__ == "__main__":
         import doctest
  
         doctest.testmod()
  
  
  
  
  