FreeChat
Open main menu
ChatGPT知识
搜索
搜索
关闭
Previous
Previous
Next
Next
Llama2开源大模型的新篇章以及在阿里云的实践
sockstack
/
139
/
2023-11-15 00:48:40
<p><span style="color: red; font-size: 18px">ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。</span><br><a href="https://ckai.xyz/?sockstack§ion=detail" target="__blank">https://ckai.xyz</a><br><br></p> <article class="_2rhmJa"><p>Llama一直被誉为AI社区中最强大的开源大模型。然而,由于开源协议的限制,它一直不能被免费用于商业用途。然而,这一切在7月19日发生了改变,当Meta终于发布了大家期待已久的免费商用版本Llama2。Llama2是一个由Meta AI开发的预训练大语言模型,它可以接受任何自然语言文本作为输入,并生成文字形式的输出。Llama2-xb-chat是基于Llama2-xb在对话场景下的优化模型,目前在大多数评测指标上超过了其他开源对话模型,并且与一些热门的闭源模型(如ChatGPT、PaLM)的表现相当。</p> <h2>官方介绍</h2> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 539px; background-color: transparent;"> <div class="image-container-fill" style="padding-bottom: 48.17%;"></div> <div class="image-view" data-width="1119" data-height="539"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-bf741cef2a60581a.png" data-original-width="1119" data-original-height="539" data-original-format="image/png" data-original-filesize="195422" data-image-index="0" style="cursor: zoom-in;" class="" src="//upload-images.jianshu.io/upload_images/29160923-bf741cef2a60581a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1119/format/webp"></div> </div> <div class="image-caption">image.png</div> </div> <p>Meta发布的Llama 2模型系列包括70亿、130亿和700亿三种参数版本。此外,他们还训练了一个340亿参数的版本,但并未发布,只在技术报告中提到。据官方介绍,Llama 2与其前身Llama 1相比,训练数据增加了40%,上下文长度也翻了一番,并采用了分组查询注意力机制。具体来说,Llama 2预训练模型是在2万亿的token上训练的,而精调Chat模型则是在100万人类标记数据上训练的。</p> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 595px; background-color: transparent;"> <div class="image-container-fill" style="padding-bottom: 59.440000000000005%;"></div> <div class="image-view" data-width="1001" data-height="595"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-161d1b00fb5b5ce0.png" data-original-width="1001" data-original-height="595" data-original-format="image/png" data-original-filesize="84381" data-image-index="1" style="cursor: zoom-in;" class="" src="//upload-images.jianshu.io/upload_images/29160923-161d1b00fb5b5ce0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1001/format/webp"></div> </div> <div class="image-caption">image.png</div> </div> <p>公布的测评结果显示,Llama 2在包括推理、编码、精通性和知识测试等许多外部基准测试中都优于其他开源语言模型。</p> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 736px;"> <div class="image-container-fill" style="padding-bottom: 105.0%;"></div> <div class="image-view" data-width="2158" data-height="2266"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-9fe17376b730bfb3.png" data-original-width="2158" data-original-height="2266" data-original-format="image/png" data-original-filesize="733597" data-image-index="2" style="cursor: zoom-in;" class="image-loading"></div> </div> <div class="image-caption">image.png</div> </div> <h2>模型部署</h2> <p>Meta在Huggingface上提供了所有模型的下载链接:<a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama" target="_blank">https://huggingface.co/meta-llama</a></p> <h3>预训练模型</h3> <p>Llama2预训练模型包含7B、13B和70B三个版本</p> <table> <thead> <tr> <th>模型名称</th> <th>模型加载名称</th> <th>下载地址</th> </tr> </thead> <tbody> <tr> <td>Llama2-7B</td> <td>meta-llama/Llama-2-7b-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-7b-hf" target="_blank">模型下载</a></td> </tr> <tr> <td>Llama2-13B</td> <td>meta-llama/Llama-2-13b-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-13b-hf" target="_blank">模型下载</a></td> </tr> <tr> <td>Llama2-70B</td> <td>meta-llama/Llama-2-70b-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-70b-hf" target="_blank">模型下载</a></td> </tr> </tbody> </table> <h3>Chat模型</h3> <p>Llama2-Chat模型基于预训练模型进行了监督微调,具备更强的对话能力</p> <table> <thead> <tr> <th>模型名称</th> <th>模型加载名称</th> <th>下载地址</th> </tr> </thead> <tbody> <tr> <td>Llama2-7B-Chat</td> <td>meta-llama/Llama-2-7b-chat-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-7b-chat-hf" target="_blank">模型下载</a></td> </tr> <tr> <td>Llama2-13B-Chat</td> <td>meta-llama/Llama-2-13b-chat-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-13b-chat-hf" target="_blank">模型下载</a></td> </tr> <tr> <td>Llama2-70B-Chat</td> <td>meta-llama/Llama-2-70b-chat-hf</td> <td><a href="https://links.jianshu.com/go?to=https%3A%2F%2Fhuggingface.co%2Fmeta-llama%2FLlama-2-70b-chat-hf" target="_blank">模型下载</a></td> </tr> </tbody> </table> <h2>阿里云机器学习平台PAI</h2> <p>机器学习平台PAI(Platform of Artificial Intelligence)面向企业客户及开发者,提供轻量化、高性价比的云原生机器学习,涵盖PAI-DSW交互式建模、PAI-Studio拖拽式可视化建模、PAI-DLC分布式训练到PAI-EAS模型在线部署的全流程。</p> <h3>PAI平台部署</h3> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 671px;"> <div class="image-container-fill" style="padding-bottom: 49.09%;"></div> <div class="image-view" data-width="1367" data-height="671"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-b59f2e48466d6051.png" data-original-width="1367" data-original-height="671" data-original-format="image/png" data-original-filesize="393380" data-image-index="3" style="cursor: zoom-in;" class="image-loading"></div> </div> <div class="image-caption">image.png</div> </div> <p>今天PAI平台也对Llama2-7b做了支持,提供了相关的镜像可以直接部署。模型部署后,用户可以在服务详情页面通过“查看Web应用”按钮来在网页端直接和模型推理交互。让我们来体验一下吧!</p> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 640px;"> <div class="image-container-fill" style="padding-bottom: 48.16%;"></div> <div class="image-view" data-width="1329" data-height="640"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-f228ced3ec705d64.png" data-original-width="1329" data-original-height="640" data-original-format="image/png" data-original-filesize="527924" data-image-index="4" style="cursor: zoom-in;" class="image-loading"></div> </div> <div class="image-caption">image.png</div> </div> <p>部署完成后:</p> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 639px;"> <div class="image-container-fill" style="padding-bottom: 43.03%;"></div> <div class="image-view" data-width="1485" data-height="639"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-be61900ecc3b1cc3.png" data-original-width="1485" data-original-height="639" data-original-format="image/png" data-original-filesize="337765" data-image-index="5" style="cursor: zoom-in;" class="image-loading"></div> </div> <div class="image-caption">image.png</div> </div> <p>进入Web页面来测试一下:</p> <div class="image-package"> <div class="image-container" style="max-width: 700px; max-height: 369px;"> <div class="image-container-fill" style="padding-bottom: 52.61%;"></div> <div class="image-view" data-width="1475" data-height="776"><img referrerpolicy="no-referrer" data-original-src="//upload-images.jianshu.io/upload_images/29160923-92249732c4a8755b.png" data-original-width="1475" data-original-height="776" data-original-format="image/png" data-original-filesize="471441" data-image-index="6" style="cursor: zoom-in;" class="image-loading"></div> </div> <div class="image-caption">image.png</div> </div> <p>此外,也支持了通过API形式直接推理,但需要前往EAS服务并将服务运行命令更新为python api/api_server.py --port=8000 --model-path=<先前填入的model-path>。服务请求Body为输入text/plain格式文本或application/json格式,返回数据为text/html格式。以下为发送请求的格式示例:</p> <div class="_2Uzcx_"> <button class="VJbwyy" type="button" aria-label="复制代码"><i aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></i></button><pre class="line-numbers language-json"><code class=" language-json"><span class="token punctuation">{</span><span class="token property">"input_ids"</span><span class="token operator">:</span> <span class="token string">"List the largest islands which begin with letter 's'."</span><span class="token punctuation">,</span><span class="token property">"temperature"</span><span class="token operator">:</span> <span class="token number">0.8</span><span class="token punctuation">,</span><span class="token property">"max_length"</span><span class="token operator">:</span> <span class="token number">5120</span><span class="token punctuation">,</span><span class="token property">"top_p"</span><span class="token operator">:</span> <span class="token number">0.9</span><span class="token punctuation">}</span> <span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre> </div> <h3>API详情</h3> <p>LLAMA2模型API调用需"申请体验"并通过后才可使用,否则API调用将返回错误状态码。以下示例展示了调用LLAMA2模型对一个用户指令进行响应的代码。</p> <h4>Python</h4> <div class="_2Uzcx_"> <button class="VJbwyy" type="button" aria-label="复制代码"><i aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></i></button><pre class="line-numbers language-python"><code class=" language-python"><span class="token comment"># For prerequisites running the following sample, visit https://help.aliyun.com/document_detail/611472.html</span> <span class="token keyword">from</span> http <span class="token keyword">import</span> HTTPStatus <span class="token keyword">from</span> dashscope <span class="token keyword">import</span> Generation <span class="token keyword">def</span> <span class="token function">simple_sample</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment"># 模型可以为模型列表中任一模型</span> response <span class="token operator">=</span> Generation<span class="token punctuation">.</span>call<span class="token punctuation">(</span>model<span class="token operator">=</span><span class="token string">'llama2-7b-chat-v2'</span><span class="token punctuation">,</span> prompt<span class="token operator">=</span><span class="token string">'Hey, are you conscious? Can you talk to me?'</span><span class="token punctuation">)</span> <span class="token keyword">if</span> response<span class="token punctuation">.</span>status_code <span class="token operator">==</span> HTTPStatus<span class="token punctuation">.</span>OK<span class="token punctuation">:</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'Result is: %s'</span> <span class="token operator">%</span> response<span class="token punctuation">.</span>output<span class="token punctuation">)</span> <span class="token keyword">else</span><span class="token punctuation">:</span> <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'Failed request_id: %s, status_code: %s, code: %s, message:%s'</span> <span class="token operator">%</span> <span class="token punctuation">(</span>response<span class="token punctuation">.</span>request_id<span class="token punctuation">,</span> response<span class="token punctuation">.</span>status_code<span class="token punctuation">,</span> response<span class="token punctuation">.</span>code<span class="token punctuation">,</span> response<span class="token punctuation">.</span>message<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span> simple_sample<span class="token punctuation">(</span><span class="token punctuation">)</span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre> </div> <p>响应示例</p> <div class="_2Uzcx_"> <button class="VJbwyy" type="button" aria-label="复制代码"><i aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></i></button><pre class="line-numbers language-json"><code class=" language-json"><span class="token punctuation">{</span><span class="token property">"text"</span><span class="token operator">:</span> <span class="token string">"Hey, are you conscious? Can you talk to me?\n[/Inst: Hey, I'm not sure if I'm conscious or not. I can't really feel anything or think very clearly. Can you tell me"</span><span class="token punctuation">}</span> <span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre> </div> <h4>HTTP调用接口</h4> <div class="_2Uzcx_"> <button class="VJbwyy" type="button" aria-label="复制代码"><i aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></i></button><pre class="line-numbers language-rust"><code class=" language-rust">curl <span class="token operator">-</span><span class="token operator">-</span>location <span class="token lifetime-annotation symbol">'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation</span>' \ <span class="token operator">-</span><span class="token operator">-</span>header <span class="token lifetime-annotation symbol">'Authorization:</span> Bearer <span class="token operator"><</span>your<span class="token operator">-</span>dashscope<span class="token operator">-</span>api<span class="token operator">-</span>key<span class="token operator">></span>' \ <span class="token operator">-</span><span class="token operator">-</span>header <span class="token lifetime-annotation symbol">'Content-Type:</span> application<span class="token operator">/</span>json' \ <span class="token operator">-</span><span class="token operator">-</span>data <span class="token lifetime-annotation symbol">'{</span> <span class="token string">"model"</span><span class="token punctuation">:</span> <span class="token string">"llama2-7b-v2"</span><span class="token punctuation">,</span> <span class="token string">"input"</span><span class="token punctuation">:</span><span class="token punctuation">{</span> <span class="token string">"prompt"</span><span class="token punctuation">:</span><span class="token string">"Hey, are you conscious? Can you talk to me?"</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>' <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre> </div> <p>响应示例</p> <div class="_2Uzcx_"> <button class="VJbwyy" type="button" aria-label="复制代码"><i aria-label="icon: copy" class="anticon anticon-copy"><svg viewbox="64 64 896 896" focusable="false" class="" data-icon="copy" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c2.2 2.2 4.7 4 7.4 5.5v1.9h4.2c3.5 1.3 7.2 2 11 2H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM350 856.2L263.9 770H350v86.2zM664 888H414V746c0-22.1-17.9-40-40-40H232V264h432v624z"></path></svg></i></button><pre class="line-numbers language-json"><code class=" language-json"><span class="token punctuation">{</span> <span class="token property">"output"</span><span class="token operator">:</span><span class="token punctuation">{</span> <span class="token property">"text"</span><span class="token operator">:</span><span class="token string">"Hey, are you conscious? Can you talk to me?\nLeaders need to be conscious of what’s going on around them, and not just what’s happening within their own heads.\nThis means listening to your team."</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token property">"request_id"</span><span class="token operator">:</span><span class="token string">"fbd7e41a-363c-938a-81be-8ae0f9fbdb3d"</span> <span class="token punctuation">}</span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre> </div> <p>随着时间的推移,基于Llama2开源模型的应用预计将在国内如雨后春笋般涌现。这种趋势反映了从依赖外部技术向自主研发的转变,这不仅能满足我们特定的需求和目标,也能避免依赖外部技术的风险。因此,我们更期待看到优秀的、独立的、自主的大模型的出现,这将推动我们的AI技术的发展和进步。</p> <p>更深入的内容后续学习后再总结吧</p> </article>
Llama2开源大模型的新篇章以及在阿里云的实践
作者
sockstack
许可协议
CC BY 4.0
发布于
2023-11-15
修改于
2024-11-09
上一篇:软件:常用 Linux 软件汇总,值得收藏
下一篇:Podman vs Docker:有什么区别?