{"id":1516,"date":"2023-08-10T19:54:29","date_gmt":"2023-08-10T11:54:29","guid":{"rendered":"https:\/\/rain1024.com\/?p=1516"},"modified":"2023-08-10T19:54:29","modified_gmt":"2023-08-10T11:54:29","slug":"%e9%80%9a%e4%b9%89%e5%8d%83%e9%97%ae%e5%bc%80%e6%ba%90%e6%a8%a1%e5%9e%8b%e9%83%a8%e7%bd%b2%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2023\/08\/10\/%e9%80%9a%e4%b9%89%e5%8d%83%e9%97%ae%e5%bc%80%e6%ba%90%e6%a8%a1%e5%9e%8b%e9%83%a8%e7%bd%b2%e4%bd%bf%e7%94%a8\/","title":{"rendered":"\u901a\u4e49\u5343\u95ee\u5f00\u6e90\u6a21\u578b\u90e8\u7f72\u4f7f\u7528"},"content":{"rendered":"<p>\u9996\u5148\u53ef\u4ee5\u53c2\u8003modelScope\u793e\u533a\u7ed9\u51fa\u7684\u4f7f\u7528\u6587\u6863\uff0c\u5df2\u7ecf\u8db3\u591f\u5168\u9762<\/p>\n<p><a href=\"https:\/\/modelscope.cn\/models\/qwen\/Qwen-7B-Chat\/quickstart\">https:\/\/modelscope.cn\/models\/qwen\/Qwen-7B-Chat\/quickstart<\/a><\/p>\n<p>\u4f46\u5728\u6309\u7167\u6587\u6863\u4e2d\u6b65\u9aa4\u90e8\u7f72\u65f6\uff0c\u8fd8\u662f\u6709\u4e9b\u9519\u8bef\u95ee\u9898\u53d1\u751f\uff0c\u53ef\u4ee5\u641c\u7d22\u53c2\u8003\u7684\u89e3\u51b3\u65b9\u5f0f\u4e0d\u591a\uff0c\u6240\u4ee5\u8bb0\u5f55\u4e0b\u6765<\/p>\n<h3>\u4e2a\u4eba\u7535\u8111\u90e8\u7f72<\/h3>\n<p>\u8fd9\u91cc\u4e0d\u592a\u5efa\u8bae\u4f7f\u7528\u81ea\u5df1\u7684\u7b14\u8bb0\u672c\u90e8\u7f72\u901a\u4e49\u5343\u95ee\u6a21\u578b\uff0c\u56e0\u4e3a\u5b9e\u5728\u662f\u592a\u8017\u8d44\u6e90\uff0c\u6211\u4f7f\u7528\u7684M2\u82af\u7247\u7684MacBook Pro\u5373\u4f7f\u8fd0\u884c\u8d77\u6765\u4e86\uff0c\u4f46\u6a21\u578b\u56de\u7b54\u4e00\u4e2a\u95ee\u9898\u90fd\u9700\u8981\u56db\u4e94\u5206\u949f\u7684\u65f6\u95f4\uff0c\u5185\u5b58\u5168\u90e8\u5360\u6ee1\uff0c\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4e5f\u90fd\u5f3a\u5236\u9000\u51fa\u4e86\u3002\u6240\u4ee5\u8fd8\u662f\u4f7f\u7528\u793e\u533a\u63d0\u4f9b\u7684\u514d\u8d39\u8d44\u6e90\uff0c\u6216\u8005\u6709\u66f4\u9ad8\u914d\u7f6e\u7684\u670d\u52a1\u5668\u6765\u90e8\u7f72\u6a21\u578b\u3002\u800c\u4e14\u671f\u95f4\u8fd8\u6709\u5404\u79cd\u95ee\u9898\uff0c\u641c\u4e86\u5f88\u591agithub\u4e0a\u7684\u95ee\u7b54\u624d\u89e3\u51b3\uff0c\u8017\u65f6\u8017\u529b\uff0c\u8fd9\u91cc\u5c31\u4e0d\u8bb0\u5f55\u4e86\uff0c\u5f88\u4e0d\u63a8\u8350\u8fd9\u79cd\u65b9\u5f0f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff669eb1.png\" alt=\"\" \/><\/p>\n<h3>\u514d\u8d39\u7b97\u529b\u670d\u52a1\u5668<\/h3>\n<p>\u6253\u5f00modelScope\u793e\u533a\u540e\uff0c\u70b9\u51fb\u767b\u5f55\u6ce8\u518c\u53ef\u4ee5\u770b\u5230\u514d\u8d39\u8d60\u9001\u7b97\u529b\u7684\u6d3b\u52a8<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff6e106a.png\" alt=\"\" \/><\/p>\n<p>\u6ce8\u518c\u5b8c\u6210\u540e\u5728\u5bf9\u5e94\u6a21\u578b\u91cc\u53ef\u4ee5\u770b\u5230\uff0c\u968f\u65f6\u90fd\u80fd\u542f\u7528\u7684\u670d\u52a1\u5668<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff75a4c8.png\" alt=\"\" \/><\/p>\n<p>\u8fd9\u91ccCPU\u73af\u5883\u7684\u670d\u52a1\u5668\u52c9\u5f3a\u53ef\u4ee5\u8dd1\u8d77\u6765\u6a21\u578b\uff0c\u4f46\u8fd0\u884c\u6548\u679c\u611f\u4eba\uff0c\u800c\u4e14\u914d\u7f6e\u8fc7\u7a0b\u4e2d\u6709\u5404\u79cd\u95ee\u9898\u9700\u8981\u4fee\u6539\uff0c\u800cGPU\u73af\u5883\u542f\u52a8\u6a21\u578b\u53ef\u4ee5\u8bf4\u662f\u975e\u5e38\u6d41\u7545\uff0c\u4f53\u9a8c\u6548\u679c\u4e5f\u5f88\u597d<\/p>\n<h3>CPU\u73af\u5883\u542f\u52a8<\/h3>\n<p>\u793e\u533a\u63d0\u4f9b\u7684\u670d\u52a1\u5668\u914d\u7f6e\u5df2\u7ecf\u5f88\u9ad8\u4e86\uff0c8\u683832G\uff0c\u4f46\u56e0\u4e3a\u662f\u7eafCPU\u73af\u5883\uff0c\u542f\u52a8\u8fc7\u7a0b\u4e2d\u8fd8\u662f\u6709\u4e9b\u95ee\u9898<\/p>\n<h4>\u5b89\u88c5\u4f9d\u8d56\u5305<\/h4>\n<p>\u7b2c\u4e00\u884c\u547d\u4ee4\u4e0d\u9700\u8981\u8fd0\u884c\uff0c\u670d\u52a1\u5668\u5df2\u7ecf\u81ea\u5e26\u4e86modelscope\u5305<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff7c559c.png\" alt=\"\" \/><\/p>\n<p>\u53ea\u9700\u8981\u65b0\u5efa\u4e00\u4e2aTerminal\u7a97\u53e3\u6765\u6267\u884c\u7b2c\u4e8c\u6761\u547d\u4ee4<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff825037.png\" alt=\"\" \/><\/p>\n<h4>\u542f\u52a8\u4ee3\u7801<\/h4>\n<p>\u76f4\u63a5\u8fd0\u884c\u6587\u6863\u63d0\u4f9b\u7684\u4ee3\u7801\u4f1a\u62a5\u9519\uff0c\u8fd9\u91cc\u662f\u56e0\u4e3a\u7eafCPU\u73af\u5883\u5bfc\u81f4\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff8922c5.png\" alt=\"\" \/><\/p>\n<h4>\u9519\u8bef 1<\/h4>\n<p>RuntimeError: &quot;addmm_impl<em>cpu<\/em>&quot; not implemented for 'Half'Hide Error Details<\/p>\n<pre><code>RuntimeError: &quot;addmm_impl_cpu_&quot; not implemented for &#039;Half&#039;\n---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\nCell In[1], line 8\n      5 model = AutoModelForCausalLM.from_pretrained(&quot;qwen\/Qwen-7B-Chat&quot;, revision = &#039;v1.0.5&#039;,device_map=&quot;auto&quot;, trust_remote_code=True,fp16 = True).eval()\n      6 model.generation_config = GenerationConfig.from_pretrained(&quot;Qwen\/Qwen-7B-Chat&quot;,revision = &#039;v1.0.5&#039;, trust_remote_code=True) # \u53ef\u6307\u5b9a\u4e0d\u540c\u7684\u751f\u6210\u957f\u5ea6\u3001top_p\u7b49\u76f8\u5173\u8d85\u53c2\n----&gt; 8 response, history = model.chat(tokenizer, &quot;\u4f60\u597d&quot;, history=None)\n      9 print(response)\n     10 response, history = model.chat(tokenizer, &quot;\u6d59\u6c5f\u7684\u7701\u4f1a\u5728\u54ea\u91cc\uff1f&quot;, history=history) \n\nFile ~\/.cache\/huggingface\/modules\/transformers_modules\/Qwen-7B-Chat\/modeling_qwen.py:1010, in QWenLMHeadModel.chat(self, tokenizer, query, history, system, append_history, stream, stop_words_ids, **kwargs)\n   1006 stop_words_ids.extend(get_stop_words_ids(\n   1007     self.generation_config.chat_format, tokenizer\n   1008 ))\n   1009 input_ids = torch.tensor([context_tokens]).to(self.device)\n-&gt; 1010 outputs = self.generate(\n   1011             input_ids,\n   1012             stop_words_ids = stop_words_ids,\n   1013             return_dict_in_generate = False,\n   1014             **kwargs,\n   1015         )\n   1017 response = decode_tokens(\n   1018     outputs[0],\n   1019     tokenizer,\n   (...)\n   1024     errors=&#039;replace&#039;\n   1025 )\n   1027 if append_history:<\/code><\/pre>\n<h4>\u9519\u8bef 2<\/h4>\n<p>ValueError: The current <code>device_map<\/code> had weights offloaded to the disk. Please provide an <code>offload_folder<\/code> for them. Alternatively, make sure you have <code>safetensors<\/code> installed if the model you are using offers the weights in this format.Hide Error Details<\/p>\n<pre><code>ValueError: The current `device_map` had weights offloaded to the disk. Please provide an `offload_folder` for them. Alternatively, make sure you have `safetensors` installed if the model you are using offers the weights in this format.\n---------------------------------------------------------------------------\nValueError                                Traceback (most recent call last)\nCell In[2], line 5\n      2 from modelscope import GenerationConfig\n      4 tokenizer = AutoTokenizer.from_pretrained(&quot;qwen\/Qwen-7B-Chat&quot;, revision = &#039;v1.0.5&#039;,trust_remote_code=True)\n----&gt; 5 model = AutoModelForCausalLM.from_pretrained(&quot;qwen\/Qwen-7B-Chat&quot;, revision = &#039;v1.0.5&#039;,device_map=&quot;auto&quot;, trust_remote_code=True,fp16 = True).eval()\n      6 model.generation_config = GenerationConfig.from_pretrained(&quot;Qwen\/Qwen-7B-Chat&quot;,revision = &#039;v1.0.5&#039;, trust_remote_code=True) # \u53ef\u6307\u5b9a\u4e0d\u540c\u7684\u751f\u6210\u957f\u5ea6\u3001top_p\u7b49\u76f8\u5173\u8d85\u53c2\n      7 model.float()\n\nFile \/opt\/conda\/lib\/python3.8\/site-packages\/modelscope\/utils\/hf_util.py:98, in get_wrapped_class.&lt;locals&gt;.ClassWrapper.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)\n     95 else:\n     96     model_dir = pretrained_model_name_or_path\n---&gt; 98 model = module_class.from_pretrained(model_dir, *model_args,\n     99                                      **kwargs)\n    100 model.model_dir = model_dir\n    101 return model<\/code><\/pre>\n<h3>\u89e3\u51b3\u65b9\u5f0f<\/h3>\n<p>\u9996\u5148\u786e\u4fddtorch 2.0.1\u7248\u672c\uff0c\u7136\u540e\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u8fd9\u4e24\u884c\uff0c\u5373\u53ef\u8fd0\u884c<\/p>\n<p>model.float()<\/p>\n<p>offload_folder=&quot;offload_folder&quot;,<\/p>\n<pre><code>from modelscope import AutoModelForCausalLM, AutoTokenizer\nfrom modelscope import GenerationConfig\nimport datetime\nprint(&quot;\u542f\u52a8\u65f6\u95f4\uff1a&quot; + str(datetime.datetime.now()))\ntokenizer = AutoTokenizer.from_pretrained(&quot;qwen\/Qwen-7B-Chat&quot;, revision = &#039;v1.0.5&#039;,trust_remote_code=True)\nmodel = AutoModelForCausalLM.from_pretrained(&quot;qwen\/Qwen-7B-Chat&quot;, revision = &#039;v1.0.5&#039;,device_map=&quot;auto&quot;,offload_folder=&quot;offload_folder&quot;, trust_remote_code=True,fp16 = True).eval()\nmodel.generation_config = GenerationConfig.from_pretrained(&quot;Qwen\/Qwen-7B-Chat&quot;,revision = &#039;v1.0.5&#039;, trust_remote_code=True) # \u53ef\u6307\u5b9a\u4e0d\u540c\u7684\u751f\u6210\u957f\u5ea6\u3001top_p\u7b49\u76f8\u5173\u8d85\u53c2\nmodel.float()\n\nprint(&quot;\u5f00\u59cb\u6267\u884c\uff1a&quot; + str(datetime.datetime.now()))\nresponse, history = model.chat(tokenizer, &quot;\u4f60\u597d&quot;, history=None)\nprint(response)\nprint(&quot;\u7b2c\u4e00\u4e2a\u95ee\u9898\u5904\u7406\u5b8c\u6bd5\uff1a&quot; + str(datetime.datetime.now()))\nresponse, history = model.chat(tokenizer, &quot;\u6d59\u6c5f\u7684\u7701\u4f1a\u5728\u54ea\u91cc\uff1f&quot;, history=history) \nprint(response)\nprint(&quot;\u7b2c\u4e8c\u4e2a\u95ee\u9898\u5904\u7406\u5b8c\u6bd5\uff1a&quot; + str(datetime.datetime.now()))\nresponse, history = model.chat(tokenizer, &quot;\u5b83\u6709\u4ec0\u4e48\u597d\u73a9\u7684\u666f\u70b9&quot;, history=history)\nprint(response)\nprint(&quot;\u7b2c\u4e09\u4e2a\u95ee\u9898\u5904\u7406\u5b8c\u6bd5\uff1a&quot; + str(datetime.datetime.now()))<\/code><\/pre>\n<p>\u8fd0\u884c\u8d77\u6765\u4e4b\u540e\u901f\u5ea6\u5b9e\u5728\u611f\u4eba\uff0c\u6ca1\u56de\u7b54\u4e00\u4e2a\u95ee\u9898\u90fd\u9700\u8981 5 \u5206\u949f\u5de6\u53f3\uff0c\u8fd8\u6709\u4e00\u5b9a\u6982\u7387\u76f4\u63a5\u542f\u52a8\u5931\u8d25<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff92859d.png\" alt=\"\" \/><\/p>\n<p>\u542f\u52a8\u6a21\u578b\u8fc7\u7a0b\u4e2d\u4f1a\u51fa\u73b0\u8fd9\u79cd\u62a5\u9519\uff0c\u70b9\u51fbOK\u91cd\u65b0\u6267\u884c\u5c31\u597d\u4e86\uff0c\u53ef\u80fd\u662f\u670d\u52a1\u5668\u8d1f\u8f7d\u592a\u9ad8<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cff998b17.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/08\/post-1516-64d4cffa24ffd.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u53ef\u4ee5\u53c2\u8003modelScope\u793e\u533a\u7ed9\u51fa\u7684\u4f7f\u7528\u6587\u6863\uff0c\u5df2\u7ecf\u8db3\u591f\u5168\u9762 https:\/\/modelscope.cn\/\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2023\/08\/10\/%e9%80%9a%e4%b9%89%e5%8d%83%e9%97%ae%e5%bc%80%e6%ba%90%e6%a8%a1%e5%9e%8b%e9%83%a8%e7%bd%b2%e4%bd%bf%e7%94%a8\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1517,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-1516","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technique"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=1516"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1516\/revisions"}],"predecessor-version":[{"id":1518,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1516\/revisions\/1518"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/1517"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=1516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=1516"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=1516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}