{"id":5730,"date":"2025-08-04T17:23:47","date_gmt":"2025-08-04T09:23:47","guid":{"rendered":"http:\/\/xinblog.ltd\/?p=5730"},"modified":"2025-08-05T10:59:16","modified_gmt":"2025-08-05T02:59:16","slug":"%e6%a8%a1%e5%9e%8b%e5%be%ae%e8%b0%836-%e6%a8%a1%e5%9e%8b%e5%be%ae%e8%b0%83","status":"publish","type":"post","link":"http:\/\/xinblog.ltd\/?p=5730","title":{"rendered":"\u6a21\u578b\u5fae\u8c036 \u6a21\u578b\u5fae\u8c03"},"content":{"rendered":"<p>6. \u6a21\u578b\u5fae\u8c03<\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u770b\u4e0b\u5fae\u8c03\u7684\u539f\u7406\uff0c\u4ee5\u53ca\u5fae\u8c03\u7684\u8fc7\u7a0b\u3002<\/p>\n<p>\u9996\u5148\u662f\u5fae\u8c03\u7684\u539f\u7406\uff0c\u4ec0\u4e48\u662f\u6a21\u578b\u5fae\u8c03<\/p>\n<p>\u5728\u4e00\u4e2a\u521d\u59cb\u7684\u6a21\u578b\u5f53\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5047\u8bbe\u6a21\u578b\u4e3b\u8981\u662f\u6839\u636e\u516c\u5f0f\u548c\u8f93\u5165\u5f97\u5230\u8f93\u51fa<\/p>\n<p>\u5373<\/p>\n<p>Y = W * X<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u60f3\u8981\u5f97\u5230\u5408\u9002\u7684Y\uff0c\u5c31\u9700\u8981\u786e\u5b9a\u5408\u9002\u7684W<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u5e0c\u671b\uff0c\u5f53\u8f93\u5165X\u4e3a2\u7684\u65f6\u5019\uff0c\u8f93\u51fa\u4e3a1\uff0c\u90a3\u4e48W\u5c31\u5e94\u8be5\u4e3a0.5<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u5c31\u9700\u8981\u5bf9W\u8fdb\u884c\u521d\u59cb\u5316\uff0c<\/p>\n<p>\u800c\u6a21\u578b\u5728\u8bad\u7ec3\u7684\u65f6\u5019\uff0c\u4f1a\u4e0d\u65ad\u7684\u6d4b\u8bd5W\u7684\u8bbe\u7f6e\uff0c\u6bd4\u5982\u4ece0.1\u5f00\u59cb\uff0c\u4e00\u76f4\u5b9e\u9a8c\u52300.5<\/p>\n<p>\u53cd\u4e4b\u5982\u679c\u6709\u4e00\u4e2a\u9884\u8bad\u7ec3\u7684\u6a21\u578b\uff0c\u4e00\u5f00\u59cbW\u5c31\u8bbe\u7f6e\u5728\u4e860.47\u7684\u9644\u8fd1\uff0c\u90a3\u4e48\u8bad\u7ec3\u52300.5\u5c31\u4f1a\u5f88\u5feb\u4e86\u3002<\/p>\n<p>\u56e0\u6b64\u6a21\u578b\u5fae\u8c03\u76f8\u8f83\u4e8e\u4ece\u5934\u5f00\u59cb\u8bad\u7ec3\uff0c\u5fae\u8c03\u53ef\u4ee5\u7701\u53bb\u5927\u91cf\u8ba1\u7b97\u8d44\u6e90\u548c\u65f6\u95f4\uff0c\u63d0\u9ad8\u7cbe\u51c6\u5ea6\u3002<\/p>\n<p>\u90a3\u4e48\u73b0\u5728\u4e3b\u6d41\u7684\u5927\u6a21\u578b\u5fae\u8c03\u662f\u57fa\u4e8eGPT-3\u4e4b\u540e\u8fdb\u884c\u7684\u6307\u4ee4\u5fae\u8c03<\/p>\n<p>Supervised fine-tuning \u7b80\u79f0SFT\u6a21\u578b\u3002<\/p>\n<p>\u90a3\u4e48\u5404\u4e2a\u4e91\u5382\u5546\u90fd\u63d0\u4f9b\u4e86\u81ea\u5df1\u7684LLM \u5fae\u8c03\u8bad\u7ec3\u5de5\u5177<\/p>\n<p>\u9664\u6b64\u5916\u8fd8\u6709HuggingFace\u63d0\u4f9b\u7684Transformers\u8bad\u7ec3\u5de5\u5177<\/p>\n<p>https:\/\/huggingface.co\/docs\/transformers\/main\/zh\/tr aining#%E8%AE%AD%E7%BB%83<\/p>\n<p>\u90a3\u4e48SFT\u8bad\u7ec3\u8fc7\u7a0b\u4e3a<\/p>\n<ol>\n<li>\n  \u51c6\u5907\u8bad\u7ec3\u6570\u636e\u548c\u8bc4\u6d4b\u6570\u636e<\/li>\n<\/ol>\n<p>\u5e76\u7ec4\u88c5\u4e3a\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\uff0c\u540c\u65f6\u8981\u6c42\u6570\u636e\u5177\u6709\u4e0a\u4e00\u8282\u8bf4\u7684\u9ad8\u8d28\u91cf\uff0c\u771f\u5b9e\u6027\uff0c\u9488\u5bf9\u6027\uff0c\u591a\u6837\u6027\u3002<\/p>\n<p>\u540c\u65f6\u786e\u4fdd\u6570\u636e\u91cf\u8db3\u591f\u591a\u3002<\/p>\n<ol>\n<li>\n  \u9009\u62e9\u5408\u9002\u7684\u57fa\u7840\u6a21\u578b<\/li>\n<\/ol>\n<p>\u6839\u636e\u76ee\u6807\u9009\u62e9\u5408\u9002\u7684\u57fa\u7840\u6a21\u578b<\/p>\n<p>\u540c\u65f6\u786e\u8ba4\u6a21\u578b\u8bad\u7ec3\u4e2d\u4f7f\u7528\u7684\u53c2\u6570\u591a\u5c11<\/p>\n<ol>\n<li>\n  Loss \u66f2\u7ebf\u5206\u6790<\/li>\n<\/ol>\n<p>\u6839\u636eLoss\u66f2\u7ebf\u6765\u8bc4\u6d4b\u8bad\u7ec3\u7ed3\u679c\u3002<\/p>\n<p>\u9664\u6b64\u5916\u8fd8\u6709LoRA\u65b9\u5f0f\u8fdb\u884c\u5fae\u8c03<\/p>\n<p>LoRA\u7684\u6838\u5fc3\u601d\u60f3\u662f\u5728\u539f\u672c\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u4e2d\uff0c\u51bb\u7ed3\u9884\u8bad\u7ec3\u597d\u7684\u6a21\u578b\u6743\u91cd\u53c2\u6570\uff0c\u5728\u51bb\u7ed3\u539f\u6a21\u578b\u53c2\u6570\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u6a21\u578b\u4e2d\u589e\u52a0\u989d\u5916\u7684\u7f51\u7edc\u5c42\uff0c\u5e76\u8bad\u7ec3\u8fd9\u4e9b\u7f51\u7edc\u5c42\u53c2\u6570\u3002<\/p>\n<p>\u6bd4\u5982\u539f\u672c\u7684\u6a21\u578b\u53c2\u6570W<\/p>\n<p>\u4e3ad * k<\/p>\n<p>\u5982\u679c\u6211\u4eec\u5f15\u5165\u4e00\u5c42\uff0c\u8fdb\u884c\u89e3\u8026<\/p>\n<p>\u53d8\u4e3a d * r + r * k<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cLoRA\u7684\u8bad\u7ec3\u91cf\u5c06\u4f1a\u5c0f\u4e8e\u5168\u91cf\u53c2\u6570\u5fae\u8c03<\/p>\n<p>\u901a\u8fc7\u663e\u5b58\u5360\u7528\u5c06\u5c0f\u4e8e\u5168\u91cf\u53c2\u6570\u5fae\u8c03<\/p>\n<p>\u5bf9\u5e94\u7684\u5de5\u5177\u4e5f\u662f\u53ef\u4ee5\u4f7f\u7528HuggingFace\u63d0\u4f9b\u7684\u57fa\u4e8ePERT\u8fdb\u884c\u8bad\u7ec3<\/p>\n<p>https:\/\/huggingface.co\/docs\/peft\/main\/en\/task_guides\/semantic_segme ntation_lora#wrap-the-base-model-as-a-peftmodel-for-lora-training<\/p>\n<p>\u5728\u5fae\u8c03\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6bd4\u8f83\u91cd\u8981\u7684\u53c2\u6570\u5373r<\/p>\n<p>LoRA\u4e2dr\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u6839\u636e\u5e94\u7528\u573a\u666f\u8c03\u6574\uff0c\u4e00\u822c\u8d8a\u5927\uff0c\u5fae\u8c03\u6570\u636e\u5bf9\u6a21\u578b\u8d77\u5230\u7684\u4f5c\u7528\u66f4\u5927\uff0c\u4e00\u822c\u53d6 8\/32\/128\u7b49<\/p>\n<p>\u800c\u4e14\u76f8\u8f83\u4e8e\u5168\u91cf\u53c2\u6570\u5fae\u8c03<\/p>\n<p>LoRA\u8868\u73b0\u4e0d\u597d\uff0c\u6240\u4ee5\u521d\u6b21\u5b9e\u9a8c\u8003\u8651\u4f7f\u7528\u5168\u91cf\u5fae\u8c03\uff0c\u540e\u7eed\u53ef\u4ee5\u7528LoRA\u8fed\u4ee3<\/p>\n<p>\u4e14LoRA\u8bb0\u5fc6\u80fd\u529b\u4e0d\u5982\u5168\u91cf\u53c2\u6570\u5fae\u8c03\u3002<\/p>\n<p>\u6700\u540e\u662f\u6a21\u578b\u8bad\u7ec3\u4e2d\u7684Post-Pretrain<\/p>\n<p>\u8fd9\u91cc\u6307\u7684Post-Pretrain\uff0c\u4e3b\u8981\u662f\u7528\u4e8e\u9488\u5bf9\u7279\u5b9a\u9886\u57df\uff0c\u8fdb\u884c\u4e13\u4e1a\u7684\u8bad\u7ec3\u3002<\/p>\n<p>\u6bd4\u5982\u4e00\u4e2a\u5728\u4e2d\u6587\u91d1\u878d\u65b9\u5411\u8fdb\u884c\u8fc7Post-Pretrain\u8c03\u6574\u540e\u7684\u5927\u6a21\u578b\u5728\u7279\u5b9a\u9886\u57df\u7684\u6548\u679c\u662f\u4f18\u4e8e\u5176\u4ed6\u7684\u6a21\u578b\u7684\u3002<\/p>\n<p>\u8fd9\u91cc\u4e3e\u4e00\u4e2a\u4f8b\u5b50<\/p>\n<p>\u6bd4\u5982Code-LLAMA\u4ee3\u7801\u5927\u6a21\u578b<\/p>\n<p>\u5728\u4ee3\u7801\u9886\u57df\uff0cCODE-LLAMA-7B\u7684\u6548\u679c\u4f18\u4e8eLLAMA2-70B\u7684<\/p>\n<p>\u5bf9\u4e8eCODE-LLAMA\u7684\u4ee3\u7801\u5927\u6a21\u578b\uff0c\u5176\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u5c31\u4f7f\u7528\u4e86Post-Pretrain\u6765\u8fdb\u884c\u4e86\u589e\u5f3a\u8bad\u7ec3\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"1240\" height=\"448\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-13.png\" class=\"wp-image-5731\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-13.png 1240w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-13-300x108.png 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-13-1024x370.png 1024w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-13-768x277.png 768w\" sizes=\"(max-width: 1240px) 100vw, 1240px\" \/><\/p>\n<p>\u90a3\u4e48\u5bf9\u4e8e\u8fd9\u6837\u7684\u4e00\u4e2a\u8bad\u7ec3\u6a21\u5f0f\uff0c\u8be5\u5982\u4f55\u64cd\u4f5c\u5462\uff1f<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u8fd9\u6837Post-Pretrain\u7684\u6a21\u5f0f\u662f\u548cSFT\u6a21\u5f0f\u76f8\u7ed3\u5408\u7684<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"1268\" height=\"495\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-14.png\" class=\"wp-image-5732\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-14.png 1268w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-14-300x117.png 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-14-1024x400.png 1024w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-14-768x300.png 768w\" sizes=\"(max-width: 1268px) 100vw, 1268px\" \/><\/p>\n<p>\u5148\u8fdb\u884cPost-Pretrain\u4e4b\u540e\u8fdb\u884c\u901a\u7528SFT\u8fdb\u884c\u8bad\u7ec3\uff0c\u6700\u540e\u8fdb\u884c\u5bf9\u9f50<\/p>\n<p>\u4e4b\u540e\u662fPost-Pretrain\u548cSFT\u7684\u5bf9\u6bd4<\/p>\n<p>Post-Pretrain \u7684\u6570\u636e\u96c6\u66f4\u52a0\u8d34\u5408\u539f\u751f\u7684\u6587\u6863\u5185\u5bb9<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"618\" height=\"402\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-15.png\" class=\"wp-image-5733\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-15.png 618w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-15-300x195.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/p>\n<p>\u800cSFT\u7684\u8bed\u6599\u683c\u5f0f\u66f4\u52a0\u8d34\u8fd1\u95ee\u7b54\u5bf9\u7684\u5f62\u5f0f<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"530\" height=\"388\" src=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-16.png\" class=\"wp-image-5734\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-16.png 530w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2025\/06\/word-image-16-300x220.png 300w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/p>\n<p>\u800cPost-Pretrain\u7684\u8bed\u6599\uff0c\u5219\u4e5f\u9700\u8981\u7ecf\u8fc7\uff0c<\/p>\n<p>\u6587\u672c\u62bd\u53d6 \u6570\u636e\u6e05\u6d17 \u53bb\u91cd\u548c\u6821\u9a8c\u7684\u8fc7\u7a0b\u53bb\u83b7\u53d6\u5230\u8bed\u6599<\/p>\n<p>\u4ece\u800c\u8fdb\u884c\u8f93\u5165\u3002<\/p>\n<p>\u800c\u4e14\u4e3a\u4e86\u4fdd\u8bc1\u6a21\u578b\u7684\u901a\u7528\u80fd\u529b\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u786e\u4fdd\u4e2d\u6587\u8bed\u6599\u548c\u82f1\u6587\u8bed\u6599\u7684\u5408\u7406\u914d\u6bd4<\/p>\n<p>\u4ee5\u53ca\u4e13\u4e1a\u9886\u57df\u8bed\u6599\u548c\u901a\u7528\u9886\u57df\u8bed\u6599\u7684\u5408\u7406\u914d\u6bd4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>6. \u6a21\u578b\u5fae\u8c03 \u8fd9\u91cc\u6211\u4eec\u770b\u4e0b\u5fae [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[],"_links":{"self":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5730"}],"collection":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5730"}],"version-history":[{"count":1,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5730\/revisions"}],"predecessor-version":[{"id":5735,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/5730\/revisions\/5735"}],"wp:attachment":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5730"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}