摘要: 本博客深入探討了群體相對(duì)策略?xún)?yōu)化(GRPO)背后的數(shù)學(xué),GRPO是推動(dòng)DeepSeek卓越推理能力的核心強(qiáng)化學(xué)習(xí)算法。我們將分解GRPO的工作原理、其關(guān)鍵組件,以及為什么它是訓(xùn)練高級(jí)大型語(yǔ)言模型(LLM)的改變者。
GRPO的基礎(chǔ)
GRPO是什么?
群相對(duì)策略?xún)?yōu)化(GRPO)是一種強(qiáng)化學(xué)習(xí)(RL)算法,專(zhuān)門(mén)用于增強(qiáng)大型語(yǔ)言模型(LLM)的推理能力。與傳統(tǒng)的RL方法不同,RL方法嚴(yán)重依賴(lài)外部評(píng)...
閱讀全文
DeepSeek大模型由于采用了GRPO算法, 大幅降低了顯存的需求.
【DeepSeek】復(fù)現(xiàn)DeepSeek R1?快來(lái)看這個(gè)Open R1項(xiàng)目實(shí)踐指南~
!!!實(shí)戰(zhàn)LLM強(qiáng)化學(xué)習(xí)——使用GRPO(DeepSeek R1出圈算法)
【DeepSeek】一文詳解GRPO算法——為什么能減少大模型訓(xùn)練資源?
DeepSeek R1系列
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
vllm是一個(gè)可以加載大模型, 推理, 量化模型, 以http api的方式暴露服務(wù)的框架.
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
@import url(http://www.aygfsteel.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
到底AI是虛的還是假的, 在企業(yè)中有沒(méi)實(shí)際落地場(chǎng)景, 以下取實(shí)際應(yīng)用場(chǎng)景:
生物公司
使用qwen2:7b訓(xùn)練細(xì)胞制備領(lǐng)域的數(shù)據(jù)集,目標(biāo)是
1.預(yù)測(cè)細(xì)胞收獲量
2.算細(xì)胞存活狀態(tài)(存活/死亡)
3.預(yù)測(cè)工藝是否成功
4.可以提前預(yù)測(cè)細(xì)胞的質(zhì)量是否達(dá)標(biāo),以便及時(shí)采取措施進(jìn)行調(diào)整
5.細(xì)胞培養(yǎng)過(guò)程中出現(xiàn)大量細(xì)胞死亡的情況,模型可以根據(jù)實(shí)時(shí)數(shù)據(jù)和歷史經(jīng)驗(yàn),分析可能是培養(yǎng)箱溫度失控、培養(yǎng)基成分錯(cuò)誤或受到污染等原因?qū)е碌模⑻峁┫鄳?yīng)的排查建議」
文體旅游
智能旅游系統(tǒng):
提供目的地介紹、
旅行路線規(guī)劃、
酒店預(yù)訂和景
點(diǎn)推薦等服務(wù)。
考試改卷
基于大模型,做一個(gè)判試卷的應(yīng)用,能夠判斷主觀題,比如閱讀理解,比如歷史,地理,政治問(wèn)答題。
判卷準(zhǔn)確率不能低于人工判卷準(zhǔn)確率。
即一次考試,一個(gè)班50份試卷,判斷結(jié)果錯(cuò)誤不超過(guò)5道題。判斷效率高于或等于人工。
取過(guò)往同學(xué)試卷題目, 作答內(nèi)容, 得分 作一波ocr出數(shù)據(jù), 一個(gè)科目, 提取所有試卷內(nèi)容, 最后就是一個(gè)科目一個(gè)模型, 提取的內(nèi)容放在文本, csv, json,
基于“bert-base-chinese”這個(gè)模型, 進(jìn)行微調(diào)出專(zhuān)用模型即可,
讓大模型成為專(zhuān)業(yè)的判卷老師
考試
用扣子打一個(gè)智能體,實(shí)現(xiàn)不同學(xué)員對(duì)掌握的知識(shí)進(jìn)行測(cè)試,根據(jù)測(cè)試結(jié)果進(jìn)行打分和二次出題測(cè)試
0. 配置環(huán)境變量
HF_ENDPOINT=https://hf-mirror.com
HF_HOME=/root/autodl-tmp/paul/tools/huggingface
1. 本機(jī)安裝python 3.10, 并設(shè)置軟件源
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. 新建一個(gè)環(huán)境, 并激活
conda create -n quantization python=3.12
2. 本機(jī)安裝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本地安裝依賴(lài)
pip install -e .["vllm","gptq"]
5. 啟動(dòng)webui
6. 在頁(yè)面中填入相關(guān)參數(shù)進(jìn)行操作
VLLM量化推理
安裝此工具前需安裝兩個(gè)包:
sudo apt-get install cmake
sudo apt-get install pkgconfig
配置huggingface鏡像地址:
export HF_ENDPOINT=https://hf-mirror.com
下載代碼庫(kù), 并安裝python依賴(lài)
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
執(zhí)行量化操作
Fine-tune Llama 3.1 Ultra-Efficiently with Unsloth
A beginners guide to fine tuning LLM using LoRA
【Day 23】調(diào)教你的 AI 寵物:用微調(diào)讓 LLM 乖乖聽(tīng)話