{"id":1239,"date":"2023-06-01T15:09:52","date_gmt":"2023-06-01T07:09:52","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1239"},"modified":"2023-06-01T15:09:53","modified_gmt":"2023-06-01T07:09:53","slug":"chatglm-6b-model-based-on-p-tuning-v2-fine-tuning-script","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2023\/06\/chatglm-6b-model-based-on-p-tuning-v2-fine-tuning-script\/","title":{"rendered":"#ChatGLM-6B\u6a21\u578b\u57fa\u4e8e P-Tuning v2 \u5fae\u8c03\u811a\u672c\u53c2\u6570\u89e3\u91ca"},"content":{"rendered":"
chatGPT\u662f\u4e00\u79cd\u751f\u6210\u5f0f\u5bf9\u8bdd\u6a21\u578b\uff0c\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u4eba\u7c7b\u7c7b\u4f3c\u7684\u81ea\u7136\u8bed\u8a00\u5bf9\u8bdd\u3002\u5728\u8bad\u7ec3\u8fd9\u4e2a\u6a21\u578b\u65f6\uff0c\u9700\u8981\u901a\u8fc7\u4e00\u7ec4\u8d85\u53c2\u6570\u6765\u63a7\u5236\u6a21\u578b\u7684\u8bad\u7ec3\u884c\u4e3a\u4ee5\u53ca\u751f\u6210\u7ed3\u679c\u7684\u8d28\u91cf\u3002<\/p>\n
\u672c\u6587\u5c06\u5bf9chatGPT\u8bad\u7ec3\u65f6\u6240\u9700\u8981\u8bbe\u7f6e\u7684\u4e00\u4e9b\u8d85\u53c2\u6570\u8fdb\u884c\u89e3\u91ca<\/p>\n
PRE_SEQ_LEN=128\nLR=2e-2\n\nCUDA_VISIBLE_DEVICES=0 python3 main.py \\\n --do_train \\\n --train_file AdvertiseGen\/train.json \\\n --validation_file AdvertiseGen\/dev.json \\\n --prompt_column content \\\n --response_column summary \\\n --overwrite_cache \\\n --model_name_or_path THUDM\/chatglm-6b \\\n --output_dir output\/adgen-chatglm-6b-pt-$PRE_SEQ_LEN-$LR \\\n --overwrite_output_dir \\\n --max_source_length 64 \\\n --max_target_length 64 \\\n --per_device_train_batch_size 1 \\\n --per_device_eval_batch_size 1 \\\n --gradient_accumulation_steps 16 \\\n --predict_with_generate \\\n --max_steps 3000 \\\n --logging_steps 10 \\\n --save_steps 1000 \\\n --learning_rate $LR \\\n --pre_seq_len $PRE_SEQ_LEN \\\n --quantization_bit 4<\/code><\/pre>\nPRE_SEQ_LEN=128<\/code> \u548c LR=2e-2<\/code> \u662f\u4e24\u4e2a\u8d85\u53c2\u6570\uff0c\u7528\u4e8e\u8bbe\u7f6echatGPT\u8bad\u7ec3\u7684\u4e00\u4e9b\u53c2\u6570\u3002\u8fd9\u4e9b\u8d85\u53c2\u6570\u7684\u5177\u4f53\u610f\u4e49\u5982\u4e0b\uff1a<\/p>\n\n- \n
PRE_SEQ_LEN=128<\/code><\/p>\n\u8fd9\u4e2a\u8d85\u53c2\u6570\u6307\u5b9a\u4e86\u6a21\u578b\u5728\u8fdb\u884cfinetune\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u6bcf\u4e2a\u793a\u4f8b\uff08prompt\u548cresponse\uff09\u8f93\u5165\u5e8f\u5217\u7684\u6700\u5927\u957f\u5ea6\u3002\u5728chatGPT\u8bad\u7ec3\u4e2d\uff0c\u8981\u5c06prompt\u548cresponse\u4e24\u4e2a\u5e8f\u5217\u5408\u5e76\u6210\u4e00\u4e2a\u8f93\u5165\u5e8f\u5217\uff0c\u56e0\u6b64\u9700\u8981\u63a7\u5236\u8f93\u5165\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u907f\u514dGPU\u5185\u5b58\u6ea2\u51fa\u6216\u8bad\u7ec3\u8fc7\u6162\u3002\u8be5\u503c\u901a\u5e38\u7531\u786c\u4ef6\u8bbe\u5907\u5185\u5b58\u5927\u5c0f\u548c\u4efb\u52a1\u8981\u6c42\u7b49\u56e0\u7d20\u7efc\u5408\u8003\u8651\u800c\u5b9a\u3002<\/p>\n<\/li>\n
- \n
LR=2e-2<\/code><\/p>\n\u8fd9\u4e2a\u8d85\u53c2\u6570\u6307\u5b9a\u4e86\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u5b66\u4e60\u7387\u3002\u5b66\u4e60\u7387\u662f\u63a7\u5236\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6a21\u578b\u53c2\u6570\u66f4\u65b0\u901f\u5ea6\u7684\u8d85\u53c2\u6570\uff0c\u5bf9\u8bad\u7ec3\u8fc7\u7a0b\u7684\u7ed3\u679c\u5177\u6709\u5f88\u5927\u7684\u5f71\u54cd\u3002\u5982\u679c\u5b66\u4e60\u7387\u8fc7\u9ad8\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6a21\u578b\u8bad\u7ec3\u5feb\u901f\u6536\u655b\u4f46\u53ef\u80fd\u4f1a\u9677\u5165\u5c40\u90e8\u6700\u4f18\u89e3\uff1b\u5982\u679c\u5b66\u4e60\u7387\u8fc7\u4f4e\uff0c\u5219\u6a21\u578b\u8bad\u7ec3\u53ef\u80fd\u4f1a\u6536\u655b\u7f13\u6162\uff0c\u5e76\u53ef\u80fd\u9677\u5165\u5c40\u90e8\u6700\u4f18\u89e3\u3002\u5728chatGPT\u8bad\u7ec3\u4e2d\uff0c\u4e00\u822c\u91c7\u7528\u9ed8\u8ba4\u503c\u6216\u5728\u4e00\u5b9a\u8303\u56f4\u5185\u8fdb\u884c\u8c03\u6574\u3002LR=2e-2<\/code> \u8868\u793a\u5b66\u4e60\u7387\u4e3a0.02\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u8fd9\u4e2a\u503c\u6bd4\u8f83\u5408\u9002\u3002<\/p>\n<\/li>\n- \n
--do_train<\/code><\/p>\n\u8be5\u53c2\u6570\u8868\u793a\u662f\u5426\u9700\u8981\u8fdb\u884c\u8bad\u7ec3\u3002\u5982\u679c\u8bbe\u7f6e\u4e86\u8be5\u53c2\u6570\uff0c\u5219\u4f1a\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\uff1b\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\uff0c\u5219\u4e0d\u8fdb\u884c\u8bad\u7ec3\u3002<\/p>\n<\/li>\n
- \n
--train_file<\/code><\/p>\n\u8be5\u53c2\u6570\u6307\u5b9a\u8bad\u7ec3\u6570\u636e\u6587\u4ef6\u7684\u8def\u5f84\u3002\u8bad\u7ec3\u6570\u636e\u6587\u4ef6\u5e94\u4e3aJSON\u683c\u5f0f\uff0c\u5176\u4e2d\u5305\u542b\u8f93\u5165\u5e8f\u5217\u548c\u8f93\u51fa\u5e8f\u5217\u7b49\u4fe1\u606f\u3002<\/p>\n<\/li>\n
- \n
--validation_file<\/code> <\/p>\n\u662f\u7528\u4e8e\u6307\u5b9a\u9a8c\u8bc1\u96c6\u6587\u4ef6\u8def\u5f84\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u5b9e\u65f6\u8bc4\u4f30\u6a21\u578b\u7684\u6548\u679c\u548c\u6027\u80fd\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u8bad\u7ec3\u6a21\u578b\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5c06\u8bad\u7ec3\u6570\u636e\u96c6\u5206\u6210\u8bad\u7ec3\u96c6\u548c\u9a8c\u8bc1\u96c6\u4e24\u90e8\u5206\u3002\u8bad\u7ec3\u96c6\u7528\u4e8e\u8bad\u7ec3\u6a21\u578b\uff0c\u9a8c\u8bc1\u96c6\u5219\u7528\u4e8e\u8bc4\u4f30\u6a21\u578b\u7684\u6027\u80fd\u548c\u51c6\u786e\u6027\u3002<\/p>\n<\/li>\n
- \n
--prompt_column<\/code><\/p>\n\u8be5\u53c2\u6570\u6307\u5b9a\u8f93\u5165\u6587\u672c\uff08\u5373\u524d\u7f6e\u6587\u672c\u6216prompt\uff09\u6240\u5728\u5217\u3002<\/p>\n<\/li>\n
- \n
--response_column<\/code><\/p>\n\u8be5\u53c2\u6570\u6307\u5b9a\u8f93\u51fa\u6587\u672c\uff08\u5373\u54cd\u5e94\u6587\u672c\u6216response\uff09\u6240\u5728\u5217\u3002<\/p>\n<\/li>\n
- \n
--overwrite_cache<\/code><\/p>\n\u8be5\u53c2\u6570\u6307\u5b9a\u662f\u5426\u91cd\u5199\u7f13\u5b58\u3002\u5982\u679c\u8bbe\u7f6e\u4e86\u8be5\u53c2\u6570\uff0c\u5219\u4f1a\u91cd\u65b0\u751f\u6210\u7f13\u5b58\u6587\u4ef6\uff1b\u5426\u5219\u4f1a\u52a0\u8f7d\u73b0\u6709\u7684\u7f13\u5b58\u6587\u4ef6\uff08\u5982\u679c\u5b58\u5728\uff09\u3002<\/p>\n<\/li>\n
- \n
--model_name_or_path<\/code><\/p>\n\u6307\u5b9a\u9884\u8bad\u7ec3\u6a21\u578b\u7684\u8def\u5f84\u6216\u540d\u79f0\u3002\u8fd9\u4e2a\u53c2\u6570\u544a\u8bc9\u7a0b\u5e8f\u5c06\u54ea\u4e00\u4e2a\u9884\u8bad\u7ec3\u6a21\u578b\u52a0\u8f7d\u8fdb\u6765\uff0c\u7528\u4e8efinetune\u6216\u8005\u4f5c\u4e3a\u57fa\u6a21\u578b\u3002<\/p>\n<\/li>\n
- \n
--output_dir<\/code><\/p>\n\u6307\u5b9a\u8bad\u7ec3\u6a21\u578b\u7684\u8f93\u51fa\u76ee\u5f55\u3002<\/p>\n<\/li>\n
- \n
--max_source_length<\/code><\/p>\n\u6307\u5b9a\u8f93\u5165\u5e8f\u5217\u7684\u6700\u5927\u957f\u5ea6\u3002\u5982\u679c\u8f93\u5165\u5e8f\u5217\u7684\u957f\u5ea6\u8d85\u8fc7\u8fd9\u4e2a\u503c\uff0c\u5219\u4f1a\u88ab\u622a\u65ad\u5230\u8be5\u503c\u3002\u8fd9\u4e2a\u53c2\u6570\u901a\u5e38\u662f\u6839\u636e\u786c\u4ef6\u8bbe\u5907GPU\u7684\u5185\u5b58\u5927\u5c0f\u6765\u786e\u5b9a\u7684\u3002<\/p>\n<\/li>\n
- \n
--max_target_length<\/code><\/p>\n\u6307\u5b9a\u8f93\u51fa\u5e8f\u5217\u7684\u6700\u5927\u957f\u5ea6\u3002\u5982\u679c\u8f93\u51fa\u5e8f\u5217\u7684\u957f\u5ea6\u8d85\u8fc7\u8fd9\u4e2a\u503c\uff0c\u5219\u4f1a\u88ab\u622a\u65ad\u5230\u8be5\u503c\u3002<\/p>\n<\/li>\n
- \n
--per_device_train_batch_size<\/code><\/p>\n\u6307\u5b9a\u6bcf\u4e2aGPU\u8bbe\u5907\u7684\u8bad\u7ec3\u6279\u6b21\u5927\u5c0f\u3002\u8fd9\u4e2a\u53c2\u6570\u63a7\u5236\u6bcf\u4e2aGPU\u4e0a\u53ef\u4ee5\u540c\u65f6\u8bad\u7ec3\u7684\u6837\u672c\u6570\u91cf\uff0c\u5f71\u54cd\u5230\u5185\u5b58\u7684\u4f7f\u7528\u91cf\u548c\u8bad\u7ec3\u901f\u5ea6\u3002<\/p>\n<\/li>\n
- \n
--per_device_eval_batch_size<\/code><\/p>\n\u6307\u5b9a\u6bcf\u4e2aGPU\u8bbe\u5907\u7684\u8bc4\u4f30\u6279\u6b21\u5927\u5c0f\u3002\u8fd9\u4e2a\u53c2\u6570\u4e0e\u8bad\u7ec3\u6279\u6b21\u5927\u5c0f\u7c7b\u4f3c\uff0c\u63a7\u5236\u6bcf\u4e2aGPU\u4e0a\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\u7684\u6837\u672c\u6570\u91cf\uff0c\u5f71\u54cd\u5230\u5185\u5b58\u7684\u4f7f\u7528\u91cf\u548c\u8bc4\u4f30\u901f\u5ea6\u3002<\/p>\n<\/li>\n
- \n
--gradient_accumulation_steps<\/code><\/p>\n\u6307\u5b9a\u68af\u5ea6\u7d2f\u79ef\u7684\u6b65\u6570\u3002\u68af\u5ea6\u7d2f\u79ef\u610f\u5473\u7740\u5728\u8ba1\u7b97\u68af\u5ea6\u65f6\uff0c\u5c06\u591a\u4e2a\u6279\u6b21\u7684\u68af\u5ea6\u7d2f\u79ef\u8d77\u6765\u518d\u8fdb\u884c\u66f4\u65b0\uff0c\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u6bcf\u4e2a\u6279\u6b21\u7684\u5185\u5b58\u5360\u7528\uff0c\u4ece\u800c\u4f7f\u5f97\u66f4\u5927\u7684\u6279\u6b21\u5927\u5c0f\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n<\/li>\n
- \n
--predict_with_generate<\/code><\/p>\n\u5982\u679c\u8bbe\u7f6e\u8be5\u53c2\u6570\uff0c\u5219\u4f1a\u5728\u8bad\u7ec3\u5b8c\u6210\u540e\u7acb\u5373\u751f\u6210\u8f93\u51fa\u7ed3\u679c\u3002\u8fd9\u6837\u53ef\u4ee5\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u4e0d\u65ad\u5730\u68c0\u67e5\u6a21\u578b\u7684\u6027\u80fd\u548c\u6548\u679c\u3002<\/p>\n<\/li>\n
- \n
--max_steps<\/code><\/p>\n\u6307\u5b9a\u8bad\u7ec3\u6a21\u578b\u7684\u6700\u5927\u6b65\u6570\u3002\u5982\u679c\u8fbe\u5230\u8fd9\u4e2a\u6b65\u6570\u5219\u505c\u6b62\u8bad\u7ec3\u3002<\/p>\n<\/li>\n
- \n
--logging_steps<\/code><\/p>\n\u6307\u5b9a\u6bcf\u9694\u591a\u5c11\u6b65\u5c06\u8bad\u7ec3\u65e5\u5fd7\u5199\u5165\u8f93\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u8fd9\u4e2a\u53c2\u6570\u63a7\u5236\u8bb0\u5f55\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u7684\u4fe1\u606f\u7684\u9891\u7387\uff0c\u6709\u52a9\u4e8e\u89c2\u5bdf\u8bad\u7ec3\u8fc7\u7a0b\u7684\u8fdb\u5c55\u60c5\u51b5\u3002<\/p>\n<\/li>\n
- \n
--save_steps<\/code><\/p>\n\u6307\u5b9a\u6bcf\u9694\u591a\u5c11\u6b65\u5c06\u6a21\u578b\u4fdd\u5b58\u5230\u8f93\u51fa\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u8fd9\u4e2a\u53c2\u6570\u63a7\u5236\u5468\u671f\u5730\u4fdd\u5b58\u8bad\u7ec3\u6a21\u578b\u7684\u9891\u7387\uff0c\u6709\u52a9\u4e8e\u4fdd\u62a4\u6a21\u578b\u8bad\u7ec3\u7684\u6210\u679c\u548c\u907f\u514d\u4fe1\u606f\u4e22\u5931\u3002<\/p>\n<\/li>\n
- \n
--learning_rate<\/code><\/p>\n\u6307\u5b9a\u5b66\u4e60\u7387\u3002\u5b66\u4e60\u7387\u662f\u63a7\u5236\u795e\u7ecf\u7f51\u7edc\u4e2d\u6743\u91cd\u53d8\u5316\u7684\u901f\u5ea6\u7684\u8d85\u53c2\u6570\u3002\u9002\u5f53\u7684\u5b66\u4e60\u7387\u6709\u52a9\u4e8e\u63d0\u9ad8\u6a21\u578b\u7684\u8bad\u7ec3\u901f\u5ea6\u548c\u8d28\u91cf\u3002<\/p>\n<\/li>\n
- \n
--pre_seq_len<\/code><\/p>\n\u6307\u5b9a\u8bad\u7ec3\u65f6\u7684\u9884\u5e8f\u5217\u957f\u5ea6\u3002\u8fd9\u4e2a\u53c2\u6570\u7528\u4e8efinetune\u64cd\u4f5c\uff0c\u63a7\u5236\u8f93\u5165\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u8fdb\u800c\u63a7\u5236\u6a21\u578b\u8f93\u51fa\u7684\u4fe1\u606f\u91cf\u548c\u8d28\u91cf\u3002<\/p>\n<\/li>\n
- \n
--quantization_bit<\/code><\/p>\n\u6307\u5b9a\u7f51\u7edc\u91cf\u5316\u65f6\u7684\u6bd4\u7279\u6570\u3002\u7f51\u7edc\u91cf\u5316\u662f\u4e00\u79cd\u4f18\u5316\u6a21\u578b\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u51cf\u5c11\u6a21\u578b\u7684\u4f53\u79ef\u548c\u5185\u5b58\u4f7f\u7528\u91cf\u3002\u9009\u62e9\u9002\u5f53\u7684\u91cf\u5316\u6bd4\u7279\u6570\u6709\u52a9\u4e8e\u63d0\u9ad8\u6a21\u578b\u7684\u6548\u7387\u548c\u901f\u5ea6\u3002<\/p>\n
\u4f5c\u4e3a\u4e00\u4e2a\u5c0f\u767d\u4ee5\u4e0a\u662f\u6211\u7528cahtgpt\u751f\u6210\u7684\u5bf9\u8fd9\u4e9b\u53c2\u6570\u7684\u8be6\u7ec6\u89e3\u91ca\uff0c\u5e0c\u671b\u5bf9\u60a8\u7406\u89e3\u8fd9\u4e2a\u6a21\u578b\u7684\u8bad\u7ec3\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"
ChatGLM-6B\u6a21\u578b\u57fa\u4e8e P-Tuning v2 \u5fae\u8c03\u811a\u672c\u53c2\u6570\u89e3\u91ca chatGPT\u662f\u4e00\u79cd\u751f\u6210\u5f0f\u5bf9\u8bdd\u6a21\u578b\uff0c\u53ef<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[],"yoast_head":"\n
#ChatGLM-6B\u6a21\u578b\u57fa\u4e8e P-Tuning v2 \u5fae\u8c03\u811a\u672c\u53c2\u6570\u89e3\u91ca - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n