<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>本地部署 on Harry AI</title><link>https://harryai.cc/tags/%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/</link><description>Recent content in 本地部署 on Harry AI</description><generator>Hugo -- gohugo.io</generator><language>zh-cn</language><managingEditor>harryliuwx888@gmail.com (Harry)</managingEditor><webMaster>harryliuwx888@gmail.com (Harry)</webMaster><copyright>Copyright © 深圳市网旭科技有限公司。&lt;a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备14077691号&lt;/a></copyright><lastBuildDate>Sat, 03 Aug 2024 12:30:01 +0800</lastBuildDate><atom:link href="https://harryai.cc/tags/%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/index.xml" rel="self" type="application/rss+xml"/><item><title>阿里开源 CosyVoice 语音克隆 部署和使用</title><link>https://harryai.cc/post/cosyvoice/</link><pubDate>Sat, 03 Aug 2024 12:30:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/cosyvoice/</guid><description>&lt;p>应该是 &lt;strong>开源界 音色 最稳定&lt;/strong> 的语音合成和克隆模型了，支持预训练音色合成、自然语言控制、3秒极速复刻和跨语种复刻。&lt;/p>
&lt;p>官方部署方式比较复杂，错误较多，我这里进行了整理和优化，&lt;strong>支持GPU和CPU&lt;/strong>，方便大家使用。&lt;/p>
&lt;p>CosyVoice 开源仓库: &lt;a href="https://github.com/FunAudioLLM/CosyVoice">CosyVoice&lt;/a>&lt;/p>
&lt;h2 id="效果展示">效果展示&lt;/h2>
&lt;h3 id="自然语言控制">自然语言控制&lt;/h3>
&lt;img src="https://harryai.cc/post/cosyvoice/1.jpg" alt="image" class="center" width="600">&lt;h3 id="3秒极速复刻">3秒极速复刻&lt;/h3>
&lt;img src="https://harryai.cc/post/cosyvoice/2.jpg" alt="image" class="center" width="600">&lt;h2 id="使用方法">使用方法&lt;/h2>
&lt;blockquote>
&lt;p>均支持 GPU 和 CPU&lt;/p>
&lt;p>第一次启动过程可能会有点长，需要从魔搭下载3个模型&lt;/p>&lt;/blockquote>
&lt;h3 id="windows-一键启动包">Windows 一键启动包&lt;/h3>
&lt;p>百度网盘: &lt;a href="https://pan.baidu.com/s/1UTuRKPQ9nuQk69qxQzdL4A?pwd=j2ei">https://pan.baidu.com/s/1UTuRKPQ9nuQk69qxQzdL4A?pwd=j2ei&lt;/a> 提取码: j2ei&lt;/p>
&lt;ul>
&lt;li>下载后使用 7z 解压。没有 7z 的话，可以在这里下载：&lt;a href="https://7-zip.org/download.html">https://7-zip.org/download.html&lt;/a>&lt;/li>
&lt;li>双击 &lt;code>双击启动.bat&lt;/code> 启动服务&lt;/li>
&lt;li>启动后，访问 &lt;a href="http://127.0.0.1:50000/">http://127.0.0.1:50000/&lt;/a>&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>注意：文件夹中不能有 &lt;strong>中文&lt;/strong>、&lt;strong>特殊字符&lt;/strong>和&lt;strong>空格&lt;/strong>，否则可能会启动失败&lt;/p>&lt;/blockquote>
&lt;h3 id="docker部署">Docker部署🐳&lt;/h3>
&lt;blockquote>
&lt;p>确保已经安装了Docker软件，没有的话，从官网下载安装 &lt;a href="https://www.docker.com/products/docker-desktop/">https://www.docker.com/products/docker-desktop/&lt;/a>&lt;/p>&lt;/blockquote>
&lt;p>复制以下代码到终端运行即可&lt;/p>
&lt;h4 id="cpu-版本">CPU 版本&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl -fsSL https://harryai.cc/cosyvoice/docker-compose.yml -o docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="gpu-版本">GPU 版本&lt;/h4>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2">2&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl -fsSL https://harryai.cc/cosyvoice/docker-compose-gpu.yml -o docker-compose.yml
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker-compose up
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>docker 启动后，访问 &lt;a href="http://127.0.0.1:50000/">http://127.0.0.1:50000/&lt;/a>&lt;/strong>&lt;/p></description></item><item><title>ChatTTS 开源语音合成服务的部署和使用</title><link>https://harryai.cc/post/chat-tts/</link><pubDate>Wed, 29 May 2024 20:16:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/chat-tts/</guid><description>&lt;p>项目地址：&lt;a href="https://github.com/2noise/ChatTTS">https://github.com/2noise/ChatTTS&lt;/a>&lt;/p>
&lt;p>&lt;strong>Windows 用户建议直接下载一键启动包，运行环境和模型都已经配置好，使用更简单。&lt;/strong>&lt;/p>
&lt;h2 id="windows-一键启动包">Windows 一键启动包&lt;/h2>
&lt;p>百度网盘下载：&lt;a href="https://pan.baidu.com/s/1wfdqQDTzDnMf01bV1wzKgQ?pwd=v2kb">https://pan.baidu.com/s/1wfdqQDTzDnMf01bV1wzKgQ?pwd=v2kb&lt;/a>
提取码：v2kb&lt;/p>
&lt;p>&lt;strong>解压密码：harryai&lt;/strong>&lt;/p>
&lt;p>&lt;strong>下载后解压&lt;/strong>，然后双击 &lt;code>启动服务.bat&lt;/code> 即可。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/windows.jpg" alt="启动服务" class="center" width="600">&lt;p>启动成功后，会自动打开 &lt;a href="http://localhost:8080/">http://localhost:8845/&lt;/a> 页面。&lt;/p>
&lt;p>输入文本内容，即可合成语音。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/webui.jpg" alt="Web效果演示" class="center" width="600">&lt;h2 id="手动部署">手动部署&lt;/h2>
&lt;h3 id="1-下载代码">1. 下载代码&lt;/h3>
&lt;p>&lt;a href="https://harryai.cc/chat-tts/code.zip">点击下载代码压缩包&lt;/a>，然后解压到本地。&lt;/p>
&lt;h3 id="2-下载模型">2. 下载模型&lt;/h3>
&lt;p>从魔搭下载 &lt;a href="https://www.modelscope.cn/models/pzc163/chatTTS/summary">https://www.modelscope.cn/models/pzc163/chatTTS/summary&lt;/a>
建议使用 git 克隆&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>git clone https://www.modelscope.cn/pzc163/chatTTS.git
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>注意：魔搭里面缺少文件 &lt;code>spk_stat.pt&lt;/code>，&lt;a href="https://harryai.cc/chat-tts/spk_stat.pt">点击这里&lt;/a> 下载，然后放到 chatTTS/asset 目录下。&lt;/p>
&lt;p>再将下载的整个文件夹，放到 &lt;code>models&lt;/code> 文件夹下，结构如下：&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/folder.jpg" alt="文件夹结构" class="center" width="600">&lt;h3 id="3-安装依赖">3. 安装依赖&lt;/h3>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>pip install -r requirements.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="4-启动服务">4. 启动服务&lt;/h3>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>python webui.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>启动成功后，会自动打开 &lt;a href="http://localhost:8080/">http://localhost:8845/&lt;/a> 页面，输入文本内容，即可合成语音。&lt;/p>
&lt;img src="https://harryai.cc/post/chat-tts/webui.jpg" alt="Web效果演示" class="center" width="600"></description></item><item><title>只需3分钟，基于 LLaMA3-8B 微调一个属于你自己的嬛嬛</title><link>https://harryai.cc/post/llama3-fine-tuning/</link><pubDate>Fri, 03 May 2024 17:56:01 +0800</pubDate><author>harryliuwx888@gmail.com (Harry)</author><guid>https://harryai.cc/post/llama3-fine-tuning/</guid><description>&lt;blockquote>
&lt;p>注意：没有GPU，也可以微调一个属于你自己的大模型，只是微调的时间长一点而已，建议晚上睡觉前运行，第二天早上就可以使用了 😄&lt;/p>&lt;/blockquote>
&lt;h2 id="效果演示">效果演示&lt;/h2>
&lt;img src="https://harryai.cc/post/llama3-fine-tuning/chatbot2.jpg" alt="ChatBot对话页">&lt;h2 id="部署环境">部署环境&lt;/h2>
&lt;ol>
&lt;li>点击下载 &lt;a href="https://harryai.cc/llama3-fine-tuning/llama3-ft.zip">LLaMA3-8B 微调代码压缩包&lt;/a>&lt;/li>
&lt;li>将下载的压缩包解压&lt;/li>
&lt;li>在 &lt;strong>终端 (macOS)&lt;/strong> 或 &lt;strong>cmd命令提示符 (Windows)&lt;/strong> 里面，进入解压后的文件夹，创建一个新的 Conda 虚拟环境
&lt;blockquote>
&lt;p>未安装 Conda 的用户，可以到 &lt;a href="https://conda.io/projects/conda/en/latest/index.html">Conda官网下载安装&lt;/a>。&lt;/p>&lt;/blockquote>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3">3&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cd llama3-ft
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>conda create -n llama3-ft python&lt;span style="color:#f92672">=&lt;/span>3.10
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>conda activate llama3-ft
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>安装依赖包
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>pip install -r requirements.txt
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;h2 id="数据准备">数据准备&lt;/h2>
&lt;p>你可以直接使用 &lt;code>dataset/huanhuan.json&lt;/code> 数据集（该数据集来源于 &lt;a href="https://github.com/KMnO4-zx">https://github.com/KMnO4-zx&lt;/a> ），&lt;strong>也可以自己准备数据集
，比如你的客服对话（FAQ）数据集，这样就可以微调一个更适合你的智能客服的模型，客服回答更准确&lt;/strong>。&lt;/p>
&lt;p>数据集的格式也比较简单，示例如下：&lt;/p>
&lt;ul>
&lt;li>&lt;code>instruction&lt;/code> 是问题&lt;/li>
&lt;li>&lt;code>output&lt;/code> 是回答&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-12">12&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>[
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;instruction&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;你好&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;input&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;output&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;皇上好，我是甄嬛，家父是大理寺少卿甄远道。&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> },
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;instruction&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;你不愿意见我？&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;input&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;&amp;#34;&lt;/span>,
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;#34;output&amp;#34;&lt;/span>: &lt;span style="color:#e6db74">&amp;#34;不该相见自然不愿见，还望王爷尊重我的意愿。&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="模型微调">模型微调&lt;/h2>
&lt;h3 id="模型选择">模型选择&lt;/h3>
&lt;p>我使用的是 &lt;a href="https://www.modelscope.cn/studios/LLM-Research/Chat_Llama-3-8B/summary">LLM-Research/Meta-Llama-3-8B-Instruct&lt;/a>
，你也可以选择一个其他模型，只需要修改 &lt;code>train.py&lt;/code> 文件里面的 &lt;code>model_id&lt;/code> 变量即可。&lt;/p>
&lt;p>由于国内访问 HuggingFace 比较困难，因此使用 &lt;a href="https://www.modelscope.cn">ModelScope&lt;/a> 提供的模型。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6">6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-7">7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-8">8&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 需要微调的基座模型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># https://www.modelscope.cn/studios/LLM-Research/Chat_Llama-3-8B/summary&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>model_id &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#39;LLM-Research/Meta-Llama-3-8B-Instruct&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 比如你也可以使用 Qwen1.5-4B-Chat 模型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># https://www.modelscope.cn/models/qwen/Qwen1.5-4B-Chat/summary&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># model_id = &amp;#39;qwen/Qwen1.5-4B-Chat&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="开始微调">开始微调&lt;/h3>
&lt;p>只需要在项目根目录下执行以下命令即可。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>python train.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>或者可以打开 &lt;code>LLaMA3-8B-Instruct Lora.ipynb&lt;/code> 文件，使用 Jupyter Notebook 进行微调。&lt;/p>
&lt;blockquote>
&lt;p>注意：&lt;/p>&lt;/blockquote>
&lt;ol>
&lt;li>微调的时间会根据你的数据集大小和模型大小而定。我由于没有 GPU，因此耗时2个小时，如果你有 GPU，大概需要 30 分钟。&lt;/li>
&lt;li>代码会自动下载模型，然后开始微调&lt;/li>
&lt;li>微调完成后，所有的文件会保存在 &lt;code>models&lt;/code> 文件夹下面，结构如下：
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1"> 1&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2"> 2&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-3">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-3"> 3&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-4">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-4"> 4&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-5">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-5"> 5&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-6">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-6"> 6&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-7">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-7"> 7&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-8">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-8"> 8&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-9">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-9"> 9&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-10">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-10">10&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-11">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-11">11&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-12">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-12">12&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-13">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-13">13&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-14">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-14">14&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-15">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-15">15&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-16">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-16">16&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-17">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-17">17&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-18">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-18">18&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-19">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-19">19&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-20">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-20">20&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-21">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-21">21&lt;/a>
&lt;/span>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-22">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-22">22&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>├── models
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── checkpoint &lt;span style="color:#75715e">#【模型微调的 checkpoint】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-100
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-200
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ ├── checkpoint-xxx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Qwen1.5-4B-Chat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-100
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-200
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── checkpoint-xxx
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── lora &lt;span style="color:#75715e">#【模型微调的 lora 文件】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Qwen1.5-4B-Chat
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── model &lt;span style="color:#75715e">#【自动下载的基座模型】&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ├── LLM-Research
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> │ └── Meta-Llama-3-8B-Instruct
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── qwen
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── Qwen1___5-4B-Chat
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;h2 id="模型测试">模型测试&lt;/h2>
&lt;p>微调完成后，你可以执行以下命令启动一个 ChatBot 进行对话测试。&lt;/p>
&lt;div class="highlight">&lt;div style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
&lt;table style="border-spacing:0;padding:0;margin:0;border:0;">&lt;tr>&lt;td style="vertical-align:top;padding:0;margin:0;border:0;">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code>&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-1">&lt;a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-1">1&lt;/a>
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>streamlit run chat.py
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>该命令执行后，会自动打开浏览器对话页面&lt;/p></description></item></channel></rss>