2024年7月8日
#
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vi /etc/apt/sources.list.d/debian.sources
添加如下内容:
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian/
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security/
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
更新所有包
安装python
sudo apt-get install python3
sudo apt-get install python3-pip
命令支持短写
sudo apt install python-is-python3
安装miniconda
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_25.3.1-1-Linux-x86_64.sh
bash Miniconda3-py310_25.3.1-1-Linux-x86_64.sh
conda config --set show_channel_urls yes
cat > ~/.condarc <<EOF
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
EOF
清除缓存
conda clean -i
conda --version
conda info # 查看渠道是否显示为清华源
sudo useradd -m paul # 创建用户并自动建立家目录
sudo passwd paul # 设置用户密码(需输入两次确认)
sudo usermod -aG wheel paul # CentOS/RHEL
[root@dev69 ~]$ groupadd docker
[root@dev69 ~]$ usermod -aG docker $USER
[root@dev69 ~]$ reboot
[paul@dev69 ~]$ docker run hello-world
AI 数据集生成和模型微调框架 Distilabel 入门指南:基本概念、安装与快速开始
蘑菇书EasyRL
李宏毅老师的《深度强化学习》是强化学习领域经典的中文视频之一。李老师幽默风趣的上课风格让晦涩难懂的强化学习理论变得轻松易懂,他会通过很多有趣的例子来讲解强化学习理论。比如老师经常会用玩 Atari 游戏的例子来讲解强化学习算法。此外,为了教程的完整性,我们整理了周博磊老师的《强化学习纲要》、李科浇老师的《世界冠军带你从零实践强化学习》以及多个强化学习的经典资料作为补充。对于想入门强化学习又想看中文讲解的人来说绝对是非常推荐的。
本教程也称为“蘑菇书”,寓意是希望此书能够为读者注入活力,让读者“吃”下这本蘑菇之后,能够饶有兴致地探索强化学习,像马里奥那样愈加强大,继而在人工智能领域觅得意外的收获。
足球基础数据
足球统计数据
足球统计数据
足球高阶数据
指数数据
足球资料库数据
Marz火星数据(体育)
基于机器学习的2022世界杯预测实战
AI 竞彩赛事 预测工具
使用trl库做微调时, 对数据集的要求是:
如果是多轮对话场景:
jsonl 文件,且需符合以下要求:
1.每行是一个独立的 JSON 对象;
2 每个对象须包含一个键名为 messages 的数组,数组不能为空;
3.messages 中每个元素必须包含 role 和 content 两个字段:
4.role 只能是 system,user 或 assisiant;
5.如果有 system 角色消息, 需在数组首位;
6.第一条非 system 消息必须是 user 角色;
7.user 和 assisiant 角色的消息应当交替、成对出现,不少于1对;
如果是指令微调场景:
jsonl 文件,且需符合以下要求:
1.每行是一个独立的 JSON 对象;
2 每个对象须包含且只能包含一个键名为 text 的键值对,值不能为空;
大模型开发出来后, 一般要经过以下几个阶段的训练:
预训练(Pre-Trained)
单纯提供文本: {"text":"..."}
训练模型由第一个文字开始, 预测后面的文字, 直到结束.
这种模型只会做完成文本的任务
监督微调(Supervised Fine Turning)
为了使模型能完成根据指令完成回答, 而不是随机生成回答
提供的文本: {"instruction":"...", "output":"..."}
高效参数微调(Parameter Efficient Fine Turning)
只调整部分参数, 具体实现方法有LoRA
参考:
大模型微调后的评估指标是衡量模型性能的关键,通常根据任务类型和具体需求选择不同的评估指标。以下是一些常见的评估指标及其适用场景:
1. 分类任务
- 准确率(Accuracy):预测正确的样本占总样本的比例。
- 精确率(Precision):预测为正类的样本中,实际为正类的比例。
- 适用场景:关注减少假阳性(False Positive)的任务。
- 召回率(Recall):实际为正类的样本中,预测为正类的比例。
- 适用场景:关注减少假阴性(False Negative)的任务。
- F1分数(F1 Score):精确率和召回率的调和平均值。
- 适用场景:类别不平衡或需要平衡精确率和召回率的任务。
- ROC-AUC:ROC曲线下的面积,衡量模型区分正负类的能力。
2. 回归任务
- 均方误差(MSE, Mean Squared Error):预测值与真实值之差的平方的平均值。
- 均方根误差(RMSE, Root Mean Squared Error):MSE的平方根。
- 平均绝对误差(MAE, Mean Absolute Error):预测值与真实值之差的绝对值的平均值。
- R²(决定系数):模型解释目标变量方差的比例。
3. 生成任务
- BLEU(Bilingual Evaluation Understudy):衡量生成文本与参考文本的n-gram重叠程度。
- ROUGE(Recall-Oriented Understudy for Gisting Evaluation):衡量生成文本与参考文本的重叠程度,侧重于召回率。
- METEOR:综合考虑精确率、召回率和词序的评估指标。
- Perplexity(困惑度):衡量模型预测概率分布的不确定性。
4. 多标签任务
- Hamming Loss:预测错误的标签比例。
- Jaccard Similarity:预测标签与真实标签的交集与并集之比。
5. 排序任务
- NDCG(Normalized Discounted Cumulative Gain):衡量排序结果的相关性。
- MAP(Mean Average Precision):平均精确率的均值。
6. 其他指标
- 训练时间:模型微调所需的时间。
- 推理速度:模型生成结果的速度。
- 资源消耗:模型运行所需的计算资源(如GPU内存、CPU使用率)。
- 鲁棒性:模型对噪声、异常值或对抗样本的抵抗能力。
7. 领域特定指标
- 医学领域:敏感性(Sensitivity)、特异性(Specificity)、AUC-ROC。
- 金融领域:收益曲线、夏普比率(Sharpe Ratio)。
- 计算机视觉:mAP(mean Average Precision)、IoU(Intersection over Union)。
8. 人类评估
- 人工评分:通过人工评估生成结果的质量(如流畅性、相关性、准确性)。
- 用户满意度:通过用户反馈评估模型的实际效果。
9. 模型对比
- 基线对比:与未微调的模型或基线模型进行性能对比。
- 消融实验:评估微调过程中不同组件(如数据、超参数)对性能的影响。
10. 综合评估
- 多指标综合:根据任务需求,结合多个指标进行综合评估。
- 任务特定指标:针对特定任务设计自定义指标。
在实际应用中,选择合适的评估指标需要结合任务目标、数据特点和业务需求,同时注意避免单一指标的局限性。
计算机毕业设计Python+Neo4j知识图谱医疗问答系统 大模型
QABasedOnMedicaKnowledgeGraph
非结构文字抽取实体与关系的大模型
SiameseUniNLU通用自然语言理解模型
数据集
各种已经训练好的模型
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
如果要从结构化的数据中提取信息,用sql即可, 即要提取的信息在select 的字段中.
如果要从非结构化的数据中, 如纯文本, 则要靠nlp, 要对文本理解后, 才能提取相应的信息.
文本结构化 with SpaCy 攻略
使用openspg自动构建医疗知识图谱
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
从实践案例介绍大模型应用经验和思考
LLaMA Factory:微调DeepSeek-R1-Distill-Qwen-7B模型实现新闻标题分类器
deepseek r1微调模型应用落地案例(医疗法律,PatientSeek)
文本转语音的模型ChatTTS体验极佳,真人般丝滑和流畅,自定义也比较灵活
医疗NLP领域 评测/比赛,数据集,论文和预训练模型资源汇总。
官网
腾讯, 需下载客户端
阿里, 需自建对话应用, 有网页版
askmanyai
360纳米搜索, 无网页版, 需自行下载app
GPTQ、GGUF、AWQ 大语言模型量化方法对比(转载)
摘要: 本博客深入探讨了群体相对策略优化(GRPO)背后的数学,GRPO是推动DeepSeek卓越推理能力的核心强化学习算法。我们将分解GRPO的工作原理、其关键组件,以及为什么它是训练高级大型语言模型(LLM)的改变者。
GRPO的基础
GRPO是什么?
群相对策略优化(GRPO)是一种强化学习(RL)算法,专门用于增强大型语言模型(LLM)的推理能力。与传统的RL方法不同,RL方法严重依赖外部评...
阅读全文
DeepSeek大模型由于采用了GRPO算法, 大幅降低了显存的需求.
【DeepSeek】复现DeepSeek R1?快来看这个Open R1项目实践指南~
!!!实战LLM强化学习——使用GRPO(DeepSeek R1出圈算法)
【DeepSeek】一文详解GRPO算法——为什么能减少大模型训练资源?
DeepSeek R1系列
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
vllm是一个可以加载大模型, 推理, 量化模型, 以http api的方式暴露服务的框架.
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
到底AI是虚的还是假的, 在企业中有没实际落地场景, 以下取实际应用场景:
生物公司
使用qwen2:7b训练细胞制备领域的数据集,目标是
1.预测细胞收获量
2.算细胞存活状态(存活/死亡)
3.预测工艺是否成功
4.可以提前预测细胞的质量是否达标,以便及时采取措施进行调整
5.细胞培养过程中出现大量细胞死亡的情况,模型可以根据实时数据和历史经验,分析可能是培养箱温度失控、培养基成分错误或受到污染等原因导致的,并提供相应的排查建议」
文体旅游
智能旅游系统:
提供目的地介绍、
旅行路线规划、
酒店预订和景
点推荐等服务。
考试改卷
基于大模型,做一个判试卷的应用,能够判断主观题,比如阅读理解,比如历史,地理,政治问答题。
判卷准确率不能低于人工判卷准确率。
即一次考试,一个班50份试卷,判断结果错误不超过5道题。判断效率高于或等于人工。
取过往同学试卷题目, 作答内容, 得分 作一波ocr出数据, 一个科目, 提取所有试卷内容, 最后就是一个科目一个模型, 提取的内容放在文本, csv, json,
基于“bert-base-chinese”这个模型, 进行微调出专用模型即可,
让大模型成为专业的判卷老师
考试
用扣子打一个智能体,实现不同学员对掌握的知识进行测试,根据测试结果进行打分和二次出题测试
0. 配置环境变量
HF_ENDPOINT=https://hf-mirror.com
HF_HOME=/root/autodl-tmp/paul/tools/huggingface
1. 本机安装python 3.10, 并设置软件源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple
2. 安装miniconda
3. 新建一个环境, 并激活
conda create -n quantization python=3.12
2. 本机安装pytorch2.5.1+cuda12.4
pip3 install torch torchvision torchaudio
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
3. clone llamafactory源码
git clone https://github.com/hiyouga/LLaMA-Factory
4. llamafactory本地安装依赖
pip install -e .["vllm","gptq"]
5. 启动webui
6. 在页面中填入相关参数进行操作
VLLM量化推理
安装此工具前需安装两个包:
sudo apt-get install cmake
sudo apt-get install pkgconfig
配置huggingface镜像地址:
export HF_ENDPOINT=https://hf-mirror.com
下载代码库, 并安装python依赖
git clone https://github.com/ModelTC/llmc.git
cd llmc/
pip install -r requirements.txt
找到量化方法的配置文件, 并作修改
base:
seed: &seed 42
model:
type: Llama
path: /home/paul/.cache/huggingface/models/models--unsloth--llama-3-8b-Instruct-lawdata
torch_dtype: auto
quant:
method: RTN
weight:
bit: 8
symmetric: True
granularity: per_group
group_size: 128
need_pack: True
eval:
eval_pos: [fake_quant]
name: wikitext2
download: True
path: /home/paul/paulwong/work/workspaces/llmc/dataset
bs: 1
seq_len: 2048
inference_per_block: False
save:
save_vllm: True
save_path: /home/paul/.cache/huggingface/models/models--unsloth--llama-3-8b-Instruct-lawdata-quantization
找到run_llmc.sh, 并作修改
#!/bin/bash
# export CUDA_VISIBLE_DEVICES=0,1
llmc=/home/paul/paulwong/work/workspaces/llmc
export PYTHONPATH=$llmc:$PYTHONPATH
# task_name=awq_w_only
# config=${llmc}/configs/quantization/methods/Awq/awq_w_only.yml
task_name=rtn_for_vllm
config=${llmc}/configs/quantization/backend/vllm/rtn_w8a16.yml
nnodes=1
nproc_per_node=1
find_unused_port() {
while true; do
port=$(shuf -i 10000-60000 -n 1)
if ! ss -tuln | grep -q ":$port "; then
echo "$port"
return 0
fi
done
}
UNUSED_PORT=$(find_unused_port)
MASTER_ADDR=127.0.0.1
MASTER_PORT=$UNUSED_PORT
task_id=$UNUSED_PORT
nohup \
torchrun \
--nnodes $nnodes \
--nproc_per_node $nproc_per_node \
--rdzv_id $task_id \
--rdzv_backend c10d \
--rdzv_endpoint $MASTER_ADDR:$MASTER_PORT \
${llmc}/llmc/__main__.py --config $config --task_id $task_id \
> ${task_name}.log 2>&1 &
sleep 2
ps aux | grep '__main__.py' | grep $task_id | awk '{print $2}' > ${task_name}.pid
# You can kill this program by
# xargs kill -9 < xxx.pid
# xxx.pid is ${task_name}.pid file
执行量化操作
Fine-tune Llama 3.1 Ultra-Efficiently with Unsloth
A beginners guide to fine tuning LLM using LoRA
【Day 23】調教你的 AI 寵物:用微調讓 LLM 乖乖聽話
设置端口转发
在 Windows 上,以管理员身份打开 PowerShell,
netsh interface portproxy add v4tov4 listenport=7860 listenaddress=0.0.0.0 connectport=7860 connectaddress=123.45.67.89
在 PowerShell 中使用 netsh interface portproxy 命令设置的端口转发规则是持久性的。这些规则会在系统重启后继续生效,因为它们被存储在 Windows 的注册表中。
删除端口转发规则
如果想删除之前设置的端口转发规则,可以使用以下命令:
netsh interface portproxy delete v4tov4 listenport=7860 listenaddress=0.0.0.0
这里的 listenport 和 listenaddress 应与之前设置时的值一致。
查看当前的端口转发规则
要查看当前系统中所有的端口转发规则,可以运行:
netsh interface portproxy show all
1. N卡驱动和toolkit安装
pip3 install --no-build-isolation axolotl[flash-attn,deepspeed]
将内网, 如家庭中的使用wifi建立的网站, 发布到外网, 而无需使用服务器.
reference:
先下载cuda版本的pytorch的整个打包文件:
pip install torch-2.5.1+cu124-cp312-cp312-linux_x86_64.whl
验证:
#python
import torch
torch.__version__
1.首先给win11的ssh开一个新端口.(修改C:\ProgramData\ssh\sshd_config即可)
2.win11设置防火墙,开放1中添加的端口.
3.win11进入wsl2,输入ifconfig,查看ip地址(输出信息第二行 inet后面那一串数字).
4.在win11的cmd中输入以下命令:
netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=<步骤1中开放的端口> connectaddress=<步骤3中得到的ip地址> connectport=22
5. ssh连接步骤1中开放的端口就可以连接上wsl2(注意事项:(1)连接时,win11上需要有一个wsl窗口,不然连不上,(2)ssh连接时的用户名写wsl2中的用户名,密码写wsl2中的密码,ip地址写win11的ip地址)
https://www.zhihu.com/question/618935377
# /etc/hosts
140.82.112.4 www.github.com
linux每次升级后都会留下多余的内核, 一键删除的方法(Centos):@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
dnf remove $(dnf repoquery --installonly --latest-limit=-2)
数据分析:从一堆已知的数据中进行分类,总结得出统计数据,如最大 值,最小值,平均值,总和等。
只能对已知数据进行操作,无法预测出新的数据的特征,于是就有了机器学习。
机器学习:给出一堆已知的,有特征栏位的和结果栏位的数据,选定一个算法,如线性回归,逻辑回归等,其实就是一条公式,进行学习,其实就是运行一堆函数,比较结果,得出规律,也就是确定了公式中参数的值。当输入新的数据时,就能预测出所需的结果,其实就是把输入数据代入公式,算出结果。
机器学习只能做比较简单的任务,如预测下个月的销售数据,判断文字内容是正面还是反面(分类),对于复杂的任务,如对话,其实就是针对输入文字预测靠谱的输出文字(回答),于是就有了深度学习。
深度学习:给出一堆数据,只需两个本栏位,如问题,答案等,选定一个算法,其实就是神经网络的类型,如卷积神经网络(CNN),循环神经网络(RNN),TRANSFORMER神经网络等,进行学习,其实就是运行一堆函数,比较结果,得出规律,也就是确定了公式中参数的值。
操作系统为centos 9.
先安装驱动程序
#切换成文字界面
sudo systemctl set-default multi-user.target
sudo reboot
sh NVIDIA-Linux-x86_64-550.107.02.run
#切换成图形界面
sudo systemctl set-default graphical.target
sudo reboot
安装docker:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
sed -i 's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo nvidia-ctk runtime configure --runtime=docker
改镜像地址:
[paul@paul-pc ~]$ cat /etc/docker/daemon.json
{
"registry-mirrors": [
"http://xxx.xxx.xxx"
],
"runtimes": {
"nvidia": {
"args": [],
"path": "nvidia-container-runtime"
}
}
}
安装container-took-kit:
sh cuda_12.6.0_560.28.03_linux.run
验证:
sudo docker run --rm -it --gpus all ubuntu nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.107.02 Driver Version: 550.107.02 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 2080 Ti Off | 00000000:01:00.0 On | N/A |
| 62% 36C P8 4W / 260W | 256MiB / 22528MiB | 1% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
| 1 NVIDIA GeForce RTX 2080 Ti Off | 00000000:02:00.0 Off | N/A |
| 64% 35C P8 5W / 260W | 9MiB / 22528MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 2657 G /usr/libexec/Xorg 99MiB |
| 0 N/A N/A 2735 G /usr/bin/gnome-shell 38MiB |
| 0 N/A N/A 3502 G /usr/lib64/firefox/firefox 111MiB |
| 1 N/A N/A 2657 G /usr/libexec/Xorg 4MiB |
+-----------------------------------------------------------------------------------------+
参考地址:
python服务器脚本,生成html,无需写js,css,适合AI项目
生成文字的代码:
st.text(
'Fixed width text')
st.markdown(
'_Markdown_')
# see #*
st.caption(
'Balloons. Hundreds of them
')
st.latex(r
''' e^{i\pi} + 1 = 0 ''')
st.write(
'Most objects')
# df, err, func, keras!
st.write([
'st',
'is <', 3])
# see *
st.title(
'My title')
st.header(
'My header')
st.subheader(
'My sub')
st.code(
'for i in range(8): foo()')
# * optional kwarg unsafe_allow_html = True
生成form控件:
st.button('Hit me')
st.data_editor('Edit data', data)
st.checkbox('Check me out')
st.radio('Pick one:', ['nose','ear'])
st.selectbox('Select', [1,2,3])
st.multiselect('Multiselect', [1,2,3])
st.slider('Slide me', min_value=0, max_value=10)
st.select_slider('Slide to select', options=[1,'2'])
st.text_input('Enter some text')
st.number_input('Enter a number')
st.text_area('Area for textual entry')
st.date_input('Date input')
st.time_input('Time entry')
st.file_uploader('File uploader')
st.download_button('On the dl', data)
st.camera_input("一二三,茄子!")
st.color_picker('Pick a color')
用表格显示数据:
st.dataframe(my_dataframe)
st.table(data.iloc[0:10])
st.json({'foo':'bar','fu':'ba'})
st.metric(label="Temp", value="273 K", delta="1.2 K")
显示加载进度条与状态:
# Show a spinner during a process
>>> with st.spinner(text='In progress'):
>>> time.sleep(3)
>>> st.success('Done')
# Show and update progress bar
>>> bar = st.progress(50)
>>> time.sleep(3)
>>> bar.progress(100)
st.balloons()
st.snow()
st.toast('Mr Stay-Puft')
st.error('Error message')
st.warning('Warning message')
st.info('Info message')
st.success('Success message')
st.exception(e)
这几天要PUSH代码到GITHUB,发现之前用的密码方式被取消了,需改成SSH KEY的方式。
1.生成SSH-KEY
ssh-keygen
#会产生 ~/.ssh/id_rsa 和 ~/.ssh/id_rsa_pub 文件
#如果是从别的地方拷贝过来的id_rsa,需chmod 400 ~/.ssh/id_rsa更改属性
2.在github上新建仓库
https://github.com/paulwong888/python-ai
3.导入公钥到github
打开你的SSH公钥文件,通常位于~/.ssh/id_rsa.pub。复制公钥内容,然后登录到你的GitHub账户,进入Settings > SSH and GPG keys,点击"New SSH key"按钮,粘贴你的公钥,然后点击"Add SSH key"。
4.克隆仓库
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git clone git@github.com:paulwong888/python-ai
5.导入project到eclipse
上步克隆时已经在本地新建了一个本地仓库,Import->Git->Project from Git->Existing local repository,选择python-ai/.git文件夹
之后的操作和用密码的方式是一样的。
上篇已经合并出了训练好的大模型,现在要搭建起一套CHATBOT,使得这套大模型能有一个WEBUI用起来。
1.设置环境变量,ollama的模型保存路径,/etc/profile
export OLLAMA_MODELS=/root/autodl-tmp/models/ollama
2.克隆ollama代码
curl -fsSL https://ollama.com/install.sh | sh
3.启动ollama
4.建立ollama镜像的配置文件,Modelfile
# set the base model
FROM /root/.ollama/llamafactory-export/saves/llama3-8b/lora/docker-commnad-nlp/export
# set custom parameter values
PARAMETER temperature 1
PARAMETER num_keep 24
PARAMETER stop <|start_header_id|>
PARAMETER stop <|end_header_id|>
PARAMETER stop <|eot_id|>
PARAMETER stop <|reserved_special_token
# set the model template
TEMPLATE """
{{ if .System }}<|start_header_id|>system<|end_header_id|>
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
{{ .Response }}<|eot_id|>
"""
# set the system message
SYSTEM You are llama3 from Meta, customized and hosted @ Paul Wong (http://paulwong88.tpddns.cn).
# set Chinese lora support
#ADAPTER /root/.ollama/models/lora/ggml-adapter-model.bin
建立镜像命令,create-ollama-image-docker-command-nlp.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
ollama create llama3-docker-commnad-nlp:paul -f Modelfile
5.运行大模型
llama3-docker-commnad-nlp:paul
对于象META的开源大模型,如llama3,由于都是用通用数据进行预训练,对想使用其模型的公司来说,可能会不适用,因为这大模型对公司的数据不熟悉,因此引入微调(Fine-Tunning)。
通过喂给大模型大量数据,1万条起步,使得大模型也能对公司的数据熟悉,进而用于各种对话场景。
1.克隆并安装LLAMA FACTORY库,install-llamafactory.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/../
pwd
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics,bitsandbytes,modelscope]"
2.设置环境变量
export USE_MODELSCOPE_HUB=1 #使用modelscop模型库,非huggingface的
export CUDA_VISIBLE_DEVICES=0 #设置使用GPU
export HF_ENDPOINT=https://hf-mirror.com #设置huggingface的替代地址
export MODELSCOPE_CACHE=/root/autodl-tmp/models/modelscope #设置modelscope中的大模型保存路径
export LLAMAFACTORY_HOME=/root/autodl-tmp/LLaMA-Factory
3.准备数据
#在data/dataset_info.json中加入此数据
"docker_command_NL": {
"hf_hub_url": "MattCoddity/dockerNLcommands"
},
在data目录中加入训练数据,MattCoddity/dockerNLcommands.json
数据格式为:
[
{
"input": "Give me a list of containers that have the Ubuntu image as their ancestor.",
"instruction": "translate this sentence in docker command",
"output": "docker ps --filter 'ancestor=ubuntu'"
},

] 4.训练大模型
训练的参数文件:llama3_lora_sft_docker_command.yaml
### model
#md model id
model_name_or_path: LLM-Research/Meta-Llama-3-8B-Instruct
#huggingface model id
#model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct
### method
stage: sft
do_train: true
finetuning_type: lora
lora_target: all
### dataset
dataset: docker_command_NL
template: llama3
cutoff_len: 1024
max_samples: 1000
overwrite_cache: true
preprocessing_num_workers: 16
### output
output_dir: /root/autodl-tmp/my-test/saves/llama3-8b/lora/sft/docker-commnad-nlp/sft
logging_steps: 10
save_steps: 500
plot_loss: true
overwrite_output_dir: true
### train
per_device_train_batch_size: 4
gradient_accumulation_steps: 8
learning_rate: 1.0e-4
num_train_epochs: 3.0
lr_scheduler_type: cosine
warmup_ratio: 0.1
bf16: true
ddp_timeout: 180000000
### eval
val_size: 0.1
per_device_eval_batch_size: 1
eval_strategy: steps
eval_steps: 500
训练命令:lora-train-docker-command.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
cd $LLAMAFACTORY_HOME
pwd
llamafactory-cli train $BIN_PATH/conf/llama3_lora_sft_docker_command.yaml
执行此命令即可开始训练大模型。
5.合并大模型
合并用的参数文件,llama3_lora_export_docker_command.yaml
### model
#md model id
model_name_or_path: LLM-Research/Meta-Llama-3-8B-Instruct
#huggingface model id
#model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct
adapter_name_or_path: /root/autodl-tmp/my-test/saves/llama3-8b/lora/docker-commnad-nlp/sft
template: llama3
export_dir: /root/autodl-tmp/my-test/saves/llama3-8b/lora/docker-commnad-nlp/export
finetuning_type: lora
export_size: 2
export_device: gpu
export_legacy_format: False
合并命令,lora-export-docker-command.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
llamafactory-cli export conf/llama3_lora_export_docker_command.yaml