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