{"id":436,"date":"2024-07-29T14:38:37","date_gmt":"2024-07-29T06:38:37","guid":{"rendered":"https:\/\/www.bosombot.com\/?p=436"},"modified":"2024-07-29T14:38:37","modified_gmt":"2024-07-29T06:38:37","slug":"qwen%e9%83%a8%e7%bd%b2%e5%ae%9e%e6%88%98%e3%80%91%e6%8e%a2%e7%b4%a2qwen-7b-chat%ef%bc%9a%e9%98%bf%e9%87%8c%e4%ba%91%e5%a4%a7%e5%9e%8b%e8%af%ad%e8%a8%80%e6%a8%a1%e5%9e%8b%e7%9a%84%e5%af%b9%e8%af%9d","status":"publish","type":"post","link":"https:\/\/www.bosombot.com\/?p=436","title":{"rendered":"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><a><\/a>\u76ee\u5f55<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#_2\">\u7cfb\u5217\u7bc7\u7ae0\ud83d\udca5<\/a><\/li>\n\n\n\n<li><a href=\"#_19\">\u4e00\u3001\u6982\u8ff0<\/a><\/li>\n\n\n\n<li><a href=\"#_22\">\u4e8c\u3001\u73af\u5883\u8981\u6c42<\/a><\/li>\n\n\n\n<li><a href=\"#_28\">\u4e09\u3001\u4f9d\u8d56\u5b89\u88c5<\/a><\/li>\n\n\n\n<li><a href=\"#_46\">\u56db\u3001\u4e0b\u8f7d\u6a21\u578b<\/a><\/li>\n\n\n\n<li><a href=\"#_65\">\u4e94\u3001\u5feb\u901f\u4f7f\u7528<\/a>\n<ul class=\"wp-block-list\">\n<li><a href=\"#1_95\">1\u3001\u7b2c\u4e00\u8f6e\u5bf9\u8bdd<\/a><\/li>\n\n\n\n<li><a href=\"#2_107\">2\u3001\u7b2c\u4e8c\u8f6e\u5bf9\u8bdd<\/a><\/li>\n\n\n\n<li><a href=\"#3_125\">3\u3001\u7b2c\u4e09\u8f6e\u5bf9\u8bdd<\/a><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><a href=\"#_139\">\u516d\u3001\u7ed3\u8bed<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_19\"><\/a>\u4e00\u3001\u6982\u8ff0<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4eba\u5de5\u667a\u80fd\u9886\u57df\uff0c\u5927\u578b<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u8bed\u8a00\u6a21\u578b<\/a>\u7684\u53d1\u5c55\u65e5\u65b0\u6708\u5f02\u3002\u963f\u91cc\u4e91\u63a8\u51fa\u7684\u901a\u4e49\u5343\u95ee-7B\uff08Qwen-7B\uff09\u6a21\u578b\uff0c\u4ee5\u517670\u4ebf\u53c2\u6570\u7684\u5e9e\u5927\u89c4\u6a21\uff0c\u6210\u4e3a\u8be5\u9886\u57df\u7684\u65b0\u661f\u3002\u57fa\u4e8e\u5148\u8fdb\u7684Transformer\u67b6\u6784\uff0cQwen-7B\u5728\u6d77\u91cf\u4e14\u591a\u6837\u5316\u7684\u9884\u8bad\u7ec3\u6570\u636e\u4e0a\u8fdb\u884c\u6df1\u5165\u5b66\u4e60\uff0c\u8fd9\u4e9b\u6570\u636e\u4e0d\u4ec5\u5305\u62ec\u4e86\u4e30\u5bcc\u7684\u7f51\u7edc\u6587\u672c\uff0c\u8fd8\u6db5\u76d6\u4e86\u4e13\u4e1a\u4e66\u7c4d\u3001\u4ee3\u7801\u7b49\u591a\u79cd\u5f62\u5f0f\u7684\u5185\u5bb9\u3002\u8fdb\u4e00\u6b65\u5730\uff0cQwen-7B-Chat\u4f5c\u4e3a\u5176\u884d\u751f\u7684AI\u52a9\u624b\u6a21\u578b\uff0c\u901a\u8fc7\u7cbe\u51c6\u7684\u5bf9\u9f50\u673a\u5236\uff0c\u5c55\u73b0\u4e86\u5927\u8bed\u8a00\u6a21\u578b\u5728\u5bf9\u8bdd\u4ea4\u4e92\u4e2d\u7684\u5353\u8d8a\u6027\u80fd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_22\"><\/a>\u4e8c\u3001\u73af\u5883\u8981\u6c42<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u5145\u5206\u5229\u7528Qwen-7B-Chat\u6a21\u578b\u7684\u5f3a\u5927\u529f\u80fd\uff0c\u5b98\u65b9\u5efa\u8bae\u5f00\u53d1\u8005\u51c6\u5907\u4ee5\u4e0b<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u73af\u5883\u914d\u7f6e<\/a>\uff1a<br>Python\u7248\u672c\u9700\u4e3a3.8\u6216\u66f4\u9ad8\u3002<br>PyTorch\u6846\u67b6\uff0c\u63a8\u8350\u4f7f\u75281.12\u7248\u672c\u6216\u66f4\u65b0\uff0c2.0\u7248\u672c\u53ca\u4ee5\u4e0a\u5c06\u83b7\u5f97\u66f4\u4f73\u4f53\u9a8c\u3002<br>\u5bf9\u4e8e\u8ba1\u5212\u4f7f\u7528GPU\u52a0\u901f\u6216flash-attention\u5e93\u7684\u7528\u6237\uff0c\u5efa\u8bae\u5b89\u88c5CUDA 11.4\u6216\u66f4\u9ad8\u7248\u672c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_28\"><\/a>\u4e09\u3001\u4f9d\u8d56\u5b89\u88c5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884cQwen-7B-Chat\uff0c\u8bf7\u786e\u4fdd\u6ee1\u8db3\u4e0a\u8ff0\u8981\u6c42\uff0c\u518d\u6267\u884c\u4ee5\u4e0bpip\u547d\u4ee4\u5b89\u88c5\u4f9d\u8d56\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install transformers==4.32.0 accelerate tiktoken einops scipy transformers_stream_generator==0.0.4 peft deepspeed\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/8ef25130e2624d038b08da02d10addbb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u5916\uff0c\u4e3a\u4e86\u8fdb\u4e00\u6b65\u63d0\u5347\u8fd0\u884c\u6548\u7387\u548c\u964d\u4f4e\u663e\u5b58\u5360\u7528\uff0c\u5b98\u65b9\u5f3a\u70c8\u63a8\u8350\u5b89\u88c5flash-attention\u5e93\uff0c\u8be5\u5e93\u5df2\u5168\u9762\u652f\u6301flash attention 2\u6280\u672f\u3002\u5b89\u88c5\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/Dao-AILab\/flash-attention\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/99467af011624eb1a9b5bfdc4fe17192.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe1\" \/><\/figure>\n<\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>cd flash-attention &amp;&amp; pip install .\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/6757490123194304aa3c07810b1dcb54.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe2\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_46\"><\/a>\u56db\u3001\u4e0b\u8f7d\u6a21\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u6a21\u578bQwen-7B-Chat\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u63d0\u793a\u90e8\u7f72\u8fd0\u884c\u6548\u7387<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import torch\nfrom modelscope import snapshot_download\nmodel_dir = snapshot_download(\n    'qwen\/Qwen-7B-Chat', \n    cache_dir='\/root\/autodl-tmp', \n    revision='master'\n)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u5982\u4e0b\uff1a<br><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/5740a4f796e8482a94eb62d3f7a33deb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe3\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u68c0\u67e5\u6743\u91cd\u6587\u4ef6\u5927\u5c0f\uff0c\u5bf9\u6bd4\u67e5\u770b\u662f\u5426\u6709\u7f3a\u5931<br><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/31979908aebe4d60bcc3ee9ea95d267c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe4\" \/><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_65\"><\/a>\u4e94\u3001\u5feb\u901f\u4f7f\u7528<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u8fde\u8d2f\u7684\u793a\u4f8b\u6f14\u793a\uff0c\u5f15\u9886\u60a8\u6b65\u5165\u4f7f\u7528Qwen-7B-Chat\u6a21\u578b\u8fdb\u884c\u591a\u8f6e\u5bf9\u8bdd\u4ea4\u4e92\u7684\u4e16\u754c\u3002\u8fd9\u4e9b\u7cbe\u5fc3\u8bbe\u8ba1\u7684\u4ea4\u4e92\u793a\u4f8b\u4e0d\u4ec5\u5c06\u5e2e\u52a9\u60a8\u8fc5\u901f\u638c\u63e1\u64cd\u4f5c\u6d41\u7a0b\uff0c\u66f4\u5c06\u8ba9\u60a8\u4eb2\u8eab\u4f53\u9a8c\u5230Qwen-7B-Chat\u5728\u667a\u80fd\u5bf9\u8bdd\u9886\u57df\u7684\u975e\u51e1\u80fd\u529b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u7684\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u4e86\u5fc5\u8981\u7684\u5e93\u548c\u4f9d\u8d56\u3002\u63a5\u4e0b\u6765\uff0c\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff0c\u6211\u4eec\u5c06\u521d\u59cb\u5316Qwen-7B-Chat\u6a21\u578b\uff0c\u5e76\u914d\u7f6e\u76f8\u5e94\u7684\u751f\u6210\u53c2\u6570\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u786c\u4ef6\u73af\u5883\u548c\u6027\u80fd\u9700\u6c42\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from transformers import AutoModelForCausalLM, AutoTokenizer\nfrom transformers.generation import GenerationConfig\n\n# \u4fe1\u4efb\u8fdc\u7a0b\u4ee3\u7801\u4ee5\u52a0\u8f7d\u6a21\u578b\uff0c\u8fd9\u9700\u8981\u5728\u5b89\u5168\u7684\u73af\u5883\u4e0b\u4f7f\u7528\ntokenizer = AutoTokenizer.from_pretrained(\"\/root\/autodl-tmp\/qwen\/Qwen-7B-Chat\", trust_remote_code=True)\n\n# \u6839\u636e\u4f60\u7684\u786c\u4ef6\u914d\u7f6e\u9009\u62e9\u5408\u9002\u7684\u6a21\u578b\u52a0\u8f7d\u65b9\u5f0f\uff1a\n# \u4f7f\u7528bf16\u7cbe\u5ea6\uff0c\u9002\u7528\u4e8e\u652f\u6301bfloat16\u7684GPU\n# model = AutoModelForCausalLM.from_pretrained(\"Qwen\/Qwen-7B-Chat\", device_map=\"auto\", trust_remote_code=True, bf16=True).eval()\n# \u4f7f\u7528fp16\u7cbe\u5ea6\uff0c\u9002\u7528\u4e8e\u9700\u8981\u6df7\u5408\u7cbe\u5ea6\u8bad\u7ec3\u7684\u573a\u5408\n# model = AutoModelForCausalLM.from_pretrained(\"Qwen\/Qwen-7B-Chat\", device_map=\"auto\", trust_remote_code=True, fp16=True).eval()\n# \u4ec5\u4f7f\u7528CPU\u8fdb\u884c\u6a21\u578b\u52a0\u8f7d\u548c\u8fd0\u7b97e\n# model = AutoModelForCausalLM.from_pretrained(\"Qwen\/Qwen-7B-Chat\", dvice_map=\"cpu\", trust_remote_code=True).eval()\n# \u81ea\u52a8\u9009\u62e9\u8bbe\u5907\u548c\u7cbe\u5ea6\u6a21\u5f0f\uff0c\u6839\u636e\u7cfb\u7edf\u73af\u5883\u667a\u80fd\u9002\u914d\nmodel = AutoModelForCausalLM.from_pretrained(\"\/root\/autodl-tmp\/qwen\/Qwen-7B-Chat\", device_map=\"auto\", trust_remote_code=True).eval()\n\n# \u5bf9\u4e8etransformers\u7248\u672c4.32.0\u53ca\u4ee5\u4e0a\uff0c\u751f\u6210\u914d\u7f6e\u5df2\u5185\u7f6e\uff0c\u65e0\u9700\u989d\u5916\u6307\u5b9a\n# \u5982\u679c\u9700\u8981\u5b9a\u5236\u5316\u751f\u6210\u914d\u7f6e\uff0c\u5982\u8c03\u6574\u751f\u6210\u957f\u5ea6\u6216top_p\u7b49\u53c2\u6570\uff0c\u53ef\u4ee5\u53d6\u6d88\u4e0b\u9762\u6ce8\u91ca\n# model.generation_config = GenerationConfig.from_pretrained(\"Qwen\/Qwen-7B-Chat\", trust_remote_code=True) \n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/direct\/af5b10f0574142ad920186c14e4b017a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"Qwen\u90e8\u7f72\u5b9e\u6218\u3011\u63a2\u7d22Qwen-7B-Chat\uff1a\u963f\u91cc\u4e91\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u5bf9\u8bdd\u5b9e\u8df5\u63d2\u56fe5\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\u6a21\u578b\u548c\u5206\u8bcd\u5668\uff0c\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u901a\u8fc7\u51e0\u8f6e\u5bf9\u8bdd\u6765\u611f\u53d7Qwen-7B-Chat\u7684\u9b45\u529b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a><\/a><a id=\"1_95\"><\/a>1\u3001\u7b2c\u4e00\u8f6e\u5bf9\u8bdd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u4e00\u8f6e\u4e2d\uff0c\u6211\u4eec\u5c06\u4ece\u57fa\u7840\u7684\u95ee\u5019\u5f00\u59cb\uff0c\u5efa\u7acb\u4e0e\u6a21\u578b\u7684\u521d\u6b65\u4ea4\u6d41\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>response, history = model.chat(tokenizer, \"\u4f60\u597d\", history=None)\nprint(response)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f60\u597d\uff01\u5f88\u9ad8\u5174\u89c1\u5230\u4f60\u3002\u6709\u4ec0\u4e48\u6211\u80fd\u5e2e\u52a9\u4f60\u7684\u5417\uff1f\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a><\/a><a id=\"2_107\"><\/a>2\u3001\u7b2c\u4e8c\u8f6e\u5bf9\u8bdd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u968f\u540e\uff0c\u6211\u4eec\u5c06\u63d0\u51fa\u4e00\u4e2a\u66f4\u5177\u4f53\u7684\u8981\u6c42\uff0c\u8ba9\u6a21\u578b\u4e3a\u6211\u4eec\u8bb2\u8ff0\u4e00\u4e2a\u52b1\u5fd7\u7684\u6545\u4e8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>response, history = model.chat(tokenizer, \"\u7ed9\u6211\u8bb2\u4e00\u4e2a\u5e74\u8f7b\u4eba\u594b\u6597\u521b\u4e1a\u6700\u7ec8\u53d6\u5f97\u6210\u529f\u7684\u6545\u4e8b\u3002\", history=history)\nprint(response)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6545\u4e8b\u7684\u4e3b\u89d2\u662f\u4e00\u4e2a\u53eb\u505a\u674e\u660e\u7684\u5e74\u8f7b\u4eba\uff0c\u4ed6\u4ece\u5bb6\u4e61\u7684\u4e00\u5bb6\u5c0f\u516c\u53f8\u5f00\u59cb\uff0c\u51ed\u501f\u81ea\u5df1\u7684\u52aa\u529b\u548c\u52c7\u6c14\uff0c\u9010\u6e10\u6210\u4e3a\u4e86\u516c\u53f8\u7684\u8d1f\u8d23\u4eba\uff0c\u5e76\u5e26\u9886\u516c\u53f8\u53d1\u5c55\u6210\u4e3a\u4e00\u5bb6\u5168\u7403\u77e5\u540d\u7684\u79d1\u6280\u516c\u53f8\u3002\n\n\u4e00\u5f00\u59cb\uff0c\u674e\u660e\u53ea\u662f\u4e00\u4e2a\u5c0f\u804c\u5458\uff0c\u4f46\u4ed6\u5e76\u4e0d\u6ee1\u8db3\u4e8e\u73b0\u72b6\uff0c\u4ed6\u77e5\u9053\u53ea\u6709\u4e0d\u65ad\u5b66\u4e60\u3001\u4e0d\u65ad\u8fdb\u6b65\u624d\u80fd\u5728\u672a\u6765\u83b7\u5f97\u66f4\u591a\u7684\u673a\u4f1a\u3002\u4e8e\u662f\uff0c\u4ed6\u5f00\u59cb\u81ea\u5b66\u7f16\u7a0b\uff0c\u5e76\u53c2\u52a0\u5404\u79cd\u6280\u672f\u6bd4\u8d5b\uff0c\u4e0d\u65ad\u63d0\u5347\u81ea\u5df1\u7684\u6280\u80fd\u3002\n\n\u5f53\u516c\u53f8\u9047\u5230\u56f0\u96be\u65f6\uff0c\u674e\u660e\u5e76\u6ca1\u6709\u9009\u62e9\u653e\u5f03\uff0c\u800c\u662f\u9009\u62e9\u52c7\u6562\u9762\u5bf9\u3002\u4ed6\u79ef\u6781\u5bfb\u627e\u89e3\u51b3\u65b9\u6848\uff0c\u5e76\u63d0\u51fa\u4e86\u4e00\u4e9b\u65b0\u7684\u601d\u8def\uff0c\u5e2e\u52a9\u516c\u53f8\u5ea6\u8fc7\u4e86\u96be\u5173\u3002\n\n\u7ecf\u8fc7\u51e0\u5e74\u7684\u52aa\u529b\uff0c\u674e\u660e\u6700\u7ec8\u6210\u529f\u5730\u9886\u5bfc\u516c\u53f8\u5b9e\u73b0\u4e86\u5feb\u901f\u53d1\u5c55\uff0c\u5e76\u5c06\u516c\u53f8\u63a8\u5411\u4e86\u5168\u7403\u5e02\u573a\u7684\u524d\u5217\u3002\u4ed6\u7684\u6545\u4e8b\u544a\u8bc9\u6211\u4eec\uff0c\u53ea\u8981\u6211\u4eec\u6709\u51b3\u5fc3\u548c\u52c7\u6c14\uff0c\u5c31\u4e00\u5b9a\u80fd\u591f\u5b9e\u73b0\u6211\u4eec\u7684\u68a6\u60f3\u3002\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a><\/a><a id=\"3_125\"><\/a>3\u3001\u7b2c\u4e09\u8f6e\u5bf9\u8bdd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\uff0c\u6211\u4eec\u5c06\u8981\u6c42\u6a21\u578b\u4e3a\u8fd9\u4e2a\u6545\u4e8b\u6784\u601d\u4e00\u4e2a\u6070\u5f53\u7684\u6807\u9898\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>response, history = model.chat(tokenizer, \"\u7ed9\u8fd9\u4e2a\u6545\u4e8b\u8d77\u4e00\u4e2a\u6807\u9898\", history=history)\nprint(response)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u300a\u52c7\u6500\u9ad8\u5cf0\uff1a\u4e00\u4e2a\u5e74\u8f7b\u4eba\u7684\u594b\u6597\u521b\u4e1a\u53f2\u300b\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8fd9\u4e9b\u793a\u4f8b\uff0c\u6211\u4eec\u4e0d\u4ec5\u5c55\u793a\u4e86Qwen-7B-Chat\u6a21\u578b\u7684\u5bf9\u8bdd\u80fd\u529b\uff0c\u4e5f\u4f53\u73b0\u4e86\u5176\u5728\u7406\u89e3\u548c\u751f\u6210\u8fde\u8d2f\u3001\u76f8\u5173\u4e14\u5bcc\u6709\u521b\u610f\u7684\u5185\u5bb9\u65b9\u9762\u7684\u5f3a\u5927\u6f5c\u529b\u3002\u968f\u7740\u5bf9\u8bdd\u7684\u6df1\u5165\uff0cQwen-7B-Chat\u8868\u73b0\u51fa\u7684\u667a\u80fd\u548c\u7075\u6d3b\u6027\u65e0\u7591\u5c06\u4e3a\u7528\u6237\u5e26\u6765\u6df1\u523b\u7684\u4ea4\u4e92\u4f53\u9a8c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a id=\"_139\"><\/a>\u516d\u3001\u7ed3\u8bed<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u672c\u7bc7\u535a\u6587\u7684\u5b9e\u8df5\u63a2\u7d22\uff0c\u6211\u4eec\u5f97\u4ee5\u4e00\u7aa5Qwen-7B-Chat\u6a21\u578b\u5728\u667a\u80fd\u5bf9\u8bdd\u9886\u57df\u7684\u5e94\u7528\u6f5c\u529b\u3002\u968f\u7740\u6280\u672f\u7684\u4e0d\u65ad\u8fdb\u6b65\u548c\u4f18\u5316\uff0c\u6211\u4eec\u6709\u7406\u7531\u76f8\u4fe1\uff0cQwen-7B-Chat\u5c06\u5728\u667a\u80fd\u52a9\u624b\u3001\u5ba2\u6237\u670d\u52a1\u3001\u6559\u80b2\u8f85\u5bfc\u7b49\u4f17\u591a\u9886\u57df\u53d1\u6325\u91cd\u8981\u4f5c\u7528\u3002\u8ba9\u6211\u4eec\u5171\u540c\u671f\u5f85\uff0c\u8fd9\u4e00\u6a21\u578b\u5c06\u5982\u4f55\u8fdb\u4e00\u6b65\u63a8\u52a8\u4eba\u673a\u4ea4\u4e92\u7684\u8fb9\u754c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/xiaobing259\/article\/details\/140081589<br>\u4f5c\u8005\uff1a\u5bfb\u9053AI\u5c0f\u5175<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u4e00\u3001\u6982\u8ff0 \u5728\u4eba\u5de5\u667a\u80fd\u9886\u57df\uff0c\u5927\u578b\u8bed\u8a00\u6a21\u578b\u7684\u53d1\u5c55\u65e5\u65b0\u6708&#8230; <\/p>\n","protected":false},"author":1,"featured_media":437,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[121],"tags":[],"class_list":["post-436","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=436"}],"version-history":[{"count":1,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/posts\/436\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/posts\/436\/revisions\/438"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=\/wp\/v2\/media\/437"}],"wp:attachment":[{"href":"https:\/\/www.bosombot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bosombot.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}