


import argparse

import torch

from transformers import ChineseCLIPConfig, ChineseCLIPModel
def 	lowercase_							(A			:			List[str]		, A			:			List[Any]		, A			:			Tuple				):
       snake_case__							:     Union[str, Any]            =     pt_weights[F'''{prefix}.in_proj_weight'''].chunk(3		, dim=0				)
       snake_case__							:     Dict            =     pt_weights[F'''{prefix}.in_proj_bias'''].chunk(3		, dim=0				)

       snake_case__							:     str            =     pt_weights[F'''{prefix}.out_proj.weight''']
       snake_case__							:     List[Any]            =     pt_weights[F'''{prefix}.out_proj.bias''']

       snake_case__							:     Union[str, Any]            =     q_proj
       snake_case__							:     Optional[Any]            =     q_proj_bias

       snake_case__							:     Any            =     k_proj
       snake_case__							:     Union[str, Any]            =     k_proj_bias

       snake_case__							:     int            =     v_proj
       snake_case__							:     str            =     v_proj_bias

       snake_case__							:     Any            =     out_proj_weights
       snake_case__							:     Any            =     out_proj_bias
def 	lowercase_							(A			:			List[Any]		, A			:			str		, A			:			Dict				):
       copy_linear(hf_mlp.fca		, A		, F'''{prefix}.c_fc'''				)
       copy_linear(hf_mlp.fca		, A		, F'''{prefix}.c_proj'''				)
def 	lowercase_							(A			:			Optional[int]		, A			:			str		, A			:			List[Any]				):
       snake_case__							:     Any            =     pt_weights[F'''{prefix}.weight'''].data
       snake_case__							:     List[str]            =     pt_weights[F'''{prefix}.bias'''].data
def 	lowercase_							(A			:			List[Any]		, A			:			Union[str, Any]		, A			:			Any				):
       # copy layer norms
       copy_linear(hf_layer.layer_norma		, A		, F'''{prefix}.ln_1'''				)
       copy_linear(hf_layer.layer_norma		, A		, F'''{prefix}.ln_2'''				)

       # copy MLP
       copy_mlp(hf_layer.mlp		, A		, F'''{prefix}.mlp'''				)

       # copy attn
       copy_attn_layer(hf_layer.self_attn		, A		, F'''{prefix}.attn'''				)
def 	lowercase_							(A			:			int		, A			:			Dict		, A			:			Optional[int]				):
       for layer_id, hf_layer in enumerate(A				):
              copy_layer(A		, A		, F'''{prefix}.{layer_id}'''				)
def 	lowercase_							(A			:			int		, A			:			Dict				):
       # copy projection
       snake_case__							:     Optional[int]            =     pt_weights['text_projection'].data.T

       # copy text encoder
       for name, param in hf_model.text_model.named_parameters():
              snake_case__							:     Optional[int]            =     pt_weights[F'''bert.{name}'''].data
def 	lowercase_							(A			:			Any		, A			:			int				):
       # copy projection
       snake_case__							:     int            =     pt_weights['visual.proj'].data.T

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

       # copy embeddings
       snake_case__							:     Optional[Any]            =     pt_weights['visual.conv1.weight'].data
       snake_case__							:     List[str]            =     pt_weights['visual.class_embedding'].data
       snake_case__							:     List[str]            =     pt_weights['visual.positional_embedding'].data

       # copy encoder
       copy_layers(hf_model.vision_model.encoder.layers		, A		, 'visual.transformer.resblocks'				)
@torch.no_grad()
def 	lowercase_							(A			:			str		, A			:			int		, A			:			Optional[Any]=None				):
       assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
       snake_case__							:     Optional[Any]            =     ChineseCLIPConfig.from_pretrained(A				)

       snake_case__							:     Any            =     ChineseCLIPModel(A				).eval()

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

       copy_text_model_and_projection(A		, A				)
       copy_vision_model_and_projection(A		, A				)
       snake_case__							:     Tuple            =     pt_weights['logit_scale'].data

       hf_model.save_pretrained(A				)


if __name__ == "__main__":
 a_       :List[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_       :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!")











import math
def 	lowercase_							(A			:			int				):

       if 1 < number < 4:
              # 2 and 3 are primes
              return True
       elif number < 2 or number % 2 == 0 or number % 3 == 0:
              # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
              return False

       # All primes number are in format of 6k +/- 1
       for i in range(5		, int(math.sqrt(A				) + 1				)		, 6				):
              if number % i == 0 or number % (i + 2) == 0:
                     return False
       return True
def 	lowercase_							(A			:			int = 1_0_0_0		, A			:			int = 1_0_0_0				):
       snake_case__							:     str            =     [0, 0, 0]  # length, a, b
       for a in range((a_limit * -1) + 1		, A				):
              for b in range(2		, A				):
                     if is_prime(A				):
                            snake_case__							:     Optional[Any]            =     0
                            snake_case__							:     Optional[int]            =     0
                            while is_prime((n**2) + (a * n) + b				):
                                   count += 1
                                   n += 1
                            if count > longest[0]:
                                   snake_case__							:     Union[str, Any]            =     [count, a, b]
       snake_case__							:     List[str]            =     longest[1] * longest[2]
       return ans


if __name__ == "__main__":
 print(solution(1_000, 1_000))






