paulwong

          量化大模型工具

          VLLM量化推理
          https://llmc-zhcn.readthedocs.io/en/latest/backend/vllm.html#id1

          安裝此工具前需安裝兩個包:
          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

          執行量化操作
          bash scripts/run_llmc.sh




          posted on 2025-01-15 18:00 paulwong 閱讀(91) 評論(0)  編輯  收藏 所屬分類: AI-QUANTIZATION


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 忻城县| 蓬溪县| 海淀区| 威信县| 卓尼县| 漯河市| 东台市| 寿宁县| 宜川县| 仙居县| 江川县| 绍兴市| 青神县| 祁连县| 曲阳县| 东乌珠穆沁旗| 兴城市| 兰考县| 遂川县| 益阳市| 高唐县| 岢岚县| 平遥县| 柞水县| 宁南县| 成都市| 潜山县| 龙胜| 衡东县| 盘锦市| 玉门市| 滕州市| 正蓝旗| 金阳县| 尚志市| 徐州市| 六盘水市| 蛟河市| 福鼎市| 江永县| 红河县|