ollama本地部署qwen微调大模型 | 新手炼丹记录(3)

系列回顾

        llama factory LoRA微调qwen大模型 | 新手炼丹记录(1)-CSDN博客

        大模型使用llama.cpp转换gguf格式并量化 | 新手炼丹记录(2)-CSDN博客

        ollama本地部署qwen微调大模型 | 新手炼丹记录(3)-CSDN博客

        上面两期我们详细讲述了使用基于AutoDL算力平台使用llama factory对qwen大模型进行微调,然后我们又使用llama.cpp对模型进行了格式转换以及量化,进一步缩小了模型的大小。上期结尾我们将量化完的gguf格式的模型文件通过FileZilla下载到了本地。本期我们将详细介绍如何使用Ollama部署gguf格式大模型。

一、Ollama下载与安装

在Windows上安装Ollama需要通过下载安装包并进行手动安装。

1、下载安装包:访问Ollama官网,下载适用于Windows的安装包。
2、安装Ollama:双击下载的安装包,按照提示完成安装。默认安装路径为C:\Users\{你的电脑账户名}\AppData\Local\Programs\Ollama。

3、验证下载:Win+R打开windows终端,输入以下内容回车,可以查看ollama版本。

ollama --version

出现ollama版本证明下载成功。

修改Ollama模型下载路径(可选)

        由于Ollama下载模型默认是在C盘,但是我们知道我们的模型动辄十几GB甚至上百GB如果全部下载C盘电脑早就不能正常使用了,因此我们需要修改一下Ollama模型的下载地址。

windows搜索环境变量,找到并打开”编辑系统环境变量“:

按照如下方式操作,点击确认后就可以在”系统变量“中看到我们保存的”OLLAMA_MODELS“,这样我们下载模型时就会下到这个路径:

OLLAMA_MODELS <你想要保存的路径>

二、Ollama常用基础命令

#查看所有模型
ollama list

#运行一个模型
ollama run <模型名>

#删除一个模型
ollama rm <模型名>

#显示模型详细信息
ollama show <模型名>

三、Ollama部署gguf格式模型

        下载完Ollama以及了解了Ollama的基础用法以后,我们就可以开始部署上期我们从服务下载的gguf格式的模型了。

这里我将上期的模型下载到了Ollama存储大模型的路径(D:\OllamaLLM\models)。打开文件管理器,在该目录下新建一个文件并命名位Modelfile:

这个Modelfile就是我们生成模型的规则,如模型文件的路径、系统设置等。这个Modelfile是需要我们来编写的。具体详细的写法我们可以参考这篇博客的内容:Ollama Modelfile官方文档-CSDN博客。但是这里一般我们可以直接参考已经本地部署的模型的Modelfile写法。

!注意:Modelfile的编写是很重要的,如果错误的编写,如将Ollama模型的modelfile作为qwen模型的modelfile可能会导致模型输出胡言乱语

这里我以先前部署的qwen2:0.5b的大模型的Modelfile作为例子。命令行输入:

ollama show qwen2:0.5b --modelfile

从官方给出的示例来看,我们的modelfile大致可以分为三部分,模型路径、模型模板以及停止词。当然如果你不会写不要紧,由于同一类的大模型配置基本也相同,所以我们可以基本可以复制同一系列模型的modelfile来使用。但是需要我们切换为我们自己的模型路径。

对于qwen1.5:7b的模型,这里我使用了13b的模型modelfile模板并且是能够正常运行的。 我们右键Modelfile以”文本文件“的方式打开编辑,输入以下内容。保存后关闭:

FROM <你的模型路径>

TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>{{ end }}<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
"""

PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"

之后打开终端,进入该文件目录下:

#cd <你保存微调模型的路径>
cd D:\OllamaLLM\models

输出创建模型的指令,Ollama将根据你的Modelfile自动生成:

#ollama create <模型名> -f Modelfile
ollama create qwen7b_lora_q4 -f Modelfile

创建成功后,我们可以使用“ollama list”来查看部署好的模型:

ollama list

下面让我们使用”ollama run“来运行试试看效果,同样我们问一个数据集中的问题:

ollama run qwen7b_lora_q4

可以看到效果还可以,那么我们自己微调的模型就已经部署好了

四、结束

        在这三期的实践中,我们通过llama factory微调了qwen大模型,随后又使用llama.cpp对模型进行了格式转换以及量化处理,用FileZilla将其传输到我们本地后使用Ollama对其进行了部署。基本上这就是一整套模型微调部署的全流程。但是我们还可以对模型做许多优化,比如可以使用QLoRA的微调方法、再做DPO训练等等。基本的流程我们已经走通了。如果大家还有什么疑惑,可以再评论区留言。或者哪里写的有错误不好的,也可以留言。

### IEEE Transactions on Geoscience and Remote Sensing (TGRS) EndNote Citation Style Setup For setting up the citation style of IEEE Transactions on Geoscience and Remote Sensing within EndNote, one must ensure that the specific ENS file corresponding to this journal is correctly placed into the styles folder used by EndNote software[^1]. After placing the downloaded `IEEE TRANSACTIONS ON GEOSCIENCE AND REMOTE SENSING.ens` file in the appropriate directory (`Styles`), restarting EndNote will make the new style available for selection. The formatting specifics such as alignment and indentation—often referred to as hanging indent—are predefined within the `.ens` file itself when it comes from a reputable source like an official journal page or EndNote&#39;s own library of styles. To apply this style: - Open EndNote. - Navigate through the menu options to select preferences related to output styles. - Choose "Select Another Style..." option if necessary. - Browse and locate the recently added IEEE Transactions on Geoscience and Remote Sensing style. - Select it to set as default or use whenever required. Once applied, all citations managed under this profile should conform automatically to the guidelines specified by IEEE Transactions on Geoscience and Remote Sensing, including proper text justification and spacing rules defined within the style settings. ```python # Example Python code demonstrating how not to handle EndNote styles programmatically; # actual configuration happens via GUI interaction with EndNote application. def configure_endnote_style(style_name="IEEE TRANSACTIONS ON GEOSCIENCE AND REMOTE SENSING"): print(f"Configuring {style_name}...") ```
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值