code: 
  
  """simple docstring"""
  import argparse
  
  import torch
  
  from transformers import ChineseCLIPConfig, ChineseCLIPModel
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase						)  ->   Tuple:
        UpperCAmelCase__ :       Union[str, Any]   				=						pt_weights[F"""{prefix}.in_proj_weight"""].chunk(3 ,  dim=0						)
        UpperCAmelCase__ :       Any   				=						pt_weights[F"""{prefix}.in_proj_bias"""].chunk(3 ,  dim=0						)
  
        UpperCAmelCase__ :       List[Any]   				=						pt_weights[F"""{prefix}.out_proj.weight"""]
        UpperCAmelCase__ :       str   				=						pt_weights[F"""{prefix}.out_proj.bias"""]
  
        UpperCAmelCase__ :       str   				=						q_proj
        UpperCAmelCase__ :       Optional[Any]   				=						q_proj_bias
  
        UpperCAmelCase__ :       List[Any]   				=						k_proj
        UpperCAmelCase__ :       str   				=						k_proj_bias
  
        UpperCAmelCase__ :       Tuple   				=						v_proj
        UpperCAmelCase__ :       List[Any]   				=						v_proj_bias
  
        UpperCAmelCase__ :       Dict   				=						out_proj_weights
        UpperCAmelCase__ :       Optional[int]   				=						out_proj_bias
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase						)  ->   str:
        copy_linear(hf_mlp.fca ,  lowercase__ ,  F"""{prefix}.c_fc"""						)
        copy_linear(hf_mlp.fca ,  lowercase__ ,  F"""{prefix}.c_proj"""						)
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase						)  ->   int:
        UpperCAmelCase__ :       List[Any]   				=						pt_weights[F"""{prefix}.weight"""].data
        UpperCAmelCase__ :       Optional[int]   				=						pt_weights[F"""{prefix}.bias"""].data
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase						)  ->   Dict:
        # copy layer norms
        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__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase						)  ->   Union[str, Any]:
        for layer_id, hf_layer in enumerate(lowercase__						):
              copy_layer(lowercase__ ,  lowercase__ ,  F"""{prefix}.{layer_id}"""						)
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase						)  ->   Any:
        # copy projection
        UpperCAmelCase__ :       List[Any]   				=						pt_weights["text_projection"].data.T
  
        # copy text encoder
        for name, param in hf_model.text_model.named_parameters():
              UpperCAmelCase__ :       List[str]   				=						pt_weights[F"""bert.{name}"""].data
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase						)  ->   str:
        # copy projection
        UpperCAmelCase__ :       Any   				=						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
        UpperCAmelCase__ :       Dict   				=						pt_weights["visual.conv1.weight"].data
        UpperCAmelCase__ :       Optional[int]   				=						pt_weights["visual.class_embedding"].data
        UpperCAmelCase__ :       Optional[Any]   				=						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__	(	lowerCAmelCase ,  lowerCAmelCase ,  lowerCAmelCase=None						)  ->   int:
        assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
        UpperCAmelCase__ :       Union[str, Any]   				=						ChineseCLIPConfig.from_pretrained(lowercase__						)
  
        UpperCAmelCase__ :       Any   				=						ChineseCLIPModel(lowercase__						).eval()
  
        UpperCAmelCase__ :       int   				=						torch.load(lowercase__ ,  map_location="""cpu"""						)["state_dict"]
        UpperCAmelCase__ :       Dict   				=						{(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__						)
        UpperCAmelCase__ :       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!""")
  
  
style_context: 
  
  """simple docstring"""
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase						)  ->   str:
        if not isinstance(lowerCAmelCase ,  lowerCAmelCase						):
              raise TypeError("""plaintext must be a string"""						)
        if not isinstance(lowerCAmelCase ,  lowerCAmelCase						):
              raise TypeError("""key must be a string"""						)
  
        if not plaintext:
              raise ValueError("""plaintext is empty"""						)
        if not key:
              raise ValueError("""key is empty"""						)
  
        key += plaintext
        UpperCAmelCase__ :       Dict						=						plaintext.lower()
        UpperCAmelCase__ :       Tuple						=						key.lower()
        UpperCAmelCase__ :       Optional[int]						=						0
        UpperCAmelCase__ :       Tuple						=						0
        UpperCAmelCase__ :       Optional[int]						=						""""""
        while plaintext_iterator < len(lowerCAmelCase						):
              if (
                  ord(plaintext[plaintext_iterator]						) < 97
                  or ord(plaintext[plaintext_iterator]						) > 1_22
              ):
                    ciphertext += plaintext[plaintext_iterator]
                    plaintext_iterator += 1
              elif ord(key[key_iterator]						) < 97 or ord(key[key_iterator]						) > 1_22:
                    key_iterator += 1
              else:
                    ciphertext += chr(
                        (
                            (ord(plaintext[plaintext_iterator]						) - 97 + ord(key[key_iterator]						))
                            - 97
                        )
                        % 26
                        + 97						)
                    key_iterator += 1
                    plaintext_iterator += 1
        return ciphertext
  
  
  
  
  def 				a__	(	lowerCAmelCase ,  lowerCAmelCase						)  ->   str:
        if not isinstance(lowerCAmelCase ,  lowerCAmelCase						):
              raise TypeError("""ciphertext must be a string"""						)
        if not isinstance(lowerCAmelCase ,  lowerCAmelCase						):
              raise TypeError("""key must be a string"""						)
  
        if not ciphertext:
              raise ValueError("""ciphertext is empty"""						)
        if not key:
              raise ValueError("""key is empty"""						)
  
        UpperCAmelCase__ :       Union[str, Any]						=						key.lower()
        UpperCAmelCase__ :       int						=						0
        UpperCAmelCase__ :       int						=						0
        UpperCAmelCase__ :       int						=						""""""
        while ciphertext_iterator < len(lowerCAmelCase						):
              if (
                  ord(ciphertext[ciphertext_iterator]						) < 97
                  or ord(ciphertext[ciphertext_iterator]						) > 1_22
              ):
                    plaintext += ciphertext[ciphertext_iterator]
              else:
                    plaintext += chr(
                        (ord(ciphertext[ciphertext_iterator]						) - ord(key[key_iterator]						)) % 26
                        + 97						)
                    key += chr(
                        (ord(ciphertext[ciphertext_iterator]						) - ord(key[key_iterator]						)) % 26
                        + 97						)
                    key_iterator += 1
              ciphertext_iterator += 1
        return plaintext
  
  
  if __name__ == "__main__":
      import doctest
  
      doctest.testmod()
      _A						=     int(input("""Type 1 to encrypt or 2 to decrypt:"""))
      if operation == 1:
          _A						=     input("""Typeplaintext to be encrypted:\n""")
          _A						=     input("""Type the key:\n""")
          print(encrypt(plaintext, key))
      elif operation == 2:
          _A						=     input("""Type the ciphertext to be decrypted:\n""")
          _A						=     input("""Type the key:\n""")
          print(decrypt(ciphertext, key))
      decrypt("""jsqqs avvwo""", """coffee""")
  
  