1.測試顯卡 ``` python mp_eval_pipeline.py --stage diagnose ``` 2.測試GPU運行 ``` pip install -U nvidia-ml-py3 python - <<'PY' import time, pynvml as nv nv.nvmlInit() h = nv.nvmlDeviceGetHandleByIndex(0) name = nv.nvmlDeviceGetName(h).decode() while True: util = nv.nvmlDeviceGetUtilizationRates(h) mem = nv.nvmlDeviceGetMemoryInfo(h) print(f"{name} | GPU {util.gpu:3d}% | MEM {mem.used/1e9:5.2f}/{mem.total/1e9:5.2f} GB") time.sleep(2.0) PY ``` 3.跑部分測試集 ``` python mp_eval_pipeline.py \ --model meta-llama/Llama-2-7b-hf \ --stage micro \ --candidates "awq_w4a16,gptq_w4a16" \ --awq_path TheBloke/Llama-2-7B-AWQ \ --gptq_path TheBloke/Llama-2-7B-GPTQ \ --ds_name wikitext --ds_config wikitext-2-raw-v1 --ds_split test \ --ctx_len 2048 --stride 1024 \ --offload_folder ./offload_cache \ --outdir runs_all ``` 4.All全測 ``` python mp_eval_pipeline.py \ --model meta-llama/Llama-2-7b-hf \ --stage mid \ --candidates "all" \ --awq_w4a16_path "TheBloke/Llama-2-7B-AWQ" \ --gptq_w4a16_path "TheBloke/Llama-2-7B-GPTQ" \ --ds_name wikitext \ --ds_config wikitext-2-raw-v1 \ --ds_split validation \ --ctx_len 2048 \ --stride 1024 \ --outdir runs_all ``` 5.產生OmniQuant ``` # 1. 複製 OmniQuant 專案 git clone https://github.com/OpenGVLab/OmniQuant.git cd OmniQuant pip install -r requirements.txt pip install sacrebleu pip install omegaconf pip install pycountry pip install rouge_score pip install termcolor pip install protobuf pip uninstall transformers pip install transformers==4.31.0 mkdir -p ./act_scales/ python generate_act_scale_shift.py \ --model meta-llama/Llama-2-7b-hf \ --calib_dataset wikitext2 \ --num-samples 128 \ --scales-output-path ./act_scales/Llama-2-7b-hf.pt # 2. 執行校準(這會花費一些時間,例如 1.6 小時 [cite: 7306-7308]) # 這會使用 FP16 的 Llama-2-7b 和校準數據, # 來「學習」W4A4 的最佳量化參數 python main.py \ --model meta-llama/Llama-2-7b-hf \ --wbits 4 \ --abits 4 \ --lwc --let \ --epochs 20 \ --output_dir ./calibrated_models/llama-2-7b-w4a4 # (此步驟會產生一個新的、校準過的 W4A4 模型在 ./calibrated_models/llama-2-7b-w4a4) ``` ``` python main.py \ --model meta-llama/Llama-2-7b-hf \ --epochs 0 \ --wbits 4 --abits 4 --lwc --let \ --act-scales ./act_scales/Llama-2-7b-hf.pt \ --act-shifts ./act_shifts/Llama-2-7b-hf.pt \ --resume ./calibrated_models/Llama-2-7b-w4a4.pth \ --save_dir ./omni-l2-7b-w4a4-fake \ --eval_ppl | tee logs_w4a4_ppl.txt ``` 6.逐層替換測試(AWQ) ``` # A) 單層替換 (以 Llama-2-7B 為例;會依序跑 L1~L32 共 N 次) python mp_eval_pipeline.py \ --stage lasq \ --model meta-llama/Llama-2-7b-hf \ --lasq_awq_path TheBloke/Llama-2-7B-AWQ \ --lasq_targets single \ --ds_name wikitext --ds_config wikitext-2-raw-v1 --ds_split test \ --ctx_len 2048 --stride 1024 \ --outdir runs_lasq_l2_7b # B) 半數替換(前 50% 與後 50%) python mp_eval_pipeline.py \ --stage lasq \ --model meta-llama/Llama-2-7b-hf \ --lasq_awq_path TheBloke/Llama-2-7B-AWQ \ --lasq_targets half \ --ds_name wikitext --ds_config wikitext-2-raw-v1 --ds_split test \ --ctx_len 2048 --stride 1024 \ --outdir runs_lasq_l2_7b_half ``` 7.逐層替換測試(W4A4) ``` python mp_eval_pipeline_Omni.py --stage lasq \ --model meta-llama/Llama-2-7b-hf \ --lasq_omni_w4a4_path /home/ess/M11307409/OmniQuant/omni-l2-7b-w4a4 \ --lasq_targets "single,half" \ --omni_smoothing sqrt_clip \ --ds_name wikitext --ds_config wikitext-2-raw-v1 --ds_split test \ --ctx_len 2048 --stride 1024 \ --outdir runs_lasq_omni_w4a4 ```