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 閱讀(92) 評論(0)  編輯  收藏 所屬分類: AI-QUANTIZATION


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


          網站導航:
           
          主站蜘蛛池模板: 通榆县| 炉霍县| 资阳市| 蒙阴县| 库尔勒市| 宁乡县| 五原县| 比如县| 乌兰察布市| 南汇区| 兴和县| 白山市| 曲阜市| 翁源县| 峨山| 达尔| 和田县| 泸定县| 郯城县| 浦城县| 汉沽区| 博客| 凤庆县| 惠东县| 辽中县| 兰溪市| 广平县| 綦江县| 永和县| 合川市| 东港市| 钟祥市| 尼勒克县| 龙井市| 南部县| 赤城县| 崇仁县| 平远县| 墨脱县| 江达县| 潼关县|