From eed8ebd785b7588097b7bfe62b3c1b12939b58ef Mon Sep 17 00:00:00 2001 From: shikang Date: Wed, 7 Aug 2024 10:20:25 +0000 Subject: [PATCH 1/4] add text --- .../foundation_models/Chinese_CLIP/README.md | 76 +- .../Chinese_CLIP/opt_txt_onnx.py | 39 +- .../Chinese_CLIP/patch.patch | 1077 +++++++++++++++++ 3 files changed, 1137 insertions(+), 55 deletions(-) create mode 100644 ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md index 44706889ce..94a3ff5f69 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md @@ -41,7 +41,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 | 输入数据 | 大小 | 数据类型 | 数据排布格式 | |----------|------------------| ------------------------- | ------------ | | image | ${bs} x 3 x 224 x 224 | FLOAT32 | NCHW | - + | txt | ${bs} x 512 | INT32 | NCHW | - 输出数据 @@ -57,8 +57,8 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 | 配套 | 版本 | 环境准备指导 | | ------------------------------------------------------------ |---------| ------------------------------------------------------------ | -| 固件与驱动 | 24.0.RC2 | [Pytorch框架推理环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/pies) | -| CANN(+ MindIE) | 8.0.RC2 | - | +| 固件与驱动 | 24.1.RC2 | [Pytorch框架推理环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/pies) | +| CANN(+ MindIE) | 8.0.RC3 | - | | Python | 3.8.17 | - | | PyTorch | 1.11.0 | - | | 说明:Atlas 300I Duo 推理卡请以CANN版本选择实际固件与驱动版本。 | \ | \ | @@ -122,6 +122,13 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 下载[权重文件](https://clip-cn-beijing.oss-cn-beijing.aliyuncs.com/checkpoints/clip_cn_vit-b-16.pt) clip_cn_vit-b-16.pt 置于 models 目录下 + 2. 获取数据集。 + 下载[cifar-100数据集](http://clip-cn-beijing.oss-cn-beijing.aliyuncs.com/datasets/cifar-100.zip) + ``` + mkdir -p ./Chinese-CLIP/data/dataset + ``` + 在dataset文件夹中解压缩 + 2. 导出onnx文件。 1. 使用 Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 导出onnx文件。 @@ -152,15 +159,15 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 1. 文本模型 ```shell - # export bs=20 - onnxsim models/vit-b-16.txt.fp16.onnx models/vit-b-16.txt.fp16.bs${bs}.sim.onnx --overwrite-input-shape "text:${bs},512" + # export bs=24 + onnxsim models/vit-b-16.txt.fp32.onnx models/vit-b-16.txt.fp32.bs${bs}.sim.onnx --overwrite-input-shape "text:${bs},512" ``` 2. 图像模型 ```shell - # export bs=20 - onnxsim models/vit-b-16.img.fp16.onnx models/vit-b-16.img.fp16.bs${bs}.sim.onnx --overwrite-input-shape "image:${bs},3,224,224" + # export bs=24 + onnxsim models/vit-b-16.img.fp32.onnx models/vit-b-16.img.fp32.bs${bs}.sim.onnx --overwrite-input-shape "image:${bs},3,224,224" ``` 4. 使用 opt_onnx.py 优化 onnx 模型。 @@ -169,17 +176,17 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 1. 文本模型 ```shell - # export bs=20 - python3 opt_txt_onnx.py models/vit-b-16.txt.fp16.bs${bs}.sim.onnx models/vit-b-16.txt.fp16.bs${bs}.opt.onnx + # export bs=24 + python3 opt_txt_onnx.py models/vit-b-16.txt.fp32.bs${bs}.sim.onnx models/vit-b-16.txt.fp32.bs${bs}.opt.onnx ``` 2. 图像模型 - + ```shell - # export bs=20 + # export bs=24 python3 opt_img_onnx.py \ - --input_file models/vit-b-16.img.fp16.bs${bs}.sim.onnx \ - --output_file models/vit-b-16.img.fp16.bs${bs}.opt.onnx \ + --input_file models/vit-b-16.img.fp32.bs${bs}.sim.onnx \ + --output_file models/vit-b-16.img.fp32.bs${bs}.opt.onnx \ --model_config vit_base_patch16_224 \ --use_flashattention ``` @@ -219,10 +226,10 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 3. 执行ATC命令。 ```shell - # 例如 export bs=20 && export chip_name=310P3 + # 例如 export bs=24 && export chip_name=310P3 atc --framework=5 \ - --model=models/vit-b-16.txt.fp16.bs${bs}.opt.onnx \ - --output=models/vit-b-16.txt.fp16.bs${bs} \ + --model=models/vit-b-16.txt.fp32.bs${bs}.opt.onnx \ + --output=models/vit-b-16.txt.bs${bs} \ --input_format=ND \ --input_shape="text:${bs},512" \ --soc_version=Ascend${chip_name} \ @@ -230,17 +237,16 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 --optypelist_for_implmode="Gelu" \ --op_select_implmode=high_performance - # 例如 export bs=20 && export chip_name=310P3 + # 例如 export bs=24 && export chip_name=310P3 atc --framework=5 \ - --model=models/vit-b-16.img.fp16.bs${bs}.opt.onnx \ - --output=models/vit-b-16.img.fp16.bs${bs} \ + --model=models/vit-b-16.img.fp32.bs${bs}.opt.onnx \ + --output=models/vit-b-16.img.bs${bs} \ --input_format=NCHW \ --input_shape="image:${bs},3,224,224" \ --soc_version=Ascend${chip_name} \ --log=error \ --optypelist_for_implmode="Sigmoid" \ --op_select_implmode=high_performance \ - --insert_op_conf aipp.config \ --enable_small_channel 1 ``` - 参数说明: @@ -253,10 +259,9 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 - --soc_version:处理器型号。 - --optypelist_for_implmode:指定算子。 - --op_select_implmode:选择高性能/高精度模式,与 --optypelist_for_implmode 配合使用。 - - --insert_op_conf:AIPP配置文件。 - --enable_small_channel:与 --insert_op_conf 配合使用。 - 运行成功后,在 models 目录下生成 vit-b-16.img.fp16.${bs}.om 离线模型文件。 + 运行成功后,在 models 目录下生成 vit-b-16.img.bs${bs}.om 和 vit-b-16.txt.bs${bs}.om 离线模型文件。 6. 开始推理验证。 @@ -264,29 +269,28 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 请访问[ais_bench推理工具](https://gitee.com/ascend/tools/tree/master/ais-bench_workload/tool/ais_bench)代码仓,根据readme文档进行工具安装。 - 2. 余弦相似度精度验证。 + 2. 数据集精度验证 ``` - python3 compare.py --img-model-path models/vit-b-16.img.fp16.bs${bs}.om --batch-size ${bs} + cd Chinese-CLIP + export vision_om = ${vit-b-16.img.bs24.om模型的绝对路径} + export text_om = ${vit-b-16.txt.bs24.om模型的绝对路径} + bash run_scripts/zeroshot_eval.sh 0 data cifar-100 ViT-B-16 RoBERTa-wwm-ext-base-chinese ../models/clip_cn_vit-b-16.pt ${text_om} ${vision_om} ``` + 得到数据集精度 top1: 63.91% - - 参数说明: - - - --img-model-path:图像侧模型所在路径 - - --batch-size:批次大小 - - 运行成功后打印om推理结果与cpu推理结果的余弦相似度,确保精度正常。 + 4. 性能验证。 纯推理性能测试命令如下: ```shell - # export bs=20 - python3 -m ais_bench --model models/vit-b-16.txt.fp16.bs${bs}.om --loop 50 + # export bs=24 + python3 -m ais_bench --model models/vit-b-16.txt.bs${bs}.om --loop 50 - # export bs=20 - python3 -m ais_bench --model models/vit-b-16.img.fp16.bs${bs}.om --loop 50 + # export bs=24 + python3 -m ais_bench --model models/vit-b-16.img.bs${bs}.om --loop 50 ``` @@ -298,10 +302,10 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 | 芯片型号 | Input Shape | 单次推理耗时 | | -------- | ----------- | ------------ | -| 300I Pro | 20 x 512 | 91.6ms | +| 300I Pro | 24 x 512 | 105ms | - 图像侧模型: | 芯片型号 | Batch Size | 单次推理耗时 | |----------|------------|----------| -| 300I Pro | 20 | 35ms | +| 300I Pro | 24 | 39ms | diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py index 2653333a6d..4ec2ea7a5a 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py @@ -27,20 +27,6 @@ def get_config(graph): def fix_attention_lnqkv(graph, qkv_start_node): - # insert reshape before qkv_start_node - reshape_before_add = graph.add_node( - f"Reshape_before_{qkv_start_node.name}", - "Reshape" - ) - reshape_init = graph.add_initializer( - f"{reshape_before_add.name}_value", - np.array([-1, HIDDEN_NUM], dtype="int64") - ) - if graph.get_node(qkv_start_node.inputs[0], node_type=Initializer): - graph.insert_node(qkv_start_node.name, reshape_before_add, refer_index=1, mode="before") - else: - graph.insert_node(qkv_start_node.name, reshape_before_add, refer_index=0, mode="before") - reshape_before_add.inputs.append(reshape_init.name) # change transpose node seen: List[List[int]] = [] @@ -96,7 +82,7 @@ def fix_attention_score(graph, softmax_node, bs, seq_len): f"bert_Mul_before_{add_node.name}", "Mul", ) - mul_init_value = np.array(1/div_init.value, dtype="float16") + mul_init_value = np.array(1/div_init.value, dtype="float32") mul_init = graph.add_initializer( f"{mul_node.name}_value", mul_init_value @@ -123,6 +109,24 @@ def main(graph): # fix_lnqkv add_nodes = graph.get_nodes("Add") + gather_node = graph.get_nodes("Gather")[0] + + # insert reshape before qkv_start_node + reshape_before_add = graph.add_node( + f"Reshape_2dims", + "Reshape" + ) + reshape_init = graph.add_initializer( + "Reshape_2dims_value", + np.array([-1, HIDDEN_NUM], dtype="int64") + ) + graph.insert_node(gather_node.name, reshape_before_add, mode="after") + + reshape_before_add.inputs.append(reshape_init.name) + + for add_node in add_nodes[:2]: + graph[add_node.inputs[1]].value = graph[add_node.inputs[1]].value.reshape(-1, HIDDEN_NUM) + for add_node in add_nodes: if len(graph.get_next_nodes(add_node.outputs[0])) == 4: fix_attention_lnqkv(graph, add_node) @@ -142,10 +146,7 @@ def main(graph): f"{last_reshape.name}_value", np.array([bs, seq_len, HIDDEN_NUM], dtype="int64") ) - if graph.get_node(last_add.inputs[0], node_type=Initializer): - graph.insert_node(last_add.name, last_reshape, refer_index=1, mode="before") - else: - graph.insert_node(last_add.name, last_reshape, refer_index=0, mode="before") + graph.insert_node(last_add.name, last_reshape, mode="after") last_reshape.inputs.append(reshape_init.name) diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch new file mode 100644 index 0000000000..2cc6b40803 --- /dev/null +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch @@ -0,0 +1,1077 @@ +diff -Nur b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py +--- b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 10:13:21.636000000 +0000 ++++ a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 01:17:34.820000000 +0000 +@@ -117,8 +117,9 @@ + text_fp32_onnx_path, + input_names=['text'], + output_names=['unnorm_text_features'], ++ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, + export_params=True, +- opset_version=13, ++ opset_version=11, + verbose=True) + # convert text FP16 ONNX model based on the FP32 model + text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" +@@ -141,9 +142,10 @@ + vision_fp32_onnx_path, + input_names=['image'], + output_names=['unnorm_image_features'], ++ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, + export_params=True, + do_constant_folding=False, +- opset_version=13, ++ opset_version=11, + verbose=True) + # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files + if args.model_arch == "ViT-H-14": +diff -Nur b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py +--- b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:13:21.636000000 +0000 ++++ a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:07:28.980000000 +0000 +@@ -10,7 +10,7 @@ + from tqdm import tqdm + + import torch +- ++from ais_bench.infer.interface import InferSession + from cn_clip.clip.model import convert_weights, CLIP + from cn_clip.clip import tokenize + from cn_clip.training.main import convert_models_to_fp32 +@@ -29,6 +29,16 @@ + def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument( ++ "--text-om", ++ default="vit-b-text.om", ++ help="Name of the text om model to use.", ++ ) ++ parser.add_argument( ++ "--vision-om", ++ default="vit-b-image.om", ++ help="Name of the vision om model to use.", ++ ) ++ parser.add_argument( + "--vision-model", + choices=["ViT-B-32", "ViT-B-16", "ViT-L-14", "ViT-L-14-336", "ViT-H-14", "RN50"], + default="ViT-B-16", +@@ -82,12 +92,12 @@ + # help="Path to imagenet val set for conducting zero shot evaluation.", + # ) + parser.add_argument( +- "--img-batch-size", type=int, default=64, help="Image batch size." ++ "--img-batch-size", type=int, default=24, help="Image batch size." + ) + parser.add_argument( + "--context-length", + type=int, +- default=52, ++ default=512, + help="The maximum length of input text (include [CLS] & [SEP] tokens)." + ) + parser.add_argument( +@@ -106,16 +116,24 @@ + + def zero_shot_classifier(model, classnames, templates, args): + with torch.no_grad(): ++ session_code = InferSession(0, model) + zeroshot_weights = [] + for classname in tqdm(classnames): + texts = [_preprocess_text(template(classname)) for template in templates] # format with class +- texts = tokenize(texts, context_length=args.context_length).to(args.gpu) # tokenize +- class_embeddings = model(None, texts) ++ texts = tokenize(texts, context_length=args.context_length) ++ x = torch.zeros(9,512) ++ texts = torch.concat((texts,x),dim=0) ++ res_class = [] ++ for i in range(8): ++ feed = [texts[i*24:(i+1)*24,].to(torch.int64)] ++ class_embeddings = session_code.infer(feed) ++ res_class.append(torch.from_numpy(class_embeddings[0])) ++ class_embeddings = torch.concat(res_class, dim=0)[:183,] + class_embeddings /= class_embeddings.norm(dim=-1, keepdim=True) + class_embedding = class_embeddings.mean(dim=0) + class_embedding /= class_embedding.norm() + zeroshot_weights.append(class_embedding) +- zeroshot_weights = torch.stack(zeroshot_weights, dim=1).to(args.gpu) ++ zeroshot_weights = torch.stack(zeroshot_weights, dim=1) + return zeroshot_weights + + +@@ -128,27 +146,31 @@ + def run(model, classifier, dataloader, args): + total_logits = [] + total_targets = [] +- with torch.no_grad(): +- top1, top5, n = 0.0, 0.0, 0.0 +- for images, target in tqdm(dataloader): +- images = images.to(args.gpu) +- target = target.to(args.gpu) +- total_targets.append(target) +- +- # predict +- image_features = model(images, None) +- image_features /= image_features.norm(dim=-1, keepdim=True) +- logits = (100.0 * image_features @ classifier).softmax(dim=-1) +- total_logits.append(logits) +- +- # measure accuracy +- acc1, acc5 = accuracy(logits, target, topk=(1, 1)) +- top1 += acc1 +- n += images.size(0) ++ session_code = InferSession(0, model) ++ # with torch.no_grad(): ++ top1, top5, n = 0.0, 0.0, 0.0 ++ for images, target in tqdm(dataloader): ++ images = images ++ target = target ++ total_targets.append(target) ++ batch = images.size(0) ++ if batch != 24: ++ pad = torch.zeros_like(images[:(24-batch)]) ++ images = torch.concat((images,pad), dim=0) ++ feed = [images.to(torch.float32)] ++ image_features = session_code.infer(feed) ++ image_features = torch.from_numpy(image_features[0][:batch,]) ++ image_features /= image_features.norm(dim=-1, keepdim=True) ++ logits = (100.0 * image_features @ classifier).softmax(dim=-1) ++ total_logits.append(logits) ++ ++ # measure accuracy ++ acc1, acc5 = accuracy(logits, target, topk=(1, 1)) ++ top1 += acc1 ++ n += batch + + outputs = torch.cat(total_logits, dim=0) + targets = torch.cat(total_targets, dim=0) +- + if getattr(args, "index", ""): + print("Use index to rearrange the logits...") + with open(args.index, "r", encoding="utf-8") as f: +@@ -166,16 +188,14 @@ + if __name__ == "__main__": + args = parse_args() + ++ text_model = args.text_om ++ vision_model = args.vision_om + # Log params. + print("Params:") + for name in sorted(vars(args)): + val = getattr(args, name) + print(f" {name}: {val}") + +- args.gpu = 0 +- torch.cuda.set_device(args.gpu) +- +- # Initialize the model. + vision_model_config_file = Path(__file__).parent.parent / f"clip/model_configs/{args.vision_model.replace('/', '-')}.json" + print('Loading vision model config from', vision_model_config_file) + assert os.path.exists(vision_model_config_file) +@@ -191,17 +211,6 @@ + for k, v in json.load(ft).items(): + model_info[k] = v + +- model = CLIP(**model_info) +- convert_weights(model) +- +- # See https://discuss.pytorch.org/t/valueerror-attemting-to-unscale-fp16-gradients/81372 +- if args.precision == "amp" or args.precision == "fp32": +- convert_models_to_fp32(model) +- model.cuda(args.gpu) +- if args.precision == "fp16": +- convert_weights(model) +- +- # Get eval data. + print("Preparing zeroshot dataset.") + data = {} + print(f"{model_info['image_resolution']}") +@@ -209,26 +218,8 @@ + args, image_transform(model_info["image_resolution"]) + ) + +- # Resume from a checkpoint. +- print("Begin to load model checkpoint from {}.".format(args.resume)) +- assert os.path.exists(args.resume), "The checkpoint file {} not exists!".format(args.resume) +- # Map model to be loaded to specified single gpu. +- loc = "cuda:{}".format(args.gpu) +- checkpoint = torch.load(args.resume, map_location='cpu') +- start_epoch = checkpoint["epoch"] +- sd = checkpoint["state_dict"] +- if next(iter(sd.items()))[0].startswith('module'): +- sd = {k[len('module.'):]: v for k, v in sd.items() if "bert.pooler" not in k} +- model.load_state_dict(sd) +- print( +- f"=> loaded checkpoint '{args.resume}' (epoch {checkpoint['epoch']} @ {checkpoint['step']} steps)" +- ) +- +- # Compute ensembled class embeddings + print('Building zero-shot classifier') + +- model.eval() +- + f = open(args.label_file, "r", encoding="utf8") + classnames = [line.strip() for line in f.readlines()] + +@@ -246,32 +237,10 @@ + else: + templates = template_dict['openai'] + +- # Make inference and evaluation + print('Using classifier') +- classifier = zero_shot_classifier(model, classnames, templates, args) ++ classifier = zero_shot_classifier(text_model, classnames, templates, args) + results = {} +- top1, logits = run(model, classifier, data[args.dataset].dataloader, args) +- +- def json_prec_dump(data, prec=6): +- return json.dumps( +- json.loads(json.dumps(data), parse_float=lambda x: round(float(x), prec)) +- ) +- +- print(logits.size()) +- output_dict = { +- "model_name": "CN-CLIP-" + args.vision_model, +- "dataset_name": args.dataset, +- "num_trainable_params": 0, +- "num_params": sum(x.numel() for x in model.parameters()), +- "num_visual_params": sum(x.numel() for x in model.visual.parameters()), +- "num_backbone_params": sum(x.numel() for x in model.parameters()), +- "n_shot": 0, +- "rnd_seeds": [123], +- "predictions": [logits.cpu().data.numpy().tolist()], +- } +- json_string = json_prec_dump(output_dict) +- with open(os.path.join(args.save_dir, f"{args.dataset}.json"), "w", encoding="utf-8") as w: +- w.write(json_string) ++ top1, logits = run(vision_model, classifier, data[args.dataset].dataloader, args) + + results["zeroshot-top1"] = top1 + +diff -Nur b/Chinese-CLIP/.git/config a/Chinese-CLIP/.git/config +--- b/Chinese-CLIP/.git/config 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/config 1970-01-01 00:00:00.000000000 +0000 +@@ -1,11 +0,0 @@ +-[core] +- repositoryformatversion = 0 +- filemode = true +- bare = false +- logallrefupdates = true +-[remote "origin"] +- url = https://github.com/OFA-Sys/Chinese-CLIP.git +- fetch = +refs/heads/*:refs/remotes/origin/* +-[branch "master"] +- remote = origin +- merge = refs/heads/master +diff -Nur b/Chinese-CLIP/.git/description a/Chinese-CLIP/.git/description +--- b/Chinese-CLIP/.git/description 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/description 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-Unnamed repository; edit this file 'description' to name the repository. +diff -Nur b/Chinese-CLIP/.git/HEAD a/Chinese-CLIP/.git/HEAD +--- b/Chinese-CLIP/.git/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-ref: refs/heads/master +diff -Nur b/Chinese-CLIP/.git/hooks/applypatch-msg.sample a/Chinese-CLIP/.git/hooks/applypatch-msg.sample +--- b/Chinese-CLIP/.git/hooks/applypatch-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/applypatch-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,15 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to check the commit log message taken by +-# applypatch from an e-mail message. +-# +-# The hook should exit with non-zero status after issuing an +-# appropriate message if it wants to stop the commit. The hook is +-# allowed to edit the commit message file. +-# +-# To enable this hook, rename this file to "applypatch-msg". +- +-. git-sh-setup +-commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +-test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +-: +diff -Nur b/Chinese-CLIP/.git/hooks/commit-msg.sample a/Chinese-CLIP/.git/hooks/commit-msg.sample +--- b/Chinese-CLIP/.git/hooks/commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,24 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to check the commit log message. +-# Called by "git commit" with one argument, the name of the file +-# that has the commit message. The hook should exit with non-zero +-# status after issuing an appropriate message if it wants to stop the +-# commit. The hook is allowed to edit the commit message file. +-# +-# To enable this hook, rename this file to "commit-msg". +- +-# Uncomment the below to add a Signed-off-by line to the message. +-# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +-# hook is more suited to it. +-# +-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +-# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" +- +-# This example catches duplicate Signed-off-by lines. +- +-test "" = "$(grep '^Signed-off-by: ' "$1" | +- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { +- echo >&2 Duplicate Signed-off-by lines. +- exit 1 +-} +diff -Nur b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample +--- b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,109 +0,0 @@ +-#!/usr/bin/perl +- +-use strict; +-use warnings; +-use IPC::Open2; +- +-# An example hook script to integrate Watchman +-# (https://facebook.github.io/watchman/) with git to speed up detecting +-# new and modified files. +-# +-# The hook is passed a version (currently 1) and a time in nanoseconds +-# formatted as a string and outputs to stdout all files that have been +-# modified since the given time. Paths must be relative to the root of +-# the working tree and separated by a single NUL. +-# +-# To enable this hook, rename this file to "query-watchman" and set +-# 'git config core.fsmonitor .git/hooks/query-watchman' +-# +-my ($version, $time) = @ARGV; +- +-# Check the hook interface version +- +-if ($version == 1) { +- # convert nanoseconds to seconds +- # subtract one second to make sure watchman will return all changes +- $time = int ($time / 1000000000) - 1; +-} else { +- die "Unsupported query-fsmonitor hook version '$version'.\n" . +- "Falling back to scanning...\n"; +-} +- +-my $git_work_tree; +-if ($^O =~ 'msys' || $^O =~ 'cygwin') { +- $git_work_tree = Win32::GetCwd(); +- $git_work_tree =~ tr/\\/\//; +-} else { +- require Cwd; +- $git_work_tree = Cwd::cwd(); +-} +- +-my $retry = 1; +- +-launch_watchman(); +- +-sub launch_watchman { +- +- my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') +- or die "open2() failed: $!\n" . +- "Falling back to scanning...\n"; +- +- # In the query expression below we're asking for names of files that +- # changed since $time but were not transient (ie created after +- # $time but no longer exist). +- # +- # To accomplish this, we're using the "since" generator to use the +- # recency index to select candidate nodes and "fields" to limit the +- # output to file names only. +- +- my $query = <<" END"; +- ["query", "$git_work_tree", { +- "since": $time, +- "fields": ["name"] +- }] +- END +- +- print CHLD_IN $query; +- close CHLD_IN; +- my $response = do {local $/; }; +- +- die "Watchman: command returned no output.\n" . +- "Falling back to scanning...\n" if $response eq ""; +- die "Watchman: command returned invalid output: $response\n" . +- "Falling back to scanning...\n" unless $response =~ /^\{/; +- +- my $json_pkg; +- eval { +- require JSON::XS; +- $json_pkg = "JSON::XS"; +- 1; +- } or do { +- require JSON::PP; +- $json_pkg = "JSON::PP"; +- }; +- +- my $o = $json_pkg->new->utf8->decode($response); +- +- if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { +- print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; +- $retry--; +- qx/watchman watch "$git_work_tree"/; +- die "Failed to make watchman watch '$git_work_tree'.\n" . +- "Falling back to scanning...\n" if $? != 0; +- +- # Watchman will always return all files on the first query so +- # return the fast "everything is dirty" flag to git and do the +- # Watchman query just to get it over with now so we won't pay +- # the cost in git to look up each individual file. +- print "/\0"; +- eval { launch_watchman() }; +- exit 0; +- } +- +- die "Watchman: $o->{error}.\n" . +- "Falling back to scanning...\n" if $o->{error}; +- +- binmode STDOUT, ":utf8"; +- local $, = "\0"; +- print @{$o->{files}}; +-} +diff -Nur b/Chinese-CLIP/.git/hooks/post-update.sample a/Chinese-CLIP/.git/hooks/post-update.sample +--- b/Chinese-CLIP/.git/hooks/post-update.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/post-update.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,8 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to prepare a packed repository for use over +-# dumb transports. +-# +-# To enable this hook, rename this file to "post-update". +- +-exec git update-server-info +diff -Nur b/Chinese-CLIP/.git/hooks/pre-applypatch.sample a/Chinese-CLIP/.git/hooks/pre-applypatch.sample +--- b/Chinese-CLIP/.git/hooks/pre-applypatch.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-applypatch.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,14 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed +-# by applypatch from an e-mail message. +-# +-# The hook should exit with non-zero status after issuing an +-# appropriate message if it wants to stop the commit. +-# +-# To enable this hook, rename this file to "pre-applypatch". +- +-. git-sh-setup +-precommit="$(git rev-parse --git-path hooks/pre-commit)" +-test -x "$precommit" && exec "$precommit" ${1+"$@"} +-: +diff -Nur b/Chinese-CLIP/.git/hooks/pre-commit.sample a/Chinese-CLIP/.git/hooks/pre-commit.sample +--- b/Chinese-CLIP/.git/hooks/pre-commit.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,49 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed. +-# Called by "git commit" with no arguments. The hook should +-# exit with non-zero status after issuing an appropriate message if +-# it wants to stop the commit. +-# +-# To enable this hook, rename this file to "pre-commit". +- +-if git rev-parse --verify HEAD >/dev/null 2>&1 +-then +- against=HEAD +-else +- # Initial commit: diff against an empty tree object +- against=$(git hash-object -t tree /dev/null) +-fi +- +-# If you want to allow non-ASCII filenames set this variable to true. +-allownonascii=$(git config --bool hooks.allownonascii) +- +-# Redirect output to stderr. +-exec 1>&2 +- +-# Cross platform projects tend to avoid non-ASCII filenames; prevent +-# them from being added to the repository. We exploit the fact that the +-# printable range starts at the space character and ends with tilde. +-if [ "$allownonascii" != "true" ] && +- # Note that the use of brackets around a tr range is ok here, (it's +- # even required, for portability to Solaris 10's /usr/bin/tr), since +- # the square bracket bytes happen to fall in the designated range. +- test $(git diff --cached --name-only --diff-filter=A -z $against | +- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +-then +- cat <<\EOF +-Error: Attempt to add a non-ASCII file name. +- +-This can cause problems if you want to work with people on other platforms. +- +-To be portable it is advisable to rename the file. +- +-If you know what you are doing you can disable this check using: +- +- git config hooks.allownonascii true +-EOF +- exit 1 +-fi +- +-# If there are whitespace errors, print the offending file names and fail. +-exec git diff-index --check --cached $against -- +diff -Nur b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample +--- b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,13 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed. +-# Called by "git merge" with no arguments. The hook should +-# exit with non-zero status after issuing an appropriate message to +-# stderr if it wants to stop the merge commit. +-# +-# To enable this hook, rename this file to "pre-merge-commit". +- +-. git-sh-setup +-test -x "$GIT_DIR/hooks/pre-commit" && +- exec "$GIT_DIR/hooks/pre-commit" +-: +diff -Nur b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample +--- b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,42 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to prepare the commit log message. +-# Called by "git commit" with the name of the file that has the +-# commit message, followed by the description of the commit +-# message's source. The hook's purpose is to edit the commit +-# message file. If the hook fails with a non-zero status, +-# the commit is aborted. +-# +-# To enable this hook, rename this file to "prepare-commit-msg". +- +-# This hook includes three examples. The first one removes the +-# "# Please enter the commit message..." help message. +-# +-# The second includes the output of "git diff --name-status -r" +-# into the message, just before the "git status" output. It is +-# commented because it doesn't cope with --amend or with squashed +-# commits. +-# +-# The third example adds a Signed-off-by line to the message, that can +-# still be edited. This is rarely a good idea. +- +-COMMIT_MSG_FILE=$1 +-COMMIT_SOURCE=$2 +-SHA1=$3 +- +-/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" +- +-# case "$COMMIT_SOURCE,$SHA1" in +-# ,|template,) +-# /usr/bin/perl -i.bak -pe ' +-# print "\n" . `git diff --cached --name-status -r` +-# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +-# *) ;; +-# esac +- +-# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +-# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +-# if test -z "$COMMIT_SOURCE" +-# then +-# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +-# fi +diff -Nur b/Chinese-CLIP/.git/hooks/pre-push.sample a/Chinese-CLIP/.git/hooks/pre-push.sample +--- b/Chinese-CLIP/.git/hooks/pre-push.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-push.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,53 +0,0 @@ +-#!/bin/sh +- +-# An example hook script to verify what is about to be pushed. Called by "git +-# push" after it has checked the remote status, but before anything has been +-# pushed. If this script exits with a non-zero status nothing will be pushed. +-# +-# This hook is called with the following parameters: +-# +-# $1 -- Name of the remote to which the push is being done +-# $2 -- URL to which the push is being done +-# +-# If pushing without using a named remote those arguments will be equal. +-# +-# Information about the commits which are being pushed is supplied as lines to +-# the standard input in the form: +-# +-# +-# +-# This sample shows how to prevent push of commits where the log message starts +-# with "WIP" (work in progress). +- +-remote="$1" +-url="$2" +- +-z40=0000000000000000000000000000000000000000 +- +-while read local_ref local_sha remote_ref remote_sha +-do +- if [ "$local_sha" = $z40 ] +- then +- # Handle delete +- : +- else +- if [ "$remote_sha" = $z40 ] +- then +- # New branch, examine all commits +- range="$local_sha" +- else +- # Update to existing branch, examine new commits +- range="$remote_sha..$local_sha" +- fi +- +- # Check for WIP commit +- commit=`git rev-list -n 1 --grep '^WIP' "$range"` +- if [ -n "$commit" ] +- then +- echo >&2 "Found WIP commit in $local_ref, not pushing" +- exit 1 +- fi +- fi +-done +- +-exit 0 +diff -Nur b/Chinese-CLIP/.git/hooks/pre-rebase.sample a/Chinese-CLIP/.git/hooks/pre-rebase.sample +--- b/Chinese-CLIP/.git/hooks/pre-rebase.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-rebase.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,169 +0,0 @@ +-#!/bin/sh +-# +-# Copyright (c) 2006, 2008 Junio C Hamano +-# +-# The "pre-rebase" hook is run just before "git rebase" starts doing +-# its job, and can prevent the command from running by exiting with +-# non-zero status. +-# +-# The hook is called with the following parameters: +-# +-# $1 -- the upstream the series was forked from. +-# $2 -- the branch being rebased (or empty when rebasing the current branch). +-# +-# This sample shows how to prevent topic branches that are already +-# merged to 'next' branch from getting rebased, because allowing it +-# would result in rebasing already published history. +- +-publish=next +-basebranch="$1" +-if test "$#" = 2 +-then +- topic="refs/heads/$2" +-else +- topic=`git symbolic-ref HEAD` || +- exit 0 ;# we do not interrupt rebasing detached HEAD +-fi +- +-case "$topic" in +-refs/heads/??/*) +- ;; +-*) +- exit 0 ;# we do not interrupt others. +- ;; +-esac +- +-# Now we are dealing with a topic branch being rebased +-# on top of master. Is it OK to rebase it? +- +-# Does the topic really exist? +-git show-ref -q "$topic" || { +- echo >&2 "No such branch $topic" +- exit 1 +-} +- +-# Is topic fully merged to master? +-not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +-if test -z "$not_in_master" +-then +- echo >&2 "$topic is fully merged to master; better remove it." +- exit 1 ;# we could allow it, but there is no point. +-fi +- +-# Is topic ever merged to next? If so you should not be rebasing it. +-only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +-only_next_2=`git rev-list ^master ${publish} | sort` +-if test "$only_next_1" = "$only_next_2" +-then +- not_in_topic=`git rev-list "^$topic" master` +- if test -z "$not_in_topic" +- then +- echo >&2 "$topic is already up to date with master" +- exit 1 ;# we could allow it, but there is no point. +- else +- exit 0 +- fi +-else +- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` +- /usr/bin/perl -e ' +- my $topic = $ARGV[0]; +- my $msg = "* $topic has commits already merged to public branch:\n"; +- my (%not_in_next) = map { +- /^([0-9a-f]+) /; +- ($1 => 1); +- } split(/\n/, $ARGV[1]); +- for my $elem (map { +- /^([0-9a-f]+) (.*)$/; +- [$1 => $2]; +- } split(/\n/, $ARGV[2])) { +- if (!exists $not_in_next{$elem->[0]}) { +- if ($msg) { +- print STDERR $msg; +- undef $msg; +- } +- print STDERR " $elem->[1]\n"; +- } +- } +- ' "$topic" "$not_in_next" "$not_in_master" +- exit 1 +-fi +- +-<<\DOC_END +- +-This sample hook safeguards topic branches that have been +-published from being rewound. +- +-The workflow assumed here is: +- +- * Once a topic branch forks from "master", "master" is never +- merged into it again (either directly or indirectly). +- +- * Once a topic branch is fully cooked and merged into "master", +- it is deleted. If you need to build on top of it to correct +- earlier mistakes, a new topic branch is created by forking at +- the tip of the "master". This is not strictly necessary, but +- it makes it easier to keep your history simple. +- +- * Whenever you need to test or publish your changes to topic +- branches, merge them into "next" branch. +- +-The script, being an example, hardcodes the publish branch name +-to be "next", but it is trivial to make it configurable via +-$GIT_DIR/config mechanism. +- +-With this workflow, you would want to know: +- +-(1) ... if a topic branch has ever been merged to "next". Young +- topic branches can have stupid mistakes you would rather +- clean up before publishing, and things that have not been +- merged into other branches can be easily rebased without +- affecting other people. But once it is published, you would +- not want to rewind it. +- +-(2) ... if a topic branch has been fully merged to "master". +- Then you can delete it. More importantly, you should not +- build on top of it -- other people may already want to +- change things related to the topic as patches against your +- "master", so if you need further changes, it is better to +- fork the topic (perhaps with the same name) afresh from the +- tip of "master". +- +-Let's look at this example: +- +- o---o---o---o---o---o---o---o---o---o "next" +- / / / / +- / a---a---b A / / +- / / / / +- / / c---c---c---c B / +- / / / \ / +- / / / b---b C \ / +- / / / / \ / +- ---o---o---o---o---o---o---o---o---o---o---o "master" +- +- +-A, B and C are topic branches. +- +- * A has one fix since it was merged up to "next". +- +- * B has finished. It has been fully merged up to "master" and "next", +- and is ready to be deleted. +- +- * C has not merged to "next" at all. +- +-We would want to allow C to be rebased, refuse A, and encourage +-B to be deleted. +- +-To compute (1): +- +- git rev-list ^master ^topic next +- git rev-list ^master next +- +- if these match, topic has not merged in next at all. +- +-To compute (2): +- +- git rev-list master..topic +- +- if this is empty, it is fully merged to "master". +- +-DOC_END +diff -Nur b/Chinese-CLIP/.git/hooks/pre-receive.sample a/Chinese-CLIP/.git/hooks/pre-receive.sample +--- b/Chinese-CLIP/.git/hooks/pre-receive.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-receive.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,24 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to make use of push options. +-# The example simply echoes all push options that start with 'echoback=' +-# and rejects all pushes when the "reject" push option is used. +-# +-# To enable this hook, rename this file to "pre-receive". +- +-if test -n "$GIT_PUSH_OPTION_COUNT" +-then +- i=0 +- while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" +- do +- eval "value=\$GIT_PUSH_OPTION_$i" +- case "$value" in +- echoback=*) +- echo "echo from the pre-receive-hook: ${value#*=}" >&2 +- ;; +- reject) +- exit 1 +- esac +- i=$((i + 1)) +- done +-fi +diff -Nur b/Chinese-CLIP/.git/hooks/update.sample a/Chinese-CLIP/.git/hooks/update.sample +--- b/Chinese-CLIP/.git/hooks/update.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/update.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,128 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to block unannotated tags from entering. +-# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +-# +-# To enable this hook, rename this file to "update". +-# +-# Config +-# ------ +-# hooks.allowunannotated +-# This boolean sets whether unannotated tags will be allowed into the +-# repository. By default they won't be. +-# hooks.allowdeletetag +-# This boolean sets whether deleting tags will be allowed in the +-# repository. By default they won't be. +-# hooks.allowmodifytag +-# This boolean sets whether a tag may be modified after creation. By default +-# it won't be. +-# hooks.allowdeletebranch +-# This boolean sets whether deleting branches will be allowed in the +-# repository. By default they won't be. +-# hooks.denycreatebranch +-# This boolean sets whether remotely creating branches will be denied +-# in the repository. By default this is allowed. +-# +- +-# --- Command line +-refname="$1" +-oldrev="$2" +-newrev="$3" +- +-# --- Safety check +-if [ -z "$GIT_DIR" ]; then +- echo "Don't run this script from the command line." >&2 +- echo " (if you want, you could supply GIT_DIR then run" >&2 +- echo " $0 )" >&2 +- exit 1 +-fi +- +-if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then +- echo "usage: $0 " >&2 +- exit 1 +-fi +- +-# --- Config +-allowunannotated=$(git config --bool hooks.allowunannotated) +-allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +-denycreatebranch=$(git config --bool hooks.denycreatebranch) +-allowdeletetag=$(git config --bool hooks.allowdeletetag) +-allowmodifytag=$(git config --bool hooks.allowmodifytag) +- +-# check for no description +-projectdesc=$(sed -e '1q' "$GIT_DIR/description") +-case "$projectdesc" in +-"Unnamed repository"* | "") +- echo "*** Project description file hasn't been set" >&2 +- exit 1 +- ;; +-esac +- +-# --- Check types +-# if $newrev is 0000...0000, it's a commit to delete a ref. +-zero="0000000000000000000000000000000000000000" +-if [ "$newrev" = "$zero" ]; then +- newrev_type=delete +-else +- newrev_type=$(git cat-file -t $newrev) +-fi +- +-case "$refname","$newrev_type" in +- refs/tags/*,commit) +- # un-annotated tag +- short_refname=${refname##refs/tags/} +- if [ "$allowunannotated" != "true" ]; then +- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 +- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 +- exit 1 +- fi +- ;; +- refs/tags/*,delete) +- # delete tag +- if [ "$allowdeletetag" != "true" ]; then +- echo "*** Deleting a tag is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/tags/*,tag) +- # annotated tag +- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 +- then +- echo "*** Tag '$refname' already exists." >&2 +- echo "*** Modifying a tag is not allowed in this repository." >&2 +- exit 1 +- fi +- ;; +- refs/heads/*,commit) +- # branch +- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then +- echo "*** Creating a branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/heads/*,delete) +- # delete branch +- if [ "$allowdeletebranch" != "true" ]; then +- echo "*** Deleting a branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/remotes/*,commit) +- # tracking branch +- ;; +- refs/remotes/*,delete) +- # delete tracking branch +- if [ "$allowdeletebranch" != "true" ]; then +- echo "*** Deleting a tracking branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- *) +- # Anything else (is there anything else?) +- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 +- exit 1 +- ;; +-esac +- +-# --- Finished +-exit 0 +Binary files b/Chinese-CLIP/.git/index and a/Chinese-CLIP/.git/index differ +diff -Nur b/Chinese-CLIP/.git/info/exclude a/Chinese-CLIP/.git/info/exclude +--- b/Chinese-CLIP/.git/info/exclude 2024-08-07 10:13:19.416000000 +0000 ++++ a/Chinese-CLIP/.git/info/exclude 1970-01-01 00:00:00.000000000 +0000 +@@ -1,6 +0,0 @@ +-# git ls-files --others --exclude-from=.git/info/exclude +-# Lines that start with '#' are comments. +-# For a project mostly in C, the following would be a good set of +-# exclude patterns (uncomment them if you want to use them): +-# *.[oa] +-# *~ +diff -Nur b/Chinese-CLIP/.git/logs/HEAD a/Chinese-CLIP/.git/logs/HEAD +--- b/Chinese-CLIP/.git/logs/HEAD 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/logs/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1,2 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +-85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/logs/refs/heads/master a/Chinese-CLIP/.git/logs/refs/heads/master +--- b/Chinese-CLIP/.git/logs/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/logs/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +@@ -1,2 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +-85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD +--- b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx differ +Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack differ +diff -Nur b/Chinese-CLIP/.git/ORIG_HEAD a/Chinese-CLIP/.git/ORIG_HEAD +--- b/Chinese-CLIP/.git/ORIG_HEAD 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/ORIG_HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-85f3fa3639e207d0b76f69a401105cad5d509593 +diff -Nur b/Chinese-CLIP/.git/packed-refs a/Chinese-CLIP/.git/packed-refs +--- b/Chinese-CLIP/.git/packed-refs 2024-08-07 10:13:21.616000000 +0000 ++++ a/Chinese-CLIP/.git/packed-refs 1970-01-01 00:00:00.000000000 +0000 +@@ -1,4 +0,0 @@ +-# pack-refs with: peeled fully-peeled sorted +-8f7d051435adefb5d662a74072e76e838c0f7ce7 refs/remotes/origin/jr_dev +-704a53d80e2192b9c9f1db2b86ee2f47305f10b4 refs/remotes/origin/jxst539246-patch-1 +-85f3fa3639e207d0b76f69a401105cad5d509593 refs/remotes/origin/master +diff -Nur b/Chinese-CLIP/.git/refs/heads/master a/Chinese-CLIP/.git/refs/heads/master +--- b/Chinese-CLIP/.git/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/refs/remotes/origin/HEAD +--- b/Chinese-CLIP/.git/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-ref: refs/remotes/origin/master +diff -Nur b/Chinese-CLIP/run_scripts/zeroshot_eval.sh a/Chinese-CLIP/run_scripts/zeroshot_eval.sh +--- b/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:13:21.656000000 +0000 ++++ a/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:07:22.108000000 +0000 +@@ -18,7 +18,9 @@ + text_model=${5} + resume=${6} + label_file=${path}/datasets/${dataset}/label_cn.txt +-index=${7:-} ++text_om=${7} ++vision_om=${8} ++index=${9:-} + + mkdir -p ${savedir} + +@@ -28,7 +30,9 @@ + --save-dir=${savedir} \ + --dataset=${dataset} \ + --index=${index} \ +- --img-batch-size=64 \ ++ --img-batch-size=24 \ + --resume=${resume} \ + --vision-model=${vision_model} \ +- --text-model=${text_model} ++ --text-model=${text_model} \ ++ --text-om=${text_om} \ ++ --vision-om=${vision_om} +diff -Nur b/cn_clip.patch a/cn_clip.patch +--- b/cn_clip.patch 1970-01-01 00:00:00.000000000 +0000 ++++ a/cn_clip.patch 2024-08-07 01:17:26.048000000 +0000 +@@ -0,0 +1,26 @@ ++diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.py ++--- cn_clip/deploy/pytorch_to_onnx.py 2024-02-20 14:49:36.955252200 +0800 +++++ cn_clip_fix/deploy/pytorch_to_onnx.py 2024-03-17 14:48:30.339636500 +0800 ++@@ -117,8 +117,9 @@ ++ text_fp32_onnx_path, ++ input_names=['text'], ++ output_names=['unnorm_text_features'], +++ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, ++ export_params=True, ++- opset_version=13, +++ opset_version=11, ++ verbose=True) ++ # convert text FP16 ONNX model based on the FP32 model ++ text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" ++@@ -141,9 +142,10 @@ ++ vision_fp32_onnx_path, ++ input_names=['image'], ++ output_names=['unnorm_image_features'], +++ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, ++ export_params=True, ++ do_constant_folding=False, ++- opset_version=13, +++ opset_version=11, ++ verbose=True) ++ # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files ++ if args.model_arch == "ViT-H-14": -- Gitee From 682a508a3b5d2ed389566d1f32eb7e488207a623 Mon Sep 17 00:00:00 2001 From: shikang Date: Wed, 7 Aug 2024 11:09:00 +0000 Subject: [PATCH 2/4] add text script --- .../foundation_models/Chinese_CLIP/README.md | 15 +- .../Chinese_CLIP/aipp.config | 16 - .../Chinese_CLIP/cn_clip.patch | 1057 +++++++++++++++- .../foundation_models/Chinese_CLIP/compare.py | 157 --- .../Chinese_CLIP/patch.patch | 1077 ----------------- 5 files changed, 1062 insertions(+), 1260 deletions(-) delete mode 100644 ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/aipp.config delete mode 100644 ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/compare.py delete mode 100644 ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md index 94a3ff5f69..ff9f55836e 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md @@ -41,7 +41,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 | 输入数据 | 大小 | 数据类型 | 数据排布格式 | |----------|------------------| ------------------------- | ------------ | | image | ${bs} x 3 x 224 x 224 | FLOAT32 | NCHW | - | txt | ${bs} x 512 | INT32 | NCHW | + | txt | ${bs} x 512 | INT32 | ND | - 输出数据 @@ -87,7 +87,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 pip3 install -r requirements.txt # 修改第三方源码推理适配部分 - patch -p0 < ../cn_clip.patch + patch -p2 < ../cn_clip.patch pip3 install -e . cd .. @@ -125,7 +125,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 2. 获取数据集。 下载[cifar-100数据集](http://clip-cn-beijing.oss-cn-beijing.aliyuncs.com/datasets/cifar-100.zip) ``` - mkdir -p ./Chinese-CLIP/data/dataset + mkdir -p ./Chinese-CLIP/data/datasets ``` 在dataset文件夹中解压缩 @@ -150,7 +150,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 - --convert-vision: 指定是否转文本侧模型 - --convert-vision: 指定是否转图像侧模型 - 运行成功后,使用models目录下生成的 vit-b-16.txt.fp16.onnx 和 vit-b-16.img.fp16.onnx 文件进行后续操作。 + 运行成功后,使用models目录下生成的 vit-b-16.txt.fp32.onnx 和 vit-b-16.img.fp32.onnx 文件进行后续操作。 3. 使用 onnx-simplifier 简化 onnx 模型。 @@ -273,11 +273,12 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 ``` cd Chinese-CLIP - export vision_om = ${vit-b-16.img.bs24.om模型的绝对路径} - export text_om = ${vit-b-16.txt.bs24.om模型的绝对路径} + export vision_om=${vit-b-16.img.bs24.om模型的绝对路径} + export text_om=${vit-b-16.txt.bs24.om模型的绝对路径} bash run_scripts/zeroshot_eval.sh 0 data cifar-100 ViT-B-16 RoBERTa-wwm-ext-base-chinese ../models/clip_cn_vit-b-16.pt ${text_om} ${vision_om} + cd .. ``` - 得到数据集精度 top1: 63.91% + 得到数据集精度 top1: 64.04% diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/aipp.config b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/aipp.config deleted file mode 100644 index e11e609a50..0000000000 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/aipp.config +++ /dev/null @@ -1,16 +0,0 @@ -aipp_op{ - aipp_mode:static - input_format : RGB888_U8 - - src_image_size_w : 224 - src_image_size_h : 224 - - crop: false - - min_chn_0 : 123.25239296 - min_chn_1 : 117.20384 - min_chn_2 : 104.50194688 - var_reci_chn_0: 0.0145414015152615 - var_reci_chn_1: 0.0149491443980385 - var_reci_chn_2: 0.014164518585317 -} \ No newline at end of file diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch index 9541637028..2cc6b40803 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch @@ -1,6 +1,6 @@ -diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.py ---- cn_clip/deploy/pytorch_to_onnx.py 2024-02-20 14:49:36.955252200 +0800 -+++ cn_clip_fix/deploy/pytorch_to_onnx.py 2024-03-17 14:48:30.339636500 +0800 +diff -Nur b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py +--- b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 10:13:21.636000000 +0000 ++++ a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 01:17:34.820000000 +0000 @@ -117,8 +117,9 @@ text_fp32_onnx_path, input_names=['text'], @@ -24,3 +24,1054 @@ diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.p verbose=True) # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files if args.model_arch == "ViT-H-14": +diff -Nur b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py +--- b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:13:21.636000000 +0000 ++++ a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:07:28.980000000 +0000 +@@ -10,7 +10,7 @@ + from tqdm import tqdm + + import torch +- ++from ais_bench.infer.interface import InferSession + from cn_clip.clip.model import convert_weights, CLIP + from cn_clip.clip import tokenize + from cn_clip.training.main import convert_models_to_fp32 +@@ -29,6 +29,16 @@ + def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument( ++ "--text-om", ++ default="vit-b-text.om", ++ help="Name of the text om model to use.", ++ ) ++ parser.add_argument( ++ "--vision-om", ++ default="vit-b-image.om", ++ help="Name of the vision om model to use.", ++ ) ++ parser.add_argument( + "--vision-model", + choices=["ViT-B-32", "ViT-B-16", "ViT-L-14", "ViT-L-14-336", "ViT-H-14", "RN50"], + default="ViT-B-16", +@@ -82,12 +92,12 @@ + # help="Path to imagenet val set for conducting zero shot evaluation.", + # ) + parser.add_argument( +- "--img-batch-size", type=int, default=64, help="Image batch size." ++ "--img-batch-size", type=int, default=24, help="Image batch size." + ) + parser.add_argument( + "--context-length", + type=int, +- default=52, ++ default=512, + help="The maximum length of input text (include [CLS] & [SEP] tokens)." + ) + parser.add_argument( +@@ -106,16 +116,24 @@ + + def zero_shot_classifier(model, classnames, templates, args): + with torch.no_grad(): ++ session_code = InferSession(0, model) + zeroshot_weights = [] + for classname in tqdm(classnames): + texts = [_preprocess_text(template(classname)) for template in templates] # format with class +- texts = tokenize(texts, context_length=args.context_length).to(args.gpu) # tokenize +- class_embeddings = model(None, texts) ++ texts = tokenize(texts, context_length=args.context_length) ++ x = torch.zeros(9,512) ++ texts = torch.concat((texts,x),dim=0) ++ res_class = [] ++ for i in range(8): ++ feed = [texts[i*24:(i+1)*24,].to(torch.int64)] ++ class_embeddings = session_code.infer(feed) ++ res_class.append(torch.from_numpy(class_embeddings[0])) ++ class_embeddings = torch.concat(res_class, dim=0)[:183,] + class_embeddings /= class_embeddings.norm(dim=-1, keepdim=True) + class_embedding = class_embeddings.mean(dim=0) + class_embedding /= class_embedding.norm() + zeroshot_weights.append(class_embedding) +- zeroshot_weights = torch.stack(zeroshot_weights, dim=1).to(args.gpu) ++ zeroshot_weights = torch.stack(zeroshot_weights, dim=1) + return zeroshot_weights + + +@@ -128,27 +146,31 @@ + def run(model, classifier, dataloader, args): + total_logits = [] + total_targets = [] +- with torch.no_grad(): +- top1, top5, n = 0.0, 0.0, 0.0 +- for images, target in tqdm(dataloader): +- images = images.to(args.gpu) +- target = target.to(args.gpu) +- total_targets.append(target) +- +- # predict +- image_features = model(images, None) +- image_features /= image_features.norm(dim=-1, keepdim=True) +- logits = (100.0 * image_features @ classifier).softmax(dim=-1) +- total_logits.append(logits) +- +- # measure accuracy +- acc1, acc5 = accuracy(logits, target, topk=(1, 1)) +- top1 += acc1 +- n += images.size(0) ++ session_code = InferSession(0, model) ++ # with torch.no_grad(): ++ top1, top5, n = 0.0, 0.0, 0.0 ++ for images, target in tqdm(dataloader): ++ images = images ++ target = target ++ total_targets.append(target) ++ batch = images.size(0) ++ if batch != 24: ++ pad = torch.zeros_like(images[:(24-batch)]) ++ images = torch.concat((images,pad), dim=0) ++ feed = [images.to(torch.float32)] ++ image_features = session_code.infer(feed) ++ image_features = torch.from_numpy(image_features[0][:batch,]) ++ image_features /= image_features.norm(dim=-1, keepdim=True) ++ logits = (100.0 * image_features @ classifier).softmax(dim=-1) ++ total_logits.append(logits) ++ ++ # measure accuracy ++ acc1, acc5 = accuracy(logits, target, topk=(1, 1)) ++ top1 += acc1 ++ n += batch + + outputs = torch.cat(total_logits, dim=0) + targets = torch.cat(total_targets, dim=0) +- + if getattr(args, "index", ""): + print("Use index to rearrange the logits...") + with open(args.index, "r", encoding="utf-8") as f: +@@ -166,16 +188,14 @@ + if __name__ == "__main__": + args = parse_args() + ++ text_model = args.text_om ++ vision_model = args.vision_om + # Log params. + print("Params:") + for name in sorted(vars(args)): + val = getattr(args, name) + print(f" {name}: {val}") + +- args.gpu = 0 +- torch.cuda.set_device(args.gpu) +- +- # Initialize the model. + vision_model_config_file = Path(__file__).parent.parent / f"clip/model_configs/{args.vision_model.replace('/', '-')}.json" + print('Loading vision model config from', vision_model_config_file) + assert os.path.exists(vision_model_config_file) +@@ -191,17 +211,6 @@ + for k, v in json.load(ft).items(): + model_info[k] = v + +- model = CLIP(**model_info) +- convert_weights(model) +- +- # See https://discuss.pytorch.org/t/valueerror-attemting-to-unscale-fp16-gradients/81372 +- if args.precision == "amp" or args.precision == "fp32": +- convert_models_to_fp32(model) +- model.cuda(args.gpu) +- if args.precision == "fp16": +- convert_weights(model) +- +- # Get eval data. + print("Preparing zeroshot dataset.") + data = {} + print(f"{model_info['image_resolution']}") +@@ -209,26 +218,8 @@ + args, image_transform(model_info["image_resolution"]) + ) + +- # Resume from a checkpoint. +- print("Begin to load model checkpoint from {}.".format(args.resume)) +- assert os.path.exists(args.resume), "The checkpoint file {} not exists!".format(args.resume) +- # Map model to be loaded to specified single gpu. +- loc = "cuda:{}".format(args.gpu) +- checkpoint = torch.load(args.resume, map_location='cpu') +- start_epoch = checkpoint["epoch"] +- sd = checkpoint["state_dict"] +- if next(iter(sd.items()))[0].startswith('module'): +- sd = {k[len('module.'):]: v for k, v in sd.items() if "bert.pooler" not in k} +- model.load_state_dict(sd) +- print( +- f"=> loaded checkpoint '{args.resume}' (epoch {checkpoint['epoch']} @ {checkpoint['step']} steps)" +- ) +- +- # Compute ensembled class embeddings + print('Building zero-shot classifier') + +- model.eval() +- + f = open(args.label_file, "r", encoding="utf8") + classnames = [line.strip() for line in f.readlines()] + +@@ -246,32 +237,10 @@ + else: + templates = template_dict['openai'] + +- # Make inference and evaluation + print('Using classifier') +- classifier = zero_shot_classifier(model, classnames, templates, args) ++ classifier = zero_shot_classifier(text_model, classnames, templates, args) + results = {} +- top1, logits = run(model, classifier, data[args.dataset].dataloader, args) +- +- def json_prec_dump(data, prec=6): +- return json.dumps( +- json.loads(json.dumps(data), parse_float=lambda x: round(float(x), prec)) +- ) +- +- print(logits.size()) +- output_dict = { +- "model_name": "CN-CLIP-" + args.vision_model, +- "dataset_name": args.dataset, +- "num_trainable_params": 0, +- "num_params": sum(x.numel() for x in model.parameters()), +- "num_visual_params": sum(x.numel() for x in model.visual.parameters()), +- "num_backbone_params": sum(x.numel() for x in model.parameters()), +- "n_shot": 0, +- "rnd_seeds": [123], +- "predictions": [logits.cpu().data.numpy().tolist()], +- } +- json_string = json_prec_dump(output_dict) +- with open(os.path.join(args.save_dir, f"{args.dataset}.json"), "w", encoding="utf-8") as w: +- w.write(json_string) ++ top1, logits = run(vision_model, classifier, data[args.dataset].dataloader, args) + + results["zeroshot-top1"] = top1 + +diff -Nur b/Chinese-CLIP/.git/config a/Chinese-CLIP/.git/config +--- b/Chinese-CLIP/.git/config 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/config 1970-01-01 00:00:00.000000000 +0000 +@@ -1,11 +0,0 @@ +-[core] +- repositoryformatversion = 0 +- filemode = true +- bare = false +- logallrefupdates = true +-[remote "origin"] +- url = https://github.com/OFA-Sys/Chinese-CLIP.git +- fetch = +refs/heads/*:refs/remotes/origin/* +-[branch "master"] +- remote = origin +- merge = refs/heads/master +diff -Nur b/Chinese-CLIP/.git/description a/Chinese-CLIP/.git/description +--- b/Chinese-CLIP/.git/description 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/description 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-Unnamed repository; edit this file 'description' to name the repository. +diff -Nur b/Chinese-CLIP/.git/HEAD a/Chinese-CLIP/.git/HEAD +--- b/Chinese-CLIP/.git/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-ref: refs/heads/master +diff -Nur b/Chinese-CLIP/.git/hooks/applypatch-msg.sample a/Chinese-CLIP/.git/hooks/applypatch-msg.sample +--- b/Chinese-CLIP/.git/hooks/applypatch-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/applypatch-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,15 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to check the commit log message taken by +-# applypatch from an e-mail message. +-# +-# The hook should exit with non-zero status after issuing an +-# appropriate message if it wants to stop the commit. The hook is +-# allowed to edit the commit message file. +-# +-# To enable this hook, rename this file to "applypatch-msg". +- +-. git-sh-setup +-commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +-test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +-: +diff -Nur b/Chinese-CLIP/.git/hooks/commit-msg.sample a/Chinese-CLIP/.git/hooks/commit-msg.sample +--- b/Chinese-CLIP/.git/hooks/commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,24 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to check the commit log message. +-# Called by "git commit" with one argument, the name of the file +-# that has the commit message. The hook should exit with non-zero +-# status after issuing an appropriate message if it wants to stop the +-# commit. The hook is allowed to edit the commit message file. +-# +-# To enable this hook, rename this file to "commit-msg". +- +-# Uncomment the below to add a Signed-off-by line to the message. +-# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +-# hook is more suited to it. +-# +-# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +-# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" +- +-# This example catches duplicate Signed-off-by lines. +- +-test "" = "$(grep '^Signed-off-by: ' "$1" | +- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { +- echo >&2 Duplicate Signed-off-by lines. +- exit 1 +-} +diff -Nur b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample +--- b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,109 +0,0 @@ +-#!/usr/bin/perl +- +-use strict; +-use warnings; +-use IPC::Open2; +- +-# An example hook script to integrate Watchman +-# (https://facebook.github.io/watchman/) with git to speed up detecting +-# new and modified files. +-# +-# The hook is passed a version (currently 1) and a time in nanoseconds +-# formatted as a string and outputs to stdout all files that have been +-# modified since the given time. Paths must be relative to the root of +-# the working tree and separated by a single NUL. +-# +-# To enable this hook, rename this file to "query-watchman" and set +-# 'git config core.fsmonitor .git/hooks/query-watchman' +-# +-my ($version, $time) = @ARGV; +- +-# Check the hook interface version +- +-if ($version == 1) { +- # convert nanoseconds to seconds +- # subtract one second to make sure watchman will return all changes +- $time = int ($time / 1000000000) - 1; +-} else { +- die "Unsupported query-fsmonitor hook version '$version'.\n" . +- "Falling back to scanning...\n"; +-} +- +-my $git_work_tree; +-if ($^O =~ 'msys' || $^O =~ 'cygwin') { +- $git_work_tree = Win32::GetCwd(); +- $git_work_tree =~ tr/\\/\//; +-} else { +- require Cwd; +- $git_work_tree = Cwd::cwd(); +-} +- +-my $retry = 1; +- +-launch_watchman(); +- +-sub launch_watchman { +- +- my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') +- or die "open2() failed: $!\n" . +- "Falling back to scanning...\n"; +- +- # In the query expression below we're asking for names of files that +- # changed since $time but were not transient (ie created after +- # $time but no longer exist). +- # +- # To accomplish this, we're using the "since" generator to use the +- # recency index to select candidate nodes and "fields" to limit the +- # output to file names only. +- +- my $query = <<" END"; +- ["query", "$git_work_tree", { +- "since": $time, +- "fields": ["name"] +- }] +- END +- +- print CHLD_IN $query; +- close CHLD_IN; +- my $response = do {local $/; }; +- +- die "Watchman: command returned no output.\n" . +- "Falling back to scanning...\n" if $response eq ""; +- die "Watchman: command returned invalid output: $response\n" . +- "Falling back to scanning...\n" unless $response =~ /^\{/; +- +- my $json_pkg; +- eval { +- require JSON::XS; +- $json_pkg = "JSON::XS"; +- 1; +- } or do { +- require JSON::PP; +- $json_pkg = "JSON::PP"; +- }; +- +- my $o = $json_pkg->new->utf8->decode($response); +- +- if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { +- print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; +- $retry--; +- qx/watchman watch "$git_work_tree"/; +- die "Failed to make watchman watch '$git_work_tree'.\n" . +- "Falling back to scanning...\n" if $? != 0; +- +- # Watchman will always return all files on the first query so +- # return the fast "everything is dirty" flag to git and do the +- # Watchman query just to get it over with now so we won't pay +- # the cost in git to look up each individual file. +- print "/\0"; +- eval { launch_watchman() }; +- exit 0; +- } +- +- die "Watchman: $o->{error}.\n" . +- "Falling back to scanning...\n" if $o->{error}; +- +- binmode STDOUT, ":utf8"; +- local $, = "\0"; +- print @{$o->{files}}; +-} +diff -Nur b/Chinese-CLIP/.git/hooks/post-update.sample a/Chinese-CLIP/.git/hooks/post-update.sample +--- b/Chinese-CLIP/.git/hooks/post-update.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/post-update.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,8 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to prepare a packed repository for use over +-# dumb transports. +-# +-# To enable this hook, rename this file to "post-update". +- +-exec git update-server-info +diff -Nur b/Chinese-CLIP/.git/hooks/pre-applypatch.sample a/Chinese-CLIP/.git/hooks/pre-applypatch.sample +--- b/Chinese-CLIP/.git/hooks/pre-applypatch.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-applypatch.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,14 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed +-# by applypatch from an e-mail message. +-# +-# The hook should exit with non-zero status after issuing an +-# appropriate message if it wants to stop the commit. +-# +-# To enable this hook, rename this file to "pre-applypatch". +- +-. git-sh-setup +-precommit="$(git rev-parse --git-path hooks/pre-commit)" +-test -x "$precommit" && exec "$precommit" ${1+"$@"} +-: +diff -Nur b/Chinese-CLIP/.git/hooks/pre-commit.sample a/Chinese-CLIP/.git/hooks/pre-commit.sample +--- b/Chinese-CLIP/.git/hooks/pre-commit.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,49 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed. +-# Called by "git commit" with no arguments. The hook should +-# exit with non-zero status after issuing an appropriate message if +-# it wants to stop the commit. +-# +-# To enable this hook, rename this file to "pre-commit". +- +-if git rev-parse --verify HEAD >/dev/null 2>&1 +-then +- against=HEAD +-else +- # Initial commit: diff against an empty tree object +- against=$(git hash-object -t tree /dev/null) +-fi +- +-# If you want to allow non-ASCII filenames set this variable to true. +-allownonascii=$(git config --bool hooks.allownonascii) +- +-# Redirect output to stderr. +-exec 1>&2 +- +-# Cross platform projects tend to avoid non-ASCII filenames; prevent +-# them from being added to the repository. We exploit the fact that the +-# printable range starts at the space character and ends with tilde. +-if [ "$allownonascii" != "true" ] && +- # Note that the use of brackets around a tr range is ok here, (it's +- # even required, for portability to Solaris 10's /usr/bin/tr), since +- # the square bracket bytes happen to fall in the designated range. +- test $(git diff --cached --name-only --diff-filter=A -z $against | +- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +-then +- cat <<\EOF +-Error: Attempt to add a non-ASCII file name. +- +-This can cause problems if you want to work with people on other platforms. +- +-To be portable it is advisable to rename the file. +- +-If you know what you are doing you can disable this check using: +- +- git config hooks.allownonascii true +-EOF +- exit 1 +-fi +- +-# If there are whitespace errors, print the offending file names and fail. +-exec git diff-index --check --cached $against -- +diff -Nur b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample +--- b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,13 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to verify what is about to be committed. +-# Called by "git merge" with no arguments. The hook should +-# exit with non-zero status after issuing an appropriate message to +-# stderr if it wants to stop the merge commit. +-# +-# To enable this hook, rename this file to "pre-merge-commit". +- +-. git-sh-setup +-test -x "$GIT_DIR/hooks/pre-commit" && +- exec "$GIT_DIR/hooks/pre-commit" +-: +diff -Nur b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample +--- b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,42 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to prepare the commit log message. +-# Called by "git commit" with the name of the file that has the +-# commit message, followed by the description of the commit +-# message's source. The hook's purpose is to edit the commit +-# message file. If the hook fails with a non-zero status, +-# the commit is aborted. +-# +-# To enable this hook, rename this file to "prepare-commit-msg". +- +-# This hook includes three examples. The first one removes the +-# "# Please enter the commit message..." help message. +-# +-# The second includes the output of "git diff --name-status -r" +-# into the message, just before the "git status" output. It is +-# commented because it doesn't cope with --amend or with squashed +-# commits. +-# +-# The third example adds a Signed-off-by line to the message, that can +-# still be edited. This is rarely a good idea. +- +-COMMIT_MSG_FILE=$1 +-COMMIT_SOURCE=$2 +-SHA1=$3 +- +-/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" +- +-# case "$COMMIT_SOURCE,$SHA1" in +-# ,|template,) +-# /usr/bin/perl -i.bak -pe ' +-# print "\n" . `git diff --cached --name-status -r` +-# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +-# *) ;; +-# esac +- +-# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +-# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +-# if test -z "$COMMIT_SOURCE" +-# then +-# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +-# fi +diff -Nur b/Chinese-CLIP/.git/hooks/pre-push.sample a/Chinese-CLIP/.git/hooks/pre-push.sample +--- b/Chinese-CLIP/.git/hooks/pre-push.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-push.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,53 +0,0 @@ +-#!/bin/sh +- +-# An example hook script to verify what is about to be pushed. Called by "git +-# push" after it has checked the remote status, but before anything has been +-# pushed. If this script exits with a non-zero status nothing will be pushed. +-# +-# This hook is called with the following parameters: +-# +-# $1 -- Name of the remote to which the push is being done +-# $2 -- URL to which the push is being done +-# +-# If pushing without using a named remote those arguments will be equal. +-# +-# Information about the commits which are being pushed is supplied as lines to +-# the standard input in the form: +-# +-# +-# +-# This sample shows how to prevent push of commits where the log message starts +-# with "WIP" (work in progress). +- +-remote="$1" +-url="$2" +- +-z40=0000000000000000000000000000000000000000 +- +-while read local_ref local_sha remote_ref remote_sha +-do +- if [ "$local_sha" = $z40 ] +- then +- # Handle delete +- : +- else +- if [ "$remote_sha" = $z40 ] +- then +- # New branch, examine all commits +- range="$local_sha" +- else +- # Update to existing branch, examine new commits +- range="$remote_sha..$local_sha" +- fi +- +- # Check for WIP commit +- commit=`git rev-list -n 1 --grep '^WIP' "$range"` +- if [ -n "$commit" ] +- then +- echo >&2 "Found WIP commit in $local_ref, not pushing" +- exit 1 +- fi +- fi +-done +- +-exit 0 +diff -Nur b/Chinese-CLIP/.git/hooks/pre-rebase.sample a/Chinese-CLIP/.git/hooks/pre-rebase.sample +--- b/Chinese-CLIP/.git/hooks/pre-rebase.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-rebase.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,169 +0,0 @@ +-#!/bin/sh +-# +-# Copyright (c) 2006, 2008 Junio C Hamano +-# +-# The "pre-rebase" hook is run just before "git rebase" starts doing +-# its job, and can prevent the command from running by exiting with +-# non-zero status. +-# +-# The hook is called with the following parameters: +-# +-# $1 -- the upstream the series was forked from. +-# $2 -- the branch being rebased (or empty when rebasing the current branch). +-# +-# This sample shows how to prevent topic branches that are already +-# merged to 'next' branch from getting rebased, because allowing it +-# would result in rebasing already published history. +- +-publish=next +-basebranch="$1" +-if test "$#" = 2 +-then +- topic="refs/heads/$2" +-else +- topic=`git symbolic-ref HEAD` || +- exit 0 ;# we do not interrupt rebasing detached HEAD +-fi +- +-case "$topic" in +-refs/heads/??/*) +- ;; +-*) +- exit 0 ;# we do not interrupt others. +- ;; +-esac +- +-# Now we are dealing with a topic branch being rebased +-# on top of master. Is it OK to rebase it? +- +-# Does the topic really exist? +-git show-ref -q "$topic" || { +- echo >&2 "No such branch $topic" +- exit 1 +-} +- +-# Is topic fully merged to master? +-not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +-if test -z "$not_in_master" +-then +- echo >&2 "$topic is fully merged to master; better remove it." +- exit 1 ;# we could allow it, but there is no point. +-fi +- +-# Is topic ever merged to next? If so you should not be rebasing it. +-only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +-only_next_2=`git rev-list ^master ${publish} | sort` +-if test "$only_next_1" = "$only_next_2" +-then +- not_in_topic=`git rev-list "^$topic" master` +- if test -z "$not_in_topic" +- then +- echo >&2 "$topic is already up to date with master" +- exit 1 ;# we could allow it, but there is no point. +- else +- exit 0 +- fi +-else +- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` +- /usr/bin/perl -e ' +- my $topic = $ARGV[0]; +- my $msg = "* $topic has commits already merged to public branch:\n"; +- my (%not_in_next) = map { +- /^([0-9a-f]+) /; +- ($1 => 1); +- } split(/\n/, $ARGV[1]); +- for my $elem (map { +- /^([0-9a-f]+) (.*)$/; +- [$1 => $2]; +- } split(/\n/, $ARGV[2])) { +- if (!exists $not_in_next{$elem->[0]}) { +- if ($msg) { +- print STDERR $msg; +- undef $msg; +- } +- print STDERR " $elem->[1]\n"; +- } +- } +- ' "$topic" "$not_in_next" "$not_in_master" +- exit 1 +-fi +- +-<<\DOC_END +- +-This sample hook safeguards topic branches that have been +-published from being rewound. +- +-The workflow assumed here is: +- +- * Once a topic branch forks from "master", "master" is never +- merged into it again (either directly or indirectly). +- +- * Once a topic branch is fully cooked and merged into "master", +- it is deleted. If you need to build on top of it to correct +- earlier mistakes, a new topic branch is created by forking at +- the tip of the "master". This is not strictly necessary, but +- it makes it easier to keep your history simple. +- +- * Whenever you need to test or publish your changes to topic +- branches, merge them into "next" branch. +- +-The script, being an example, hardcodes the publish branch name +-to be "next", but it is trivial to make it configurable via +-$GIT_DIR/config mechanism. +- +-With this workflow, you would want to know: +- +-(1) ... if a topic branch has ever been merged to "next". Young +- topic branches can have stupid mistakes you would rather +- clean up before publishing, and things that have not been +- merged into other branches can be easily rebased without +- affecting other people. But once it is published, you would +- not want to rewind it. +- +-(2) ... if a topic branch has been fully merged to "master". +- Then you can delete it. More importantly, you should not +- build on top of it -- other people may already want to +- change things related to the topic as patches against your +- "master", so if you need further changes, it is better to +- fork the topic (perhaps with the same name) afresh from the +- tip of "master". +- +-Let's look at this example: +- +- o---o---o---o---o---o---o---o---o---o "next" +- / / / / +- / a---a---b A / / +- / / / / +- / / c---c---c---c B / +- / / / \ / +- / / / b---b C \ / +- / / / / \ / +- ---o---o---o---o---o---o---o---o---o---o---o "master" +- +- +-A, B and C are topic branches. +- +- * A has one fix since it was merged up to "next". +- +- * B has finished. It has been fully merged up to "master" and "next", +- and is ready to be deleted. +- +- * C has not merged to "next" at all. +- +-We would want to allow C to be rebased, refuse A, and encourage +-B to be deleted. +- +-To compute (1): +- +- git rev-list ^master ^topic next +- git rev-list ^master next +- +- if these match, topic has not merged in next at all. +- +-To compute (2): +- +- git rev-list master..topic +- +- if this is empty, it is fully merged to "master". +- +-DOC_END +diff -Nur b/Chinese-CLIP/.git/hooks/pre-receive.sample a/Chinese-CLIP/.git/hooks/pre-receive.sample +--- b/Chinese-CLIP/.git/hooks/pre-receive.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/pre-receive.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,24 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to make use of push options. +-# The example simply echoes all push options that start with 'echoback=' +-# and rejects all pushes when the "reject" push option is used. +-# +-# To enable this hook, rename this file to "pre-receive". +- +-if test -n "$GIT_PUSH_OPTION_COUNT" +-then +- i=0 +- while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" +- do +- eval "value=\$GIT_PUSH_OPTION_$i" +- case "$value" in +- echoback=*) +- echo "echo from the pre-receive-hook: ${value#*=}" >&2 +- ;; +- reject) +- exit 1 +- esac +- i=$((i + 1)) +- done +-fi +diff -Nur b/Chinese-CLIP/.git/hooks/update.sample a/Chinese-CLIP/.git/hooks/update.sample +--- b/Chinese-CLIP/.git/hooks/update.sample 2024-08-07 10:13:19.420000000 +0000 ++++ a/Chinese-CLIP/.git/hooks/update.sample 1970-01-01 00:00:00.000000000 +0000 +@@ -1,128 +0,0 @@ +-#!/bin/sh +-# +-# An example hook script to block unannotated tags from entering. +-# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +-# +-# To enable this hook, rename this file to "update". +-# +-# Config +-# ------ +-# hooks.allowunannotated +-# This boolean sets whether unannotated tags will be allowed into the +-# repository. By default they won't be. +-# hooks.allowdeletetag +-# This boolean sets whether deleting tags will be allowed in the +-# repository. By default they won't be. +-# hooks.allowmodifytag +-# This boolean sets whether a tag may be modified after creation. By default +-# it won't be. +-# hooks.allowdeletebranch +-# This boolean sets whether deleting branches will be allowed in the +-# repository. By default they won't be. +-# hooks.denycreatebranch +-# This boolean sets whether remotely creating branches will be denied +-# in the repository. By default this is allowed. +-# +- +-# --- Command line +-refname="$1" +-oldrev="$2" +-newrev="$3" +- +-# --- Safety check +-if [ -z "$GIT_DIR" ]; then +- echo "Don't run this script from the command line." >&2 +- echo " (if you want, you could supply GIT_DIR then run" >&2 +- echo " $0 )" >&2 +- exit 1 +-fi +- +-if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then +- echo "usage: $0 " >&2 +- exit 1 +-fi +- +-# --- Config +-allowunannotated=$(git config --bool hooks.allowunannotated) +-allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +-denycreatebranch=$(git config --bool hooks.denycreatebranch) +-allowdeletetag=$(git config --bool hooks.allowdeletetag) +-allowmodifytag=$(git config --bool hooks.allowmodifytag) +- +-# check for no description +-projectdesc=$(sed -e '1q' "$GIT_DIR/description") +-case "$projectdesc" in +-"Unnamed repository"* | "") +- echo "*** Project description file hasn't been set" >&2 +- exit 1 +- ;; +-esac +- +-# --- Check types +-# if $newrev is 0000...0000, it's a commit to delete a ref. +-zero="0000000000000000000000000000000000000000" +-if [ "$newrev" = "$zero" ]; then +- newrev_type=delete +-else +- newrev_type=$(git cat-file -t $newrev) +-fi +- +-case "$refname","$newrev_type" in +- refs/tags/*,commit) +- # un-annotated tag +- short_refname=${refname##refs/tags/} +- if [ "$allowunannotated" != "true" ]; then +- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 +- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 +- exit 1 +- fi +- ;; +- refs/tags/*,delete) +- # delete tag +- if [ "$allowdeletetag" != "true" ]; then +- echo "*** Deleting a tag is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/tags/*,tag) +- # annotated tag +- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 +- then +- echo "*** Tag '$refname' already exists." >&2 +- echo "*** Modifying a tag is not allowed in this repository." >&2 +- exit 1 +- fi +- ;; +- refs/heads/*,commit) +- # branch +- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then +- echo "*** Creating a branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/heads/*,delete) +- # delete branch +- if [ "$allowdeletebranch" != "true" ]; then +- echo "*** Deleting a branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- refs/remotes/*,commit) +- # tracking branch +- ;; +- refs/remotes/*,delete) +- # delete tracking branch +- if [ "$allowdeletebranch" != "true" ]; then +- echo "*** Deleting a tracking branch is not allowed in this repository" >&2 +- exit 1 +- fi +- ;; +- *) +- # Anything else (is there anything else?) +- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 +- exit 1 +- ;; +-esac +- +-# --- Finished +-exit 0 +Binary files b/Chinese-CLIP/.git/index and a/Chinese-CLIP/.git/index differ +diff -Nur b/Chinese-CLIP/.git/info/exclude a/Chinese-CLIP/.git/info/exclude +--- b/Chinese-CLIP/.git/info/exclude 2024-08-07 10:13:19.416000000 +0000 ++++ a/Chinese-CLIP/.git/info/exclude 1970-01-01 00:00:00.000000000 +0000 +@@ -1,6 +0,0 @@ +-# git ls-files --others --exclude-from=.git/info/exclude +-# Lines that start with '#' are comments. +-# For a project mostly in C, the following would be a good set of +-# exclude patterns (uncomment them if you want to use them): +-# *.[oa] +-# *~ +diff -Nur b/Chinese-CLIP/.git/logs/HEAD a/Chinese-CLIP/.git/logs/HEAD +--- b/Chinese-CLIP/.git/logs/HEAD 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/logs/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1,2 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +-85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/logs/refs/heads/master a/Chinese-CLIP/.git/logs/refs/heads/master +--- b/Chinese-CLIP/.git/logs/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/logs/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +@@ -1,2 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +-85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD +--- b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git +Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx differ +Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack differ +diff -Nur b/Chinese-CLIP/.git/ORIG_HEAD a/Chinese-CLIP/.git/ORIG_HEAD +--- b/Chinese-CLIP/.git/ORIG_HEAD 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/ORIG_HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-85f3fa3639e207d0b76f69a401105cad5d509593 +diff -Nur b/Chinese-CLIP/.git/packed-refs a/Chinese-CLIP/.git/packed-refs +--- b/Chinese-CLIP/.git/packed-refs 2024-08-07 10:13:21.616000000 +0000 ++++ a/Chinese-CLIP/.git/packed-refs 1970-01-01 00:00:00.000000000 +0000 +@@ -1,4 +0,0 @@ +-# pack-refs with: peeled fully-peeled sorted +-8f7d051435adefb5d662a74072e76e838c0f7ce7 refs/remotes/origin/jr_dev +-704a53d80e2192b9c9f1db2b86ee2f47305f10b4 refs/remotes/origin/jxst539246-patch-1 +-85f3fa3639e207d0b76f69a401105cad5d509593 refs/remotes/origin/master +diff -Nur b/Chinese-CLIP/.git/refs/heads/master a/Chinese-CLIP/.git/refs/heads/master +--- b/Chinese-CLIP/.git/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 ++++ a/Chinese-CLIP/.git/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-2c38d03557e50eadc72972b272cebf840dbc34ea +diff -Nur b/Chinese-CLIP/.git/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/refs/remotes/origin/HEAD +--- b/Chinese-CLIP/.git/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 ++++ a/Chinese-CLIP/.git/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 +@@ -1 +0,0 @@ +-ref: refs/remotes/origin/master +diff -Nur b/Chinese-CLIP/run_scripts/zeroshot_eval.sh a/Chinese-CLIP/run_scripts/zeroshot_eval.sh +--- b/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:13:21.656000000 +0000 ++++ a/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:07:22.108000000 +0000 +@@ -18,7 +18,9 @@ + text_model=${5} + resume=${6} + label_file=${path}/datasets/${dataset}/label_cn.txt +-index=${7:-} ++text_om=${7} ++vision_om=${8} ++index=${9:-} + + mkdir -p ${savedir} + +@@ -28,7 +30,9 @@ + --save-dir=${savedir} \ + --dataset=${dataset} \ + --index=${index} \ +- --img-batch-size=64 \ ++ --img-batch-size=24 \ + --resume=${resume} \ + --vision-model=${vision_model} \ +- --text-model=${text_model} ++ --text-model=${text_model} \ ++ --text-om=${text_om} \ ++ --vision-om=${vision_om} +diff -Nur b/cn_clip.patch a/cn_clip.patch +--- b/cn_clip.patch 1970-01-01 00:00:00.000000000 +0000 ++++ a/cn_clip.patch 2024-08-07 01:17:26.048000000 +0000 +@@ -0,0 +1,26 @@ ++diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.py ++--- cn_clip/deploy/pytorch_to_onnx.py 2024-02-20 14:49:36.955252200 +0800 +++++ cn_clip_fix/deploy/pytorch_to_onnx.py 2024-03-17 14:48:30.339636500 +0800 ++@@ -117,8 +117,9 @@ ++ text_fp32_onnx_path, ++ input_names=['text'], ++ output_names=['unnorm_text_features'], +++ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, ++ export_params=True, ++- opset_version=13, +++ opset_version=11, ++ verbose=True) ++ # convert text FP16 ONNX model based on the FP32 model ++ text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" ++@@ -141,9 +142,10 @@ ++ vision_fp32_onnx_path, ++ input_names=['image'], ++ output_names=['unnorm_image_features'], +++ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, ++ export_params=True, ++ do_constant_folding=False, ++- opset_version=13, +++ opset_version=11, ++ verbose=True) ++ # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files ++ if args.model_arch == "ViT-H-14": diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/compare.py b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/compare.py deleted file mode 100644 index 4df6ecfa89..0000000000 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/compare.py +++ /dev/null @@ -1,157 +0,0 @@ -# Copyright 2024 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import argparse -import json -from PIL import Image -from pathlib import Path - -import torch -import numpy as np -from torchvision.transforms import Compose, Resize, InterpolationMode -from ais_bench.infer.interface import InferSession - -from cn_clip.clip.model import convert_weights, CLIP -import cn_clip.clip as clip -from cn_clip.training.main import convert_models_to_fp32 -from cn_clip.clip.utils import image_transform - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument( - "--vision-model", - choices=["ViT-B-32", "ViT-B-16", "ViT-L-14", "ViT-L-14-336", "ViT-H-14", "RN50"], - default="ViT-B-16", - help="Name of the vision backbone to use.", - ) - parser.add_argument( - "--text-model", - choices=["RoBERTa-wwm-ext-base-chinese", "RoBERTa-wwm-ext-large-chinese", "RBT3-chinese"], - default="RoBERTa-wwm-ext-base-chinese", - help="Name of the text backbone to use.", - ) - parser.add_argument( - "--batch-size", type=int, default=20, help="Image batch size." - ) - parser.add_argument( - "--resume", - default="./models/clip_cn_vit-b-16.pt", - type=str, - help="path to latest checkpoint (default: none)", - ) - parser.add_argument( - "--npu-device", type=int, default=0, help="Npu device ID." - ) - parser.add_argument( - "--txt-model-path", - type=str, - default=None, - help="path to img om model." - ) - parser.add_argument( - "--img-model-path", - type=str, - default=None, - help="path to img om model." - ) - args = parser.parse_args() - - return args - - -def _convert_to_rgb(image): - return torch.tensor(np.array(image.convert('RGB')).astype("uint8")) - - -def image_transform_wo_normalize(image_size=224): - transform = Compose([ - Resize((image_size, image_size), interpolation=InterpolationMode.BICUBIC), - _convert_to_rgb, - ]) - return transform - - -def cpu_infer(args, model_info, txt, img): - # get model - model = CLIP(**model_info) - # See https://discuss.pytorch.org/t/valueerror-attemting-to-unscale-fp16-gradients/81372 - convert_weights(model) - convert_models_to_fp32(model) - # Resume from a checkpoint. - print("Begin to load model checkpoint from {}.".format(args.resume)) - assert os.path.exists(args.resume), "The checkpoint file {} not exists!".format(args.resume) - # Map model to be loaded to specified device. - checkpoint = torch.load(args.resume, map_location='cpu') - sd = checkpoint["state_dict"] - if next(iter(sd.items()))[0].startswith('module'): - sd = {k[len('module.'):]: v for k, v in sd.items() if "bert.pooler" not in k} - model.load_state_dict(sd) - model.eval() - - # cpu infer - with torch.no_grad(): - assert args.txt_model_path is not None or args.img_model_path is not None, "txt_model_path and img_model_path cannot both be None" - assert args.txt_model_path is None or args.img_model_path is None, "txt_model_path and img_model_path cannot both passing values" - if args.txt_model_path: - out = model(None, txt) - elif args.img_model_path: - out = model(img, None) - return out - - -def om_infer(args, txt, img): - assert args.txt_model_path is not None or args.img_model_path is not None, "txt_model_path and img_model_path cannot both be None" - assert args.txt_model_path is None or args.img_model_path is None, "txt_model_path and img_model_path cannot both passing values" - if args.txt_model_path: - session = InferSession(args.npu_device, args.txt_model_path) - out = session.infer([txt]) - elif args.img_model_path: - session = InferSession(args.npu_device, args.img_model_path) - out = session.infer([img]) - return torch.tensor(out[0]) - - -if __name__ == "__main__": - args = parse_args() - - # Get model config. - vision_model_config_file = Path(__file__).parent / \ - f"Chinese-CLIP/cn_clip/clip/model_configs/{args.vision_model.replace('/', '-')}.json" - assert os.path.exists(vision_model_config_file) - - text_model_config_file = Path(__file__).parent / \ - f"Chinese-CLIP/cn_clip/clip/model_configs/{args.text_model.replace('/', '-')}.json" - assert os.path.exists(text_model_config_file) - - with open(vision_model_config_file, 'r') as fv, open(text_model_config_file, 'r') as ft: - model_info = json.load(fv) - if isinstance(model_info['vision_layers'], str): - model_info['vision_layers'] = eval(model_info['vision_layers']) - for k, v in json.load(ft).items(): - model_info[k] = v - - # build inputs - text = clip.tokenize(["皮卡丘"], context_length=512).expand(args.batch_size, 512) - preprocess = image_transform(model_info["image_resolution"]) - image = preprocess(Image.open("Chinese-CLIP/examples/pokemon.jpeg")).unsqueeze(0).expand(args.batch_size,3,224,224) - preprocess = image_transform_wo_normalize(model_info["image_resolution"]) - image_wo_normalize = preprocess(Image.open("Chinese-CLIP/examples/pokemon.jpeg")).unsqueeze(0).expand(args.batch_size,224,224,3) - - x = cpu_infer(args, model_info, text, image) - y = om_infer(args, text, image_wo_normalize) - - similarity = torch.cosine_similarity(torch.tensor(x).reshape(-1), y.reshape(-1), dim=0) - print(f"模型输出的余弦相似度为:{similarity}") \ No newline at end of file diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch deleted file mode 100644 index 2cc6b40803..0000000000 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/patch.patch +++ /dev/null @@ -1,1077 +0,0 @@ -diff -Nur b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py ---- b/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 10:13:21.636000000 +0000 -+++ a/Chinese-CLIP/cn_clip/deploy/pytorch_to_onnx.py 2024-08-07 01:17:34.820000000 +0000 -@@ -117,8 +117,9 @@ - text_fp32_onnx_path, - input_names=['text'], - output_names=['unnorm_text_features'], -+ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, - export_params=True, -- opset_version=13, -+ opset_version=11, - verbose=True) - # convert text FP16 ONNX model based on the FP32 model - text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" -@@ -141,9 +142,10 @@ - vision_fp32_onnx_path, - input_names=['image'], - output_names=['unnorm_image_features'], -+ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, - export_params=True, - do_constant_folding=False, -- opset_version=13, -+ opset_version=11, - verbose=True) - # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files - if args.model_arch == "ViT-H-14": -diff -Nur b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py ---- b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:13:21.636000000 +0000 -+++ a/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py 2024-08-07 10:07:28.980000000 +0000 -@@ -10,7 +10,7 @@ - from tqdm import tqdm - - import torch -- -+from ais_bench.infer.interface import InferSession - from cn_clip.clip.model import convert_weights, CLIP - from cn_clip.clip import tokenize - from cn_clip.training.main import convert_models_to_fp32 -@@ -29,6 +29,16 @@ - def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument( -+ "--text-om", -+ default="vit-b-text.om", -+ help="Name of the text om model to use.", -+ ) -+ parser.add_argument( -+ "--vision-om", -+ default="vit-b-image.om", -+ help="Name of the vision om model to use.", -+ ) -+ parser.add_argument( - "--vision-model", - choices=["ViT-B-32", "ViT-B-16", "ViT-L-14", "ViT-L-14-336", "ViT-H-14", "RN50"], - default="ViT-B-16", -@@ -82,12 +92,12 @@ - # help="Path to imagenet val set for conducting zero shot evaluation.", - # ) - parser.add_argument( -- "--img-batch-size", type=int, default=64, help="Image batch size." -+ "--img-batch-size", type=int, default=24, help="Image batch size." - ) - parser.add_argument( - "--context-length", - type=int, -- default=52, -+ default=512, - help="The maximum length of input text (include [CLS] & [SEP] tokens)." - ) - parser.add_argument( -@@ -106,16 +116,24 @@ - - def zero_shot_classifier(model, classnames, templates, args): - with torch.no_grad(): -+ session_code = InferSession(0, model) - zeroshot_weights = [] - for classname in tqdm(classnames): - texts = [_preprocess_text(template(classname)) for template in templates] # format with class -- texts = tokenize(texts, context_length=args.context_length).to(args.gpu) # tokenize -- class_embeddings = model(None, texts) -+ texts = tokenize(texts, context_length=args.context_length) -+ x = torch.zeros(9,512) -+ texts = torch.concat((texts,x),dim=0) -+ res_class = [] -+ for i in range(8): -+ feed = [texts[i*24:(i+1)*24,].to(torch.int64)] -+ class_embeddings = session_code.infer(feed) -+ res_class.append(torch.from_numpy(class_embeddings[0])) -+ class_embeddings = torch.concat(res_class, dim=0)[:183,] - class_embeddings /= class_embeddings.norm(dim=-1, keepdim=True) - class_embedding = class_embeddings.mean(dim=0) - class_embedding /= class_embedding.norm() - zeroshot_weights.append(class_embedding) -- zeroshot_weights = torch.stack(zeroshot_weights, dim=1).to(args.gpu) -+ zeroshot_weights = torch.stack(zeroshot_weights, dim=1) - return zeroshot_weights - - -@@ -128,27 +146,31 @@ - def run(model, classifier, dataloader, args): - total_logits = [] - total_targets = [] -- with torch.no_grad(): -- top1, top5, n = 0.0, 0.0, 0.0 -- for images, target in tqdm(dataloader): -- images = images.to(args.gpu) -- target = target.to(args.gpu) -- total_targets.append(target) -- -- # predict -- image_features = model(images, None) -- image_features /= image_features.norm(dim=-1, keepdim=True) -- logits = (100.0 * image_features @ classifier).softmax(dim=-1) -- total_logits.append(logits) -- -- # measure accuracy -- acc1, acc5 = accuracy(logits, target, topk=(1, 1)) -- top1 += acc1 -- n += images.size(0) -+ session_code = InferSession(0, model) -+ # with torch.no_grad(): -+ top1, top5, n = 0.0, 0.0, 0.0 -+ for images, target in tqdm(dataloader): -+ images = images -+ target = target -+ total_targets.append(target) -+ batch = images.size(0) -+ if batch != 24: -+ pad = torch.zeros_like(images[:(24-batch)]) -+ images = torch.concat((images,pad), dim=0) -+ feed = [images.to(torch.float32)] -+ image_features = session_code.infer(feed) -+ image_features = torch.from_numpy(image_features[0][:batch,]) -+ image_features /= image_features.norm(dim=-1, keepdim=True) -+ logits = (100.0 * image_features @ classifier).softmax(dim=-1) -+ total_logits.append(logits) -+ -+ # measure accuracy -+ acc1, acc5 = accuracy(logits, target, topk=(1, 1)) -+ top1 += acc1 -+ n += batch - - outputs = torch.cat(total_logits, dim=0) - targets = torch.cat(total_targets, dim=0) -- - if getattr(args, "index", ""): - print("Use index to rearrange the logits...") - with open(args.index, "r", encoding="utf-8") as f: -@@ -166,16 +188,14 @@ - if __name__ == "__main__": - args = parse_args() - -+ text_model = args.text_om -+ vision_model = args.vision_om - # Log params. - print("Params:") - for name in sorted(vars(args)): - val = getattr(args, name) - print(f" {name}: {val}") - -- args.gpu = 0 -- torch.cuda.set_device(args.gpu) -- -- # Initialize the model. - vision_model_config_file = Path(__file__).parent.parent / f"clip/model_configs/{args.vision_model.replace('/', '-')}.json" - print('Loading vision model config from', vision_model_config_file) - assert os.path.exists(vision_model_config_file) -@@ -191,17 +211,6 @@ - for k, v in json.load(ft).items(): - model_info[k] = v - -- model = CLIP(**model_info) -- convert_weights(model) -- -- # See https://discuss.pytorch.org/t/valueerror-attemting-to-unscale-fp16-gradients/81372 -- if args.precision == "amp" or args.precision == "fp32": -- convert_models_to_fp32(model) -- model.cuda(args.gpu) -- if args.precision == "fp16": -- convert_weights(model) -- -- # Get eval data. - print("Preparing zeroshot dataset.") - data = {} - print(f"{model_info['image_resolution']}") -@@ -209,26 +218,8 @@ - args, image_transform(model_info["image_resolution"]) - ) - -- # Resume from a checkpoint. -- print("Begin to load model checkpoint from {}.".format(args.resume)) -- assert os.path.exists(args.resume), "The checkpoint file {} not exists!".format(args.resume) -- # Map model to be loaded to specified single gpu. -- loc = "cuda:{}".format(args.gpu) -- checkpoint = torch.load(args.resume, map_location='cpu') -- start_epoch = checkpoint["epoch"] -- sd = checkpoint["state_dict"] -- if next(iter(sd.items()))[0].startswith('module'): -- sd = {k[len('module.'):]: v for k, v in sd.items() if "bert.pooler" not in k} -- model.load_state_dict(sd) -- print( -- f"=> loaded checkpoint '{args.resume}' (epoch {checkpoint['epoch']} @ {checkpoint['step']} steps)" -- ) -- -- # Compute ensembled class embeddings - print('Building zero-shot classifier') - -- model.eval() -- - f = open(args.label_file, "r", encoding="utf8") - classnames = [line.strip() for line in f.readlines()] - -@@ -246,32 +237,10 @@ - else: - templates = template_dict['openai'] - -- # Make inference and evaluation - print('Using classifier') -- classifier = zero_shot_classifier(model, classnames, templates, args) -+ classifier = zero_shot_classifier(text_model, classnames, templates, args) - results = {} -- top1, logits = run(model, classifier, data[args.dataset].dataloader, args) -- -- def json_prec_dump(data, prec=6): -- return json.dumps( -- json.loads(json.dumps(data), parse_float=lambda x: round(float(x), prec)) -- ) -- -- print(logits.size()) -- output_dict = { -- "model_name": "CN-CLIP-" + args.vision_model, -- "dataset_name": args.dataset, -- "num_trainable_params": 0, -- "num_params": sum(x.numel() for x in model.parameters()), -- "num_visual_params": sum(x.numel() for x in model.visual.parameters()), -- "num_backbone_params": sum(x.numel() for x in model.parameters()), -- "n_shot": 0, -- "rnd_seeds": [123], -- "predictions": [logits.cpu().data.numpy().tolist()], -- } -- json_string = json_prec_dump(output_dict) -- with open(os.path.join(args.save_dir, f"{args.dataset}.json"), "w", encoding="utf-8") as w: -- w.write(json_string) -+ top1, logits = run(vision_model, classifier, data[args.dataset].dataloader, args) - - results["zeroshot-top1"] = top1 - -diff -Nur b/Chinese-CLIP/.git/config a/Chinese-CLIP/.git/config ---- b/Chinese-CLIP/.git/config 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/config 1970-01-01 00:00:00.000000000 +0000 -@@ -1,11 +0,0 @@ --[core] -- repositoryformatversion = 0 -- filemode = true -- bare = false -- logallrefupdates = true --[remote "origin"] -- url = https://github.com/OFA-Sys/Chinese-CLIP.git -- fetch = +refs/heads/*:refs/remotes/origin/* --[branch "master"] -- remote = origin -- merge = refs/heads/master -diff -Nur b/Chinese-CLIP/.git/description a/Chinese-CLIP/.git/description ---- b/Chinese-CLIP/.git/description 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/description 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --Unnamed repository; edit this file 'description' to name the repository. -diff -Nur b/Chinese-CLIP/.git/HEAD a/Chinese-CLIP/.git/HEAD ---- b/Chinese-CLIP/.git/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --ref: refs/heads/master -diff -Nur b/Chinese-CLIP/.git/hooks/applypatch-msg.sample a/Chinese-CLIP/.git/hooks/applypatch-msg.sample ---- b/Chinese-CLIP/.git/hooks/applypatch-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/applypatch-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,15 +0,0 @@ --#!/bin/sh --# --# An example hook script to check the commit log message taken by --# applypatch from an e-mail message. --# --# The hook should exit with non-zero status after issuing an --# appropriate message if it wants to stop the commit. The hook is --# allowed to edit the commit message file. --# --# To enable this hook, rename this file to "applypatch-msg". -- --. git-sh-setup --commitmsg="$(git rev-parse --git-path hooks/commit-msg)" --test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} --: -diff -Nur b/Chinese-CLIP/.git/hooks/commit-msg.sample a/Chinese-CLIP/.git/hooks/commit-msg.sample ---- b/Chinese-CLIP/.git/hooks/commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,24 +0,0 @@ --#!/bin/sh --# --# An example hook script to check the commit log message. --# Called by "git commit" with one argument, the name of the file --# that has the commit message. The hook should exit with non-zero --# status after issuing an appropriate message if it wants to stop the --# commit. The hook is allowed to edit the commit message file. --# --# To enable this hook, rename this file to "commit-msg". -- --# Uncomment the below to add a Signed-off-by line to the message. --# Doing this in a hook is a bad idea in general, but the prepare-commit-msg --# hook is more suited to it. --# --# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') --# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" -- --# This example catches duplicate Signed-off-by lines. -- --test "" = "$(grep '^Signed-off-by: ' "$1" | -- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { -- echo >&2 Duplicate Signed-off-by lines. -- exit 1 --} -diff -Nur b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample ---- b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,109 +0,0 @@ --#!/usr/bin/perl -- --use strict; --use warnings; --use IPC::Open2; -- --# An example hook script to integrate Watchman --# (https://facebook.github.io/watchman/) with git to speed up detecting --# new and modified files. --# --# The hook is passed a version (currently 1) and a time in nanoseconds --# formatted as a string and outputs to stdout all files that have been --# modified since the given time. Paths must be relative to the root of --# the working tree and separated by a single NUL. --# --# To enable this hook, rename this file to "query-watchman" and set --# 'git config core.fsmonitor .git/hooks/query-watchman' --# --my ($version, $time) = @ARGV; -- --# Check the hook interface version -- --if ($version == 1) { -- # convert nanoseconds to seconds -- # subtract one second to make sure watchman will return all changes -- $time = int ($time / 1000000000) - 1; --} else { -- die "Unsupported query-fsmonitor hook version '$version'.\n" . -- "Falling back to scanning...\n"; --} -- --my $git_work_tree; --if ($^O =~ 'msys' || $^O =~ 'cygwin') { -- $git_work_tree = Win32::GetCwd(); -- $git_work_tree =~ tr/\\/\//; --} else { -- require Cwd; -- $git_work_tree = Cwd::cwd(); --} -- --my $retry = 1; -- --launch_watchman(); -- --sub launch_watchman { -- -- my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') -- or die "open2() failed: $!\n" . -- "Falling back to scanning...\n"; -- -- # In the query expression below we're asking for names of files that -- # changed since $time but were not transient (ie created after -- # $time but no longer exist). -- # -- # To accomplish this, we're using the "since" generator to use the -- # recency index to select candidate nodes and "fields" to limit the -- # output to file names only. -- -- my $query = <<" END"; -- ["query", "$git_work_tree", { -- "since": $time, -- "fields": ["name"] -- }] -- END -- -- print CHLD_IN $query; -- close CHLD_IN; -- my $response = do {local $/; }; -- -- die "Watchman: command returned no output.\n" . -- "Falling back to scanning...\n" if $response eq ""; -- die "Watchman: command returned invalid output: $response\n" . -- "Falling back to scanning...\n" unless $response =~ /^\{/; -- -- my $json_pkg; -- eval { -- require JSON::XS; -- $json_pkg = "JSON::XS"; -- 1; -- } or do { -- require JSON::PP; -- $json_pkg = "JSON::PP"; -- }; -- -- my $o = $json_pkg->new->utf8->decode($response); -- -- if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { -- print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; -- $retry--; -- qx/watchman watch "$git_work_tree"/; -- die "Failed to make watchman watch '$git_work_tree'.\n" . -- "Falling back to scanning...\n" if $? != 0; -- -- # Watchman will always return all files on the first query so -- # return the fast "everything is dirty" flag to git and do the -- # Watchman query just to get it over with now so we won't pay -- # the cost in git to look up each individual file. -- print "/\0"; -- eval { launch_watchman() }; -- exit 0; -- } -- -- die "Watchman: $o->{error}.\n" . -- "Falling back to scanning...\n" if $o->{error}; -- -- binmode STDOUT, ":utf8"; -- local $, = "\0"; -- print @{$o->{files}}; --} -diff -Nur b/Chinese-CLIP/.git/hooks/post-update.sample a/Chinese-CLIP/.git/hooks/post-update.sample ---- b/Chinese-CLIP/.git/hooks/post-update.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/post-update.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,8 +0,0 @@ --#!/bin/sh --# --# An example hook script to prepare a packed repository for use over --# dumb transports. --# --# To enable this hook, rename this file to "post-update". -- --exec git update-server-info -diff -Nur b/Chinese-CLIP/.git/hooks/pre-applypatch.sample a/Chinese-CLIP/.git/hooks/pre-applypatch.sample ---- b/Chinese-CLIP/.git/hooks/pre-applypatch.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-applypatch.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,14 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed --# by applypatch from an e-mail message. --# --# The hook should exit with non-zero status after issuing an --# appropriate message if it wants to stop the commit. --# --# To enable this hook, rename this file to "pre-applypatch". -- --. git-sh-setup --precommit="$(git rev-parse --git-path hooks/pre-commit)" --test -x "$precommit" && exec "$precommit" ${1+"$@"} --: -diff -Nur b/Chinese-CLIP/.git/hooks/pre-commit.sample a/Chinese-CLIP/.git/hooks/pre-commit.sample ---- b/Chinese-CLIP/.git/hooks/pre-commit.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,49 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed. --# Called by "git commit" with no arguments. The hook should --# exit with non-zero status after issuing an appropriate message if --# it wants to stop the commit. --# --# To enable this hook, rename this file to "pre-commit". -- --if git rev-parse --verify HEAD >/dev/null 2>&1 --then -- against=HEAD --else -- # Initial commit: diff against an empty tree object -- against=$(git hash-object -t tree /dev/null) --fi -- --# If you want to allow non-ASCII filenames set this variable to true. --allownonascii=$(git config --bool hooks.allownonascii) -- --# Redirect output to stderr. --exec 1>&2 -- --# Cross platform projects tend to avoid non-ASCII filenames; prevent --# them from being added to the repository. We exploit the fact that the --# printable range starts at the space character and ends with tilde. --if [ "$allownonascii" != "true" ] && -- # Note that the use of brackets around a tr range is ok here, (it's -- # even required, for portability to Solaris 10's /usr/bin/tr), since -- # the square bracket bytes happen to fall in the designated range. -- test $(git diff --cached --name-only --diff-filter=A -z $against | -- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 --then -- cat <<\EOF --Error: Attempt to add a non-ASCII file name. -- --This can cause problems if you want to work with people on other platforms. -- --To be portable it is advisable to rename the file. -- --If you know what you are doing you can disable this check using: -- -- git config hooks.allownonascii true --EOF -- exit 1 --fi -- --# If there are whitespace errors, print the offending file names and fail. --exec git diff-index --check --cached $against -- -diff -Nur b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample ---- b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,13 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed. --# Called by "git merge" with no arguments. The hook should --# exit with non-zero status after issuing an appropriate message to --# stderr if it wants to stop the merge commit. --# --# To enable this hook, rename this file to "pre-merge-commit". -- --. git-sh-setup --test -x "$GIT_DIR/hooks/pre-commit" && -- exec "$GIT_DIR/hooks/pre-commit" --: -diff -Nur b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample ---- b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,42 +0,0 @@ --#!/bin/sh --# --# An example hook script to prepare the commit log message. --# Called by "git commit" with the name of the file that has the --# commit message, followed by the description of the commit --# message's source. The hook's purpose is to edit the commit --# message file. If the hook fails with a non-zero status, --# the commit is aborted. --# --# To enable this hook, rename this file to "prepare-commit-msg". -- --# This hook includes three examples. The first one removes the --# "# Please enter the commit message..." help message. --# --# The second includes the output of "git diff --name-status -r" --# into the message, just before the "git status" output. It is --# commented because it doesn't cope with --amend or with squashed --# commits. --# --# The third example adds a Signed-off-by line to the message, that can --# still be edited. This is rarely a good idea. -- --COMMIT_MSG_FILE=$1 --COMMIT_SOURCE=$2 --SHA1=$3 -- --/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" -- --# case "$COMMIT_SOURCE,$SHA1" in --# ,|template,) --# /usr/bin/perl -i.bak -pe ' --# print "\n" . `git diff --cached --name-status -r` --# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; --# *) ;; --# esac -- --# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') --# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" --# if test -z "$COMMIT_SOURCE" --# then --# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" --# fi -diff -Nur b/Chinese-CLIP/.git/hooks/pre-push.sample a/Chinese-CLIP/.git/hooks/pre-push.sample ---- b/Chinese-CLIP/.git/hooks/pre-push.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-push.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,53 +0,0 @@ --#!/bin/sh -- --# An example hook script to verify what is about to be pushed. Called by "git --# push" after it has checked the remote status, but before anything has been --# pushed. If this script exits with a non-zero status nothing will be pushed. --# --# This hook is called with the following parameters: --# --# $1 -- Name of the remote to which the push is being done --# $2 -- URL to which the push is being done --# --# If pushing without using a named remote those arguments will be equal. --# --# Information about the commits which are being pushed is supplied as lines to --# the standard input in the form: --# --# --# --# This sample shows how to prevent push of commits where the log message starts --# with "WIP" (work in progress). -- --remote="$1" --url="$2" -- --z40=0000000000000000000000000000000000000000 -- --while read local_ref local_sha remote_ref remote_sha --do -- if [ "$local_sha" = $z40 ] -- then -- # Handle delete -- : -- else -- if [ "$remote_sha" = $z40 ] -- then -- # New branch, examine all commits -- range="$local_sha" -- else -- # Update to existing branch, examine new commits -- range="$remote_sha..$local_sha" -- fi -- -- # Check for WIP commit -- commit=`git rev-list -n 1 --grep '^WIP' "$range"` -- if [ -n "$commit" ] -- then -- echo >&2 "Found WIP commit in $local_ref, not pushing" -- exit 1 -- fi -- fi --done -- --exit 0 -diff -Nur b/Chinese-CLIP/.git/hooks/pre-rebase.sample a/Chinese-CLIP/.git/hooks/pre-rebase.sample ---- b/Chinese-CLIP/.git/hooks/pre-rebase.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-rebase.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,169 +0,0 @@ --#!/bin/sh --# --# Copyright (c) 2006, 2008 Junio C Hamano --# --# The "pre-rebase" hook is run just before "git rebase" starts doing --# its job, and can prevent the command from running by exiting with --# non-zero status. --# --# The hook is called with the following parameters: --# --# $1 -- the upstream the series was forked from. --# $2 -- the branch being rebased (or empty when rebasing the current branch). --# --# This sample shows how to prevent topic branches that are already --# merged to 'next' branch from getting rebased, because allowing it --# would result in rebasing already published history. -- --publish=next --basebranch="$1" --if test "$#" = 2 --then -- topic="refs/heads/$2" --else -- topic=`git symbolic-ref HEAD` || -- exit 0 ;# we do not interrupt rebasing detached HEAD --fi -- --case "$topic" in --refs/heads/??/*) -- ;; --*) -- exit 0 ;# we do not interrupt others. -- ;; --esac -- --# Now we are dealing with a topic branch being rebased --# on top of master. Is it OK to rebase it? -- --# Does the topic really exist? --git show-ref -q "$topic" || { -- echo >&2 "No such branch $topic" -- exit 1 --} -- --# Is topic fully merged to master? --not_in_master=`git rev-list --pretty=oneline ^master "$topic"` --if test -z "$not_in_master" --then -- echo >&2 "$topic is fully merged to master; better remove it." -- exit 1 ;# we could allow it, but there is no point. --fi -- --# Is topic ever merged to next? If so you should not be rebasing it. --only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` --only_next_2=`git rev-list ^master ${publish} | sort` --if test "$only_next_1" = "$only_next_2" --then -- not_in_topic=`git rev-list "^$topic" master` -- if test -z "$not_in_topic" -- then -- echo >&2 "$topic is already up to date with master" -- exit 1 ;# we could allow it, but there is no point. -- else -- exit 0 -- fi --else -- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` -- /usr/bin/perl -e ' -- my $topic = $ARGV[0]; -- my $msg = "* $topic has commits already merged to public branch:\n"; -- my (%not_in_next) = map { -- /^([0-9a-f]+) /; -- ($1 => 1); -- } split(/\n/, $ARGV[1]); -- for my $elem (map { -- /^([0-9a-f]+) (.*)$/; -- [$1 => $2]; -- } split(/\n/, $ARGV[2])) { -- if (!exists $not_in_next{$elem->[0]}) { -- if ($msg) { -- print STDERR $msg; -- undef $msg; -- } -- print STDERR " $elem->[1]\n"; -- } -- } -- ' "$topic" "$not_in_next" "$not_in_master" -- exit 1 --fi -- --<<\DOC_END -- --This sample hook safeguards topic branches that have been --published from being rewound. -- --The workflow assumed here is: -- -- * Once a topic branch forks from "master", "master" is never -- merged into it again (either directly or indirectly). -- -- * Once a topic branch is fully cooked and merged into "master", -- it is deleted. If you need to build on top of it to correct -- earlier mistakes, a new topic branch is created by forking at -- the tip of the "master". This is not strictly necessary, but -- it makes it easier to keep your history simple. -- -- * Whenever you need to test or publish your changes to topic -- branches, merge them into "next" branch. -- --The script, being an example, hardcodes the publish branch name --to be "next", but it is trivial to make it configurable via --$GIT_DIR/config mechanism. -- --With this workflow, you would want to know: -- --(1) ... if a topic branch has ever been merged to "next". Young -- topic branches can have stupid mistakes you would rather -- clean up before publishing, and things that have not been -- merged into other branches can be easily rebased without -- affecting other people. But once it is published, you would -- not want to rewind it. -- --(2) ... if a topic branch has been fully merged to "master". -- Then you can delete it. More importantly, you should not -- build on top of it -- other people may already want to -- change things related to the topic as patches against your -- "master", so if you need further changes, it is better to -- fork the topic (perhaps with the same name) afresh from the -- tip of "master". -- --Let's look at this example: -- -- o---o---o---o---o---o---o---o---o---o "next" -- / / / / -- / a---a---b A / / -- / / / / -- / / c---c---c---c B / -- / / / \ / -- / / / b---b C \ / -- / / / / \ / -- ---o---o---o---o---o---o---o---o---o---o---o "master" -- -- --A, B and C are topic branches. -- -- * A has one fix since it was merged up to "next". -- -- * B has finished. It has been fully merged up to "master" and "next", -- and is ready to be deleted. -- -- * C has not merged to "next" at all. -- --We would want to allow C to be rebased, refuse A, and encourage --B to be deleted. -- --To compute (1): -- -- git rev-list ^master ^topic next -- git rev-list ^master next -- -- if these match, topic has not merged in next at all. -- --To compute (2): -- -- git rev-list master..topic -- -- if this is empty, it is fully merged to "master". -- --DOC_END -diff -Nur b/Chinese-CLIP/.git/hooks/pre-receive.sample a/Chinese-CLIP/.git/hooks/pre-receive.sample ---- b/Chinese-CLIP/.git/hooks/pre-receive.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-receive.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,24 +0,0 @@ --#!/bin/sh --# --# An example hook script to make use of push options. --# The example simply echoes all push options that start with 'echoback=' --# and rejects all pushes when the "reject" push option is used. --# --# To enable this hook, rename this file to "pre-receive". -- --if test -n "$GIT_PUSH_OPTION_COUNT" --then -- i=0 -- while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" -- do -- eval "value=\$GIT_PUSH_OPTION_$i" -- case "$value" in -- echoback=*) -- echo "echo from the pre-receive-hook: ${value#*=}" >&2 -- ;; -- reject) -- exit 1 -- esac -- i=$((i + 1)) -- done --fi -diff -Nur b/Chinese-CLIP/.git/hooks/update.sample a/Chinese-CLIP/.git/hooks/update.sample ---- b/Chinese-CLIP/.git/hooks/update.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/update.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,128 +0,0 @@ --#!/bin/sh --# --# An example hook script to block unannotated tags from entering. --# Called by "git receive-pack" with arguments: refname sha1-old sha1-new --# --# To enable this hook, rename this file to "update". --# --# Config --# ------ --# hooks.allowunannotated --# This boolean sets whether unannotated tags will be allowed into the --# repository. By default they won't be. --# hooks.allowdeletetag --# This boolean sets whether deleting tags will be allowed in the --# repository. By default they won't be. --# hooks.allowmodifytag --# This boolean sets whether a tag may be modified after creation. By default --# it won't be. --# hooks.allowdeletebranch --# This boolean sets whether deleting branches will be allowed in the --# repository. By default they won't be. --# hooks.denycreatebranch --# This boolean sets whether remotely creating branches will be denied --# in the repository. By default this is allowed. --# -- --# --- Command line --refname="$1" --oldrev="$2" --newrev="$3" -- --# --- Safety check --if [ -z "$GIT_DIR" ]; then -- echo "Don't run this script from the command line." >&2 -- echo " (if you want, you could supply GIT_DIR then run" >&2 -- echo " $0 )" >&2 -- exit 1 --fi -- --if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then -- echo "usage: $0 " >&2 -- exit 1 --fi -- --# --- Config --allowunannotated=$(git config --bool hooks.allowunannotated) --allowdeletebranch=$(git config --bool hooks.allowdeletebranch) --denycreatebranch=$(git config --bool hooks.denycreatebranch) --allowdeletetag=$(git config --bool hooks.allowdeletetag) --allowmodifytag=$(git config --bool hooks.allowmodifytag) -- --# check for no description --projectdesc=$(sed -e '1q' "$GIT_DIR/description") --case "$projectdesc" in --"Unnamed repository"* | "") -- echo "*** Project description file hasn't been set" >&2 -- exit 1 -- ;; --esac -- --# --- Check types --# if $newrev is 0000...0000, it's a commit to delete a ref. --zero="0000000000000000000000000000000000000000" --if [ "$newrev" = "$zero" ]; then -- newrev_type=delete --else -- newrev_type=$(git cat-file -t $newrev) --fi -- --case "$refname","$newrev_type" in -- refs/tags/*,commit) -- # un-annotated tag -- short_refname=${refname##refs/tags/} -- if [ "$allowunannotated" != "true" ]; then -- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 -- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 -- exit 1 -- fi -- ;; -- refs/tags/*,delete) -- # delete tag -- if [ "$allowdeletetag" != "true" ]; then -- echo "*** Deleting a tag is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/tags/*,tag) -- # annotated tag -- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 -- then -- echo "*** Tag '$refname' already exists." >&2 -- echo "*** Modifying a tag is not allowed in this repository." >&2 -- exit 1 -- fi -- ;; -- refs/heads/*,commit) -- # branch -- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then -- echo "*** Creating a branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/heads/*,delete) -- # delete branch -- if [ "$allowdeletebranch" != "true" ]; then -- echo "*** Deleting a branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/remotes/*,commit) -- # tracking branch -- ;; -- refs/remotes/*,delete) -- # delete tracking branch -- if [ "$allowdeletebranch" != "true" ]; then -- echo "*** Deleting a tracking branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- *) -- # Anything else (is there anything else?) -- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 -- exit 1 -- ;; --esac -- --# --- Finished --exit 0 -Binary files b/Chinese-CLIP/.git/index and a/Chinese-CLIP/.git/index differ -diff -Nur b/Chinese-CLIP/.git/info/exclude a/Chinese-CLIP/.git/info/exclude ---- b/Chinese-CLIP/.git/info/exclude 2024-08-07 10:13:19.416000000 +0000 -+++ a/Chinese-CLIP/.git/info/exclude 1970-01-01 00:00:00.000000000 +0000 -@@ -1,6 +0,0 @@ --# git ls-files --others --exclude-from=.git/info/exclude --# Lines that start with '#' are comments. --# For a project mostly in C, the following would be a good set of --# exclude patterns (uncomment them if you want to use them): --# *.[oa] --# *~ -diff -Nur b/Chinese-CLIP/.git/logs/HEAD a/Chinese-CLIP/.git/logs/HEAD ---- b/Chinese-CLIP/.git/logs/HEAD 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/logs/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1,2 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git --85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/logs/refs/heads/master a/Chinese-CLIP/.git/logs/refs/heads/master ---- b/Chinese-CLIP/.git/logs/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/logs/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 -@@ -1,2 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git --85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD ---- b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git -Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx differ -Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack differ -diff -Nur b/Chinese-CLIP/.git/ORIG_HEAD a/Chinese-CLIP/.git/ORIG_HEAD ---- b/Chinese-CLIP/.git/ORIG_HEAD 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/ORIG_HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --85f3fa3639e207d0b76f69a401105cad5d509593 -diff -Nur b/Chinese-CLIP/.git/packed-refs a/Chinese-CLIP/.git/packed-refs ---- b/Chinese-CLIP/.git/packed-refs 2024-08-07 10:13:21.616000000 +0000 -+++ a/Chinese-CLIP/.git/packed-refs 1970-01-01 00:00:00.000000000 +0000 -@@ -1,4 +0,0 @@ --# pack-refs with: peeled fully-peeled sorted --8f7d051435adefb5d662a74072e76e838c0f7ce7 refs/remotes/origin/jr_dev --704a53d80e2192b9c9f1db2b86ee2f47305f10b4 refs/remotes/origin/jxst539246-patch-1 --85f3fa3639e207d0b76f69a401105cad5d509593 refs/remotes/origin/master -diff -Nur b/Chinese-CLIP/.git/refs/heads/master a/Chinese-CLIP/.git/refs/heads/master ---- b/Chinese-CLIP/.git/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/refs/remotes/origin/HEAD ---- b/Chinese-CLIP/.git/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --ref: refs/remotes/origin/master -diff -Nur b/Chinese-CLIP/run_scripts/zeroshot_eval.sh a/Chinese-CLIP/run_scripts/zeroshot_eval.sh ---- b/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:13:21.656000000 +0000 -+++ a/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:07:22.108000000 +0000 -@@ -18,7 +18,9 @@ - text_model=${5} - resume=${6} - label_file=${path}/datasets/${dataset}/label_cn.txt --index=${7:-} -+text_om=${7} -+vision_om=${8} -+index=${9:-} - - mkdir -p ${savedir} - -@@ -28,7 +30,9 @@ - --save-dir=${savedir} \ - --dataset=${dataset} \ - --index=${index} \ -- --img-batch-size=64 \ -+ --img-batch-size=24 \ - --resume=${resume} \ - --vision-model=${vision_model} \ -- --text-model=${text_model} -+ --text-model=${text_model} \ -+ --text-om=${text_om} \ -+ --vision-om=${vision_om} -diff -Nur b/cn_clip.patch a/cn_clip.patch ---- b/cn_clip.patch 1970-01-01 00:00:00.000000000 +0000 -+++ a/cn_clip.patch 2024-08-07 01:17:26.048000000 +0000 -@@ -0,0 +1,26 @@ -+diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.py -+--- cn_clip/deploy/pytorch_to_onnx.py 2024-02-20 14:49:36.955252200 +0800 -++++ cn_clip_fix/deploy/pytorch_to_onnx.py 2024-03-17 14:48:30.339636500 +0800 -+@@ -117,8 +117,9 @@ -+ text_fp32_onnx_path, -+ input_names=['text'], -+ output_names=['unnorm_text_features'], -++ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, -+ export_params=True, -+- opset_version=13, -++ opset_version=11, -+ verbose=True) -+ # convert text FP16 ONNX model based on the FP32 model -+ text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" -+@@ -141,9 +142,10 @@ -+ vision_fp32_onnx_path, -+ input_names=['image'], -+ output_names=['unnorm_image_features'], -++ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, -+ export_params=True, -+ do_constant_folding=False, -+- opset_version=13, -++ opset_version=11, -+ verbose=True) -+ # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files -+ if args.model_arch == "ViT-H-14": -- Gitee From 3c722205b21a76a406c2458b29e1f25ed01859c9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 8 Aug 2024 10:57:15 +0000 Subject: [PATCH 3/4] bug fix --- .../foundation_models/Chinese_CLIP/README.md | 4 +- .../Chinese_CLIP/cn_clip.patch | 804 ------------------ .../Chinese_CLIP/opt_img_onnx.py | 4 +- .../Chinese_CLIP/opt_txt_onnx.py | 27 +- 4 files changed, 20 insertions(+), 819 deletions(-) diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md index ff9f55836e..26c1b40d53 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md @@ -273,8 +273,8 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 ``` cd Chinese-CLIP - export vision_om=${vit-b-16.img.bs24.om模型的绝对路径} - export text_om=${vit-b-16.txt.bs24.om模型的绝对路径} + export vision_om=../models/vit-b-16.img.bs24.om + export text_om=../models/vit-b-16.txt.bs24.om bash run_scripts/zeroshot_eval.sh 0 data cifar-100 ViT-B-16 RoBERTa-wwm-ext-base-chinese ../models/clip_cn_vit-b-16.pt ${text_om} ${vision_om} cd .. ``` diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch index 2cc6b40803..cd5f927879 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/cn_clip.patch @@ -245,780 +245,6 @@ diff -Nur b/Chinese-CLIP/cn_clip/eval/zeroshot_evaluation.py a/Chinese-CLIP/cn_c results["zeroshot-top1"] = top1 -diff -Nur b/Chinese-CLIP/.git/config a/Chinese-CLIP/.git/config ---- b/Chinese-CLIP/.git/config 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/config 1970-01-01 00:00:00.000000000 +0000 -@@ -1,11 +0,0 @@ --[core] -- repositoryformatversion = 0 -- filemode = true -- bare = false -- logallrefupdates = true --[remote "origin"] -- url = https://github.com/OFA-Sys/Chinese-CLIP.git -- fetch = +refs/heads/*:refs/remotes/origin/* --[branch "master"] -- remote = origin -- merge = refs/heads/master -diff -Nur b/Chinese-CLIP/.git/description a/Chinese-CLIP/.git/description ---- b/Chinese-CLIP/.git/description 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/description 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --Unnamed repository; edit this file 'description' to name the repository. -diff -Nur b/Chinese-CLIP/.git/HEAD a/Chinese-CLIP/.git/HEAD ---- b/Chinese-CLIP/.git/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --ref: refs/heads/master -diff -Nur b/Chinese-CLIP/.git/hooks/applypatch-msg.sample a/Chinese-CLIP/.git/hooks/applypatch-msg.sample ---- b/Chinese-CLIP/.git/hooks/applypatch-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/applypatch-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,15 +0,0 @@ --#!/bin/sh --# --# An example hook script to check the commit log message taken by --# applypatch from an e-mail message. --# --# The hook should exit with non-zero status after issuing an --# appropriate message if it wants to stop the commit. The hook is --# allowed to edit the commit message file. --# --# To enable this hook, rename this file to "applypatch-msg". -- --. git-sh-setup --commitmsg="$(git rev-parse --git-path hooks/commit-msg)" --test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} --: -diff -Nur b/Chinese-CLIP/.git/hooks/commit-msg.sample a/Chinese-CLIP/.git/hooks/commit-msg.sample ---- b/Chinese-CLIP/.git/hooks/commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,24 +0,0 @@ --#!/bin/sh --# --# An example hook script to check the commit log message. --# Called by "git commit" with one argument, the name of the file --# that has the commit message. The hook should exit with non-zero --# status after issuing an appropriate message if it wants to stop the --# commit. The hook is allowed to edit the commit message file. --# --# To enable this hook, rename this file to "commit-msg". -- --# Uncomment the below to add a Signed-off-by line to the message. --# Doing this in a hook is a bad idea in general, but the prepare-commit-msg --# hook is more suited to it. --# --# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') --# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" -- --# This example catches duplicate Signed-off-by lines. -- --test "" = "$(grep '^Signed-off-by: ' "$1" | -- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { -- echo >&2 Duplicate Signed-off-by lines. -- exit 1 --} -diff -Nur b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample ---- b/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/fsmonitor-watchman.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,109 +0,0 @@ --#!/usr/bin/perl -- --use strict; --use warnings; --use IPC::Open2; -- --# An example hook script to integrate Watchman --# (https://facebook.github.io/watchman/) with git to speed up detecting --# new and modified files. --# --# The hook is passed a version (currently 1) and a time in nanoseconds --# formatted as a string and outputs to stdout all files that have been --# modified since the given time. Paths must be relative to the root of --# the working tree and separated by a single NUL. --# --# To enable this hook, rename this file to "query-watchman" and set --# 'git config core.fsmonitor .git/hooks/query-watchman' --# --my ($version, $time) = @ARGV; -- --# Check the hook interface version -- --if ($version == 1) { -- # convert nanoseconds to seconds -- # subtract one second to make sure watchman will return all changes -- $time = int ($time / 1000000000) - 1; --} else { -- die "Unsupported query-fsmonitor hook version '$version'.\n" . -- "Falling back to scanning...\n"; --} -- --my $git_work_tree; --if ($^O =~ 'msys' || $^O =~ 'cygwin') { -- $git_work_tree = Win32::GetCwd(); -- $git_work_tree =~ tr/\\/\//; --} else { -- require Cwd; -- $git_work_tree = Cwd::cwd(); --} -- --my $retry = 1; -- --launch_watchman(); -- --sub launch_watchman { -- -- my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') -- or die "open2() failed: $!\n" . -- "Falling back to scanning...\n"; -- -- # In the query expression below we're asking for names of files that -- # changed since $time but were not transient (ie created after -- # $time but no longer exist). -- # -- # To accomplish this, we're using the "since" generator to use the -- # recency index to select candidate nodes and "fields" to limit the -- # output to file names only. -- -- my $query = <<" END"; -- ["query", "$git_work_tree", { -- "since": $time, -- "fields": ["name"] -- }] -- END -- -- print CHLD_IN $query; -- close CHLD_IN; -- my $response = do {local $/; }; -- -- die "Watchman: command returned no output.\n" . -- "Falling back to scanning...\n" if $response eq ""; -- die "Watchman: command returned invalid output: $response\n" . -- "Falling back to scanning...\n" unless $response =~ /^\{/; -- -- my $json_pkg; -- eval { -- require JSON::XS; -- $json_pkg = "JSON::XS"; -- 1; -- } or do { -- require JSON::PP; -- $json_pkg = "JSON::PP"; -- }; -- -- my $o = $json_pkg->new->utf8->decode($response); -- -- if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { -- print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; -- $retry--; -- qx/watchman watch "$git_work_tree"/; -- die "Failed to make watchman watch '$git_work_tree'.\n" . -- "Falling back to scanning...\n" if $? != 0; -- -- # Watchman will always return all files on the first query so -- # return the fast "everything is dirty" flag to git and do the -- # Watchman query just to get it over with now so we won't pay -- # the cost in git to look up each individual file. -- print "/\0"; -- eval { launch_watchman() }; -- exit 0; -- } -- -- die "Watchman: $o->{error}.\n" . -- "Falling back to scanning...\n" if $o->{error}; -- -- binmode STDOUT, ":utf8"; -- local $, = "\0"; -- print @{$o->{files}}; --} -diff -Nur b/Chinese-CLIP/.git/hooks/post-update.sample a/Chinese-CLIP/.git/hooks/post-update.sample ---- b/Chinese-CLIP/.git/hooks/post-update.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/post-update.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,8 +0,0 @@ --#!/bin/sh --# --# An example hook script to prepare a packed repository for use over --# dumb transports. --# --# To enable this hook, rename this file to "post-update". -- --exec git update-server-info -diff -Nur b/Chinese-CLIP/.git/hooks/pre-applypatch.sample a/Chinese-CLIP/.git/hooks/pre-applypatch.sample ---- b/Chinese-CLIP/.git/hooks/pre-applypatch.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-applypatch.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,14 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed --# by applypatch from an e-mail message. --# --# The hook should exit with non-zero status after issuing an --# appropriate message if it wants to stop the commit. --# --# To enable this hook, rename this file to "pre-applypatch". -- --. git-sh-setup --precommit="$(git rev-parse --git-path hooks/pre-commit)" --test -x "$precommit" && exec "$precommit" ${1+"$@"} --: -diff -Nur b/Chinese-CLIP/.git/hooks/pre-commit.sample a/Chinese-CLIP/.git/hooks/pre-commit.sample ---- b/Chinese-CLIP/.git/hooks/pre-commit.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-commit.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,49 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed. --# Called by "git commit" with no arguments. The hook should --# exit with non-zero status after issuing an appropriate message if --# it wants to stop the commit. --# --# To enable this hook, rename this file to "pre-commit". -- --if git rev-parse --verify HEAD >/dev/null 2>&1 --then -- against=HEAD --else -- # Initial commit: diff against an empty tree object -- against=$(git hash-object -t tree /dev/null) --fi -- --# If you want to allow non-ASCII filenames set this variable to true. --allownonascii=$(git config --bool hooks.allownonascii) -- --# Redirect output to stderr. --exec 1>&2 -- --# Cross platform projects tend to avoid non-ASCII filenames; prevent --# them from being added to the repository. We exploit the fact that the --# printable range starts at the space character and ends with tilde. --if [ "$allownonascii" != "true" ] && -- # Note that the use of brackets around a tr range is ok here, (it's -- # even required, for portability to Solaris 10's /usr/bin/tr), since -- # the square bracket bytes happen to fall in the designated range. -- test $(git diff --cached --name-only --diff-filter=A -z $against | -- LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 --then -- cat <<\EOF --Error: Attempt to add a non-ASCII file name. -- --This can cause problems if you want to work with people on other platforms. -- --To be portable it is advisable to rename the file. -- --If you know what you are doing you can disable this check using: -- -- git config hooks.allownonascii true --EOF -- exit 1 --fi -- --# If there are whitespace errors, print the offending file names and fail. --exec git diff-index --check --cached $against -- -diff -Nur b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample ---- b/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-merge-commit.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,13 +0,0 @@ --#!/bin/sh --# --# An example hook script to verify what is about to be committed. --# Called by "git merge" with no arguments. The hook should --# exit with non-zero status after issuing an appropriate message to --# stderr if it wants to stop the merge commit. --# --# To enable this hook, rename this file to "pre-merge-commit". -- --. git-sh-setup --test -x "$GIT_DIR/hooks/pre-commit" && -- exec "$GIT_DIR/hooks/pre-commit" --: -diff -Nur b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample ---- b/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/prepare-commit-msg.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,42 +0,0 @@ --#!/bin/sh --# --# An example hook script to prepare the commit log message. --# Called by "git commit" with the name of the file that has the --# commit message, followed by the description of the commit --# message's source. The hook's purpose is to edit the commit --# message file. If the hook fails with a non-zero status, --# the commit is aborted. --# --# To enable this hook, rename this file to "prepare-commit-msg". -- --# This hook includes three examples. The first one removes the --# "# Please enter the commit message..." help message. --# --# The second includes the output of "git diff --name-status -r" --# into the message, just before the "git status" output. It is --# commented because it doesn't cope with --amend or with squashed --# commits. --# --# The third example adds a Signed-off-by line to the message, that can --# still be edited. This is rarely a good idea. -- --COMMIT_MSG_FILE=$1 --COMMIT_SOURCE=$2 --SHA1=$3 -- --/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" -- --# case "$COMMIT_SOURCE,$SHA1" in --# ,|template,) --# /usr/bin/perl -i.bak -pe ' --# print "\n" . `git diff --cached --name-status -r` --# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; --# *) ;; --# esac -- --# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') --# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" --# if test -z "$COMMIT_SOURCE" --# then --# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" --# fi -diff -Nur b/Chinese-CLIP/.git/hooks/pre-push.sample a/Chinese-CLIP/.git/hooks/pre-push.sample ---- b/Chinese-CLIP/.git/hooks/pre-push.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-push.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,53 +0,0 @@ --#!/bin/sh -- --# An example hook script to verify what is about to be pushed. Called by "git --# push" after it has checked the remote status, but before anything has been --# pushed. If this script exits with a non-zero status nothing will be pushed. --# --# This hook is called with the following parameters: --# --# $1 -- Name of the remote to which the push is being done --# $2 -- URL to which the push is being done --# --# If pushing without using a named remote those arguments will be equal. --# --# Information about the commits which are being pushed is supplied as lines to --# the standard input in the form: --# --# --# --# This sample shows how to prevent push of commits where the log message starts --# with "WIP" (work in progress). -- --remote="$1" --url="$2" -- --z40=0000000000000000000000000000000000000000 -- --while read local_ref local_sha remote_ref remote_sha --do -- if [ "$local_sha" = $z40 ] -- then -- # Handle delete -- : -- else -- if [ "$remote_sha" = $z40 ] -- then -- # New branch, examine all commits -- range="$local_sha" -- else -- # Update to existing branch, examine new commits -- range="$remote_sha..$local_sha" -- fi -- -- # Check for WIP commit -- commit=`git rev-list -n 1 --grep '^WIP' "$range"` -- if [ -n "$commit" ] -- then -- echo >&2 "Found WIP commit in $local_ref, not pushing" -- exit 1 -- fi -- fi --done -- --exit 0 -diff -Nur b/Chinese-CLIP/.git/hooks/pre-rebase.sample a/Chinese-CLIP/.git/hooks/pre-rebase.sample ---- b/Chinese-CLIP/.git/hooks/pre-rebase.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-rebase.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,169 +0,0 @@ --#!/bin/sh --# --# Copyright (c) 2006, 2008 Junio C Hamano --# --# The "pre-rebase" hook is run just before "git rebase" starts doing --# its job, and can prevent the command from running by exiting with --# non-zero status. --# --# The hook is called with the following parameters: --# --# $1 -- the upstream the series was forked from. --# $2 -- the branch being rebased (or empty when rebasing the current branch). --# --# This sample shows how to prevent topic branches that are already --# merged to 'next' branch from getting rebased, because allowing it --# would result in rebasing already published history. -- --publish=next --basebranch="$1" --if test "$#" = 2 --then -- topic="refs/heads/$2" --else -- topic=`git symbolic-ref HEAD` || -- exit 0 ;# we do not interrupt rebasing detached HEAD --fi -- --case "$topic" in --refs/heads/??/*) -- ;; --*) -- exit 0 ;# we do not interrupt others. -- ;; --esac -- --# Now we are dealing with a topic branch being rebased --# on top of master. Is it OK to rebase it? -- --# Does the topic really exist? --git show-ref -q "$topic" || { -- echo >&2 "No such branch $topic" -- exit 1 --} -- --# Is topic fully merged to master? --not_in_master=`git rev-list --pretty=oneline ^master "$topic"` --if test -z "$not_in_master" --then -- echo >&2 "$topic is fully merged to master; better remove it." -- exit 1 ;# we could allow it, but there is no point. --fi -- --# Is topic ever merged to next? If so you should not be rebasing it. --only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` --only_next_2=`git rev-list ^master ${publish} | sort` --if test "$only_next_1" = "$only_next_2" --then -- not_in_topic=`git rev-list "^$topic" master` -- if test -z "$not_in_topic" -- then -- echo >&2 "$topic is already up to date with master" -- exit 1 ;# we could allow it, but there is no point. -- else -- exit 0 -- fi --else -- not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` -- /usr/bin/perl -e ' -- my $topic = $ARGV[0]; -- my $msg = "* $topic has commits already merged to public branch:\n"; -- my (%not_in_next) = map { -- /^([0-9a-f]+) /; -- ($1 => 1); -- } split(/\n/, $ARGV[1]); -- for my $elem (map { -- /^([0-9a-f]+) (.*)$/; -- [$1 => $2]; -- } split(/\n/, $ARGV[2])) { -- if (!exists $not_in_next{$elem->[0]}) { -- if ($msg) { -- print STDERR $msg; -- undef $msg; -- } -- print STDERR " $elem->[1]\n"; -- } -- } -- ' "$topic" "$not_in_next" "$not_in_master" -- exit 1 --fi -- --<<\DOC_END -- --This sample hook safeguards topic branches that have been --published from being rewound. -- --The workflow assumed here is: -- -- * Once a topic branch forks from "master", "master" is never -- merged into it again (either directly or indirectly). -- -- * Once a topic branch is fully cooked and merged into "master", -- it is deleted. If you need to build on top of it to correct -- earlier mistakes, a new topic branch is created by forking at -- the tip of the "master". This is not strictly necessary, but -- it makes it easier to keep your history simple. -- -- * Whenever you need to test or publish your changes to topic -- branches, merge them into "next" branch. -- --The script, being an example, hardcodes the publish branch name --to be "next", but it is trivial to make it configurable via --$GIT_DIR/config mechanism. -- --With this workflow, you would want to know: -- --(1) ... if a topic branch has ever been merged to "next". Young -- topic branches can have stupid mistakes you would rather -- clean up before publishing, and things that have not been -- merged into other branches can be easily rebased without -- affecting other people. But once it is published, you would -- not want to rewind it. -- --(2) ... if a topic branch has been fully merged to "master". -- Then you can delete it. More importantly, you should not -- build on top of it -- other people may already want to -- change things related to the topic as patches against your -- "master", so if you need further changes, it is better to -- fork the topic (perhaps with the same name) afresh from the -- tip of "master". -- --Let's look at this example: -- -- o---o---o---o---o---o---o---o---o---o "next" -- / / / / -- / a---a---b A / / -- / / / / -- / / c---c---c---c B / -- / / / \ / -- / / / b---b C \ / -- / / / / \ / -- ---o---o---o---o---o---o---o---o---o---o---o "master" -- -- --A, B and C are topic branches. -- -- * A has one fix since it was merged up to "next". -- -- * B has finished. It has been fully merged up to "master" and "next", -- and is ready to be deleted. -- -- * C has not merged to "next" at all. -- --We would want to allow C to be rebased, refuse A, and encourage --B to be deleted. -- --To compute (1): -- -- git rev-list ^master ^topic next -- git rev-list ^master next -- -- if these match, topic has not merged in next at all. -- --To compute (2): -- -- git rev-list master..topic -- -- if this is empty, it is fully merged to "master". -- --DOC_END -diff -Nur b/Chinese-CLIP/.git/hooks/pre-receive.sample a/Chinese-CLIP/.git/hooks/pre-receive.sample ---- b/Chinese-CLIP/.git/hooks/pre-receive.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/pre-receive.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,24 +0,0 @@ --#!/bin/sh --# --# An example hook script to make use of push options. --# The example simply echoes all push options that start with 'echoback=' --# and rejects all pushes when the "reject" push option is used. --# --# To enable this hook, rename this file to "pre-receive". -- --if test -n "$GIT_PUSH_OPTION_COUNT" --then -- i=0 -- while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" -- do -- eval "value=\$GIT_PUSH_OPTION_$i" -- case "$value" in -- echoback=*) -- echo "echo from the pre-receive-hook: ${value#*=}" >&2 -- ;; -- reject) -- exit 1 -- esac -- i=$((i + 1)) -- done --fi -diff -Nur b/Chinese-CLIP/.git/hooks/update.sample a/Chinese-CLIP/.git/hooks/update.sample ---- b/Chinese-CLIP/.git/hooks/update.sample 2024-08-07 10:13:19.420000000 +0000 -+++ a/Chinese-CLIP/.git/hooks/update.sample 1970-01-01 00:00:00.000000000 +0000 -@@ -1,128 +0,0 @@ --#!/bin/sh --# --# An example hook script to block unannotated tags from entering. --# Called by "git receive-pack" with arguments: refname sha1-old sha1-new --# --# To enable this hook, rename this file to "update". --# --# Config --# ------ --# hooks.allowunannotated --# This boolean sets whether unannotated tags will be allowed into the --# repository. By default they won't be. --# hooks.allowdeletetag --# This boolean sets whether deleting tags will be allowed in the --# repository. By default they won't be. --# hooks.allowmodifytag --# This boolean sets whether a tag may be modified after creation. By default --# it won't be. --# hooks.allowdeletebranch --# This boolean sets whether deleting branches will be allowed in the --# repository. By default they won't be. --# hooks.denycreatebranch --# This boolean sets whether remotely creating branches will be denied --# in the repository. By default this is allowed. --# -- --# --- Command line --refname="$1" --oldrev="$2" --newrev="$3" -- --# --- Safety check --if [ -z "$GIT_DIR" ]; then -- echo "Don't run this script from the command line." >&2 -- echo " (if you want, you could supply GIT_DIR then run" >&2 -- echo " $0 )" >&2 -- exit 1 --fi -- --if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then -- echo "usage: $0 " >&2 -- exit 1 --fi -- --# --- Config --allowunannotated=$(git config --bool hooks.allowunannotated) --allowdeletebranch=$(git config --bool hooks.allowdeletebranch) --denycreatebranch=$(git config --bool hooks.denycreatebranch) --allowdeletetag=$(git config --bool hooks.allowdeletetag) --allowmodifytag=$(git config --bool hooks.allowmodifytag) -- --# check for no description --projectdesc=$(sed -e '1q' "$GIT_DIR/description") --case "$projectdesc" in --"Unnamed repository"* | "") -- echo "*** Project description file hasn't been set" >&2 -- exit 1 -- ;; --esac -- --# --- Check types --# if $newrev is 0000...0000, it's a commit to delete a ref. --zero="0000000000000000000000000000000000000000" --if [ "$newrev" = "$zero" ]; then -- newrev_type=delete --else -- newrev_type=$(git cat-file -t $newrev) --fi -- --case "$refname","$newrev_type" in -- refs/tags/*,commit) -- # un-annotated tag -- short_refname=${refname##refs/tags/} -- if [ "$allowunannotated" != "true" ]; then -- echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 -- echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 -- exit 1 -- fi -- ;; -- refs/tags/*,delete) -- # delete tag -- if [ "$allowdeletetag" != "true" ]; then -- echo "*** Deleting a tag is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/tags/*,tag) -- # annotated tag -- if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 -- then -- echo "*** Tag '$refname' already exists." >&2 -- echo "*** Modifying a tag is not allowed in this repository." >&2 -- exit 1 -- fi -- ;; -- refs/heads/*,commit) -- # branch -- if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then -- echo "*** Creating a branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/heads/*,delete) -- # delete branch -- if [ "$allowdeletebranch" != "true" ]; then -- echo "*** Deleting a branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- refs/remotes/*,commit) -- # tracking branch -- ;; -- refs/remotes/*,delete) -- # delete tracking branch -- if [ "$allowdeletebranch" != "true" ]; then -- echo "*** Deleting a tracking branch is not allowed in this repository" >&2 -- exit 1 -- fi -- ;; -- *) -- # Anything else (is there anything else?) -- echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 -- exit 1 -- ;; --esac -- --# --- Finished --exit 0 -Binary files b/Chinese-CLIP/.git/index and a/Chinese-CLIP/.git/index differ -diff -Nur b/Chinese-CLIP/.git/info/exclude a/Chinese-CLIP/.git/info/exclude ---- b/Chinese-CLIP/.git/info/exclude 2024-08-07 10:13:19.416000000 +0000 -+++ a/Chinese-CLIP/.git/info/exclude 1970-01-01 00:00:00.000000000 +0000 -@@ -1,6 +0,0 @@ --# git ls-files --others --exclude-from=.git/info/exclude --# Lines that start with '#' are comments. --# For a project mostly in C, the following would be a good set of --# exclude patterns (uncomment them if you want to use them): --# *.[oa] --# *~ -diff -Nur b/Chinese-CLIP/.git/logs/HEAD a/Chinese-CLIP/.git/logs/HEAD ---- b/Chinese-CLIP/.git/logs/HEAD 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/logs/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1,2 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git --85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/logs/refs/heads/master a/Chinese-CLIP/.git/logs/refs/heads/master ---- b/Chinese-CLIP/.git/logs/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/logs/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 -@@ -1,2 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git --85f3fa3639e207d0b76f69a401105cad5d509593 2c38d03557e50eadc72972b272cebf840dbc34ea root 1723025645 +0000 reset: moving to 2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD ---- b/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/logs/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --0000000000000000000000000000000000000000 85f3fa3639e207d0b76f69a401105cad5d509593 root 1723025601 +0000 clone: from https://github.com/OFA-Sys/Chinese-CLIP.git -Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.idx differ -Binary files b/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack and a/Chinese-CLIP/.git/objects/pack/pack-16fe3d00be17b9911e5f90d605ef3c107d7cfae9.pack differ -diff -Nur b/Chinese-CLIP/.git/ORIG_HEAD a/Chinese-CLIP/.git/ORIG_HEAD ---- b/Chinese-CLIP/.git/ORIG_HEAD 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/ORIG_HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --85f3fa3639e207d0b76f69a401105cad5d509593 -diff -Nur b/Chinese-CLIP/.git/packed-refs a/Chinese-CLIP/.git/packed-refs ---- b/Chinese-CLIP/.git/packed-refs 2024-08-07 10:13:21.616000000 +0000 -+++ a/Chinese-CLIP/.git/packed-refs 1970-01-01 00:00:00.000000000 +0000 -@@ -1,4 +0,0 @@ --# pack-refs with: peeled fully-peeled sorted --8f7d051435adefb5d662a74072e76e838c0f7ce7 refs/remotes/origin/jr_dev --704a53d80e2192b9c9f1db2b86ee2f47305f10b4 refs/remotes/origin/jxst539246-patch-1 --85f3fa3639e207d0b76f69a401105cad5d509593 refs/remotes/origin/master -diff -Nur b/Chinese-CLIP/.git/refs/heads/master a/Chinese-CLIP/.git/refs/heads/master ---- b/Chinese-CLIP/.git/refs/heads/master 2024-08-07 10:14:05.168000000 +0000 -+++ a/Chinese-CLIP/.git/refs/heads/master 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --2c38d03557e50eadc72972b272cebf840dbc34ea -diff -Nur b/Chinese-CLIP/.git/refs/remotes/origin/HEAD a/Chinese-CLIP/.git/refs/remotes/origin/HEAD ---- b/Chinese-CLIP/.git/refs/remotes/origin/HEAD 2024-08-07 10:13:21.620000000 +0000 -+++ a/Chinese-CLIP/.git/refs/remotes/origin/HEAD 1970-01-01 00:00:00.000000000 +0000 -@@ -1 +0,0 @@ --ref: refs/remotes/origin/master diff -Nur b/Chinese-CLIP/run_scripts/zeroshot_eval.sh a/Chinese-CLIP/run_scripts/zeroshot_eval.sh --- b/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:13:21.656000000 +0000 +++ a/Chinese-CLIP/run_scripts/zeroshot_eval.sh 2024-08-07 10:07:22.108000000 +0000 @@ -1045,33 +271,3 @@ diff -Nur b/Chinese-CLIP/run_scripts/zeroshot_eval.sh a/Chinese-CLIP/run_scripts + --text-model=${text_model} \ + --text-om=${text_om} \ + --vision-om=${vision_om} -diff -Nur b/cn_clip.patch a/cn_clip.patch ---- b/cn_clip.patch 1970-01-01 00:00:00.000000000 +0000 -+++ a/cn_clip.patch 2024-08-07 01:17:26.048000000 +0000 -@@ -0,0 +1,26 @@ -+diff -urN cn_clip/deploy/pytorch_to_onnx.py cn_clip_fix/deploy/pytorch_to_onnx.py -+--- cn_clip/deploy/pytorch_to_onnx.py 2024-02-20 14:49:36.955252200 +0800 -++++ cn_clip_fix/deploy/pytorch_to_onnx.py 2024-03-17 14:48:30.339636500 +0800 -+@@ -117,8 +117,9 @@ -+ text_fp32_onnx_path, -+ input_names=['text'], -+ output_names=['unnorm_text_features'], -++ dynamic_axes={'text':{0:"-1"}, 'unnorm_text_features':{0:"-1"}}, -+ export_params=True, -+- opset_version=13, -++ opset_version=11, -+ verbose=True) -+ # convert text FP16 ONNX model based on the FP32 model -+ text_fp16_onnx_path = f"{args.save_onnx_path}.txt.fp16.onnx" -+@@ -141,9 +142,10 @@ -+ vision_fp32_onnx_path, -+ input_names=['image'], -+ output_names=['unnorm_image_features'], -++ dynamic_axes={'image':{0:"-1"}, 'unnorm_image_features':{0:"-1"}}, -+ export_params=True, -+ do_constant_folding=False, -+- opset_version=13, -++ opset_version=11, -+ verbose=True) -+ # for ViT-H-14 FP32 model, make another conversion to deal with the generated small files -+ if args.model_arch == "ViT-H-14": diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_img_onnx.py b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_img_onnx.py index bb7a487872..0d61ccac72 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_img_onnx.py +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_img_onnx.py @@ -205,7 +205,7 @@ def pad_nz_block( padding_shape, original_shape = cal_padding_shape(graph, merged) axis = 0 if merged else 1 - new_concat_init = graph.add_initializer(f"padding_concat_init", np.zeros(padding_shape, dtype=np.float16)) + new_concat_init = graph.add_initializer(f"padding_concat_init", np.zeros(padding_shape, dtype=np.float32)) add_node = anchor_adds_2[0] new_concat_name = f"Concat_before_{add_node.name}" new_concat_node = graph.add_node(new_concat_name, "Concat", attrs={"axis": axis}) @@ -459,7 +459,7 @@ def adapt_for_attentionscore(graph: OnnxGraph, anchor_softmaxes: List[OnnxNode]) div_value = graph[div_before_matmul.inputs[1]].value new_mul_init = graph.add_initializer( f"{new_mul_name}_init", - np.array(1/div_value, dtype="float16") + np.array(1/div_value, dtype="float32") ) graph.insert_node(softmax_node.name, new_mul_node, mode="before") new_mul_node.inputs.append(new_mul_init.name) diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py index 4ec2ea7a5a..b265e98f9b 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/opt_txt_onnx.py @@ -91,17 +91,6 @@ def fix_attention_score(graph, softmax_node, bs, seq_len): mul_node.inputs.append(mul_init.name) graph.remove(div_node.name) - expand_node = graph.add_node( - f"Expand_before_{add_node.name}", - "Expand" - ) - expand_init = graph.add_initializer( - f"{expand_node.name}_value", - np.array([bs, 1, seq_len, seq_len], dtype="int64") - ) - graph.insert_node(add_node.name, expand_node, refer_index=~refer_index, mode="before") - expand_node.inputs.append(expand_init.name) - def main(graph): # get config @@ -136,6 +125,22 @@ def main(graph): for softmax_node in softmax_nodes: fix_attention_score(graph, softmax_node, bs, seq_len) + # add expand node + expand_node = graph.add_node( + f"Expand_Mask", + "Expand" + ) + expand_init = graph.add_initializer( + f"expand_value", + np.array([bs, 1, seq_len, seq_len], dtype="int64") + ) + s_node = softmax_nodes[0] + a_node = graph.get_prev_node(s_node.inputs[0]) + m_node = graph.get_prev_node(a_node.inputs[1]) + expand_node.inputs=["mul_out", "expand_value"] + expand_node.outputs=[m_node.outputs[0]] + m_node.outputs=["mul_out"] + # insert last reshape to recover shape last_add = graph.get_nodes(op_type="Add")[-1] last_reshape = graph.add_node( -- Gitee From b5ba278358d8663e4fe1916684e18fb35a38f679 Mon Sep 17 00:00:00 2001 From: shikang Date: Thu, 8 Aug 2024 11:06:43 +0000 Subject: [PATCH 4/4] bug fix --- ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md index 26c1b40d53..5f28c3728f 100644 --- a/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md +++ b/ACL_PyTorch/built-in/foundation_models/Chinese_CLIP/README.md @@ -303,7 +303,7 @@ Chinese_CLIP为CLIP模型的中文版本,使用大规模中文数据进行训 | 芯片型号 | Input Shape | 单次推理耗时 | | -------- | ----------- | ------------ | -| 300I Pro | 24 x 512 | 105ms | +| 300I Pro | 24 x 512 | 103ms | - 图像侧模型: -- Gitee