Which quantization method is efficient & effective? ๐ง
๋ ์ด ์ง๋๋ฉด ์ง๋ ์๋ก ์ ์ ์ฌ์ด์ฆ๊ฐ ์ปค์ ธ๊ฐ๋ LLM์ ํ๋์์ ์ด๋ค์ ์์ฝ๊ฒ ํจ์จ์ ๋ฐ ํจ๊ณผ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๋ ๋ฐฉ๋ฒ์๋ ๋ฌด์์ด ์์๊น? ์์ฆ์๋ ๋ค๋ฅธ method๋ค๋ณด๋ค๋ quantization, ์ฆ ์์ํ๋ฅผ ์ฃผ๋ก ์ฌ์ฉํ๋ ์ถ์ธ์ด๋ค. ์ด quantization์ ํตํด ์ฌ๋๋ค์ ๊ณ ์ฉ๋ RAM์ ๊ฐ์ง๋ GPU์์๋ ์ฌ์ฉํ๊ธฐ๊ฐ ํ๋ค๋ LLM์ ํจ์ฌ ํจ์จ์ ์ผ๋ก ์ฌ์ฉํ ์ ์๊ฒ ๋์๋ค! ๐ค
์ต์ํ์ ์ฑ๋ฅ ๊ฐ์๋ก ์ต์ ์ ํจ์จ์ฑ์ ๋ณด์ฌ์ฃผ๋ quantization์ ์ํด HuuggingFace์์๋ 2๊ฐ์ง quantization method๋ฅผ ์ ๊ณตํ๊ณ ์๋ค. ๋ฐ๋ก BitsAndBytes์ GPTQ์ด๋ค. ์ด๋ฅผ ํ ๋๋ก ๋ quantization method๊ฐ ์ด๋ค ์ฅ๋จ์ ์ ๊ฐ์ง๋์ง ์ง์ ๋น๊ต ๋ฐ ๋ถ์์ ์งํํ HuggingFace์ ๋ธ๋ก๊ทธ ํฌ์คํธ๋ฅผ ๋ณด๊ณ , ์ด ๋ธ๋ก๊ทธ ํฌ์คํธ์ ๋ง์ง๋ง ๋ถ๋ถ์ ์ ์๋์๋ quantization method์ ํจ์จ์ฑ์ ์ง์ ์คํ์ ํตํด ์ ์ฆํ๋ ํ๋ก์ ํธ๋ฅผ ์งํํ์๋ค! ํ๋ก์ ํธ์ Github Repository๋ ๋ณธ ํฌ์คํธ์ ๋ง์ง๋ง ๋ถ๋ถ์ ์๋ ์ถ์ฒ์์ ํ์ธํ์๊ธธ ๋ฐ๋ผ๊ฒ ์ต๋๋ค.
ํ๋ก์ ํธ๋ฅผ ์๊ฐํ๊ธฐ์ ์์ ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์๊ฐํ ๊ฐ๋ ๋ค์ ๋ํด ์ ๊น ์ง๊ณ ๋์ด๊ฐ ๋ณด๋๋ก ํ๊ฒ ๋ค!
Before start..
๊ฐ quantization method์ ๋ํด ์์ธํ ๋์ฑ ์์ธํ๊ฒ ์์๋ณด๊ณ ์ถ๋ค๋ฉด ์๋์ Resource๋ฅผ ์ฐธ๊ณ ํด ์ฃผ์๊ธธ ๋ฐ๋ผ๊ฒ ์ต๋๋ค!
Resources
- GPTQ blogpost: GPTQ quantization method์ ๋ํ ์ ์ฒด์ ์ธ ๊ฐ์๋ฅผ ์๋ ค์ฃผ๊ณ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ํด ์๋ ค์ค.
- bitsandbytes 4-bit quantization blogpost: 4-bit ์์์์ ํจ์จ์ ์ธ fine-tuning ๋ฐฉ์์ธ QLoRA์ ๋ํด์ ์ค๋ช ํจ.
- bitsandbytes 8-bit quantization blogpost: bitsandbytes๋ฅผ ํ์ฉํ์ ๋ 8-bit quantization์ด ์ด๋ป๊ฒ ๋๋์ง ์ค๋ช ํจ.
- Basic usage Google Colab notebook for GPTQ: GPTQ method๋ฅผ ํ์ฉํ์ฌ ์ด๋ป๊ฒ Transformers ๋ชจ๋ธ์ ์์ํํ๊ณ , ์ถ๋ก ํ๋์ง ๋ฑ์ ์๋ ค์ค. ๊ทธ๋ฆฌ๊ณ quantized model์ ํ์ฉํ์ฌ ์ด๋ป๊ฒ fine-tuning ํ๋์ง ์๋ ค์ค.
- Basic usage Google Colab notebook for bitsandbytes: 4-bit model์ ํ์ฉํด์ ์ด๋ป๊ฒ ์ถ๋ก ํ ์ ์๋์ง ๋ณด์ฌ์ค. ๊ทธ๋ฆฌ๊ณ GPT-neo-X๋ฅผ Google Colab Free GPU์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์๋ ค์ค.
- Merve's blogpost on quantization: ์์ํ์ ์์ํ ๋ฐฉ๋ฒ์ ๋ํด ์์ธํ๊ฒ ์๋ ค์ค.
Pros & Cons Analysis(bitsandbytes, GPTQ) ๐
HuggingFace์ ๋ธ๋ก๊ทธ ํฌ์คํธ์์๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ quantization method์ ์ฅ๋จ์ ์ ์๊ฐํ๋ค.
The benefits & rooms of improvements of bitsandbytes
Benefits
- easy ๐: bitsandbytes๋ ๋ชจ๋ธ ๋ก๋ ์์ ๋ชจ๋ ๊ฒ์ ์ํํ๋ฏ๋ก ์ด๋ ํ ํ์ฒ๋ฆฌ ๋๋ ์ค๋น ์คํ ์ ๊ฑฐ์น์ง ์์๋ ๋.
- cross-modality interoperability ๐งฐ: ์ด๋ ํ modality๋ผ๊ณ ํด๋ quantization์ด ๊ฐ๋ฅํจ. ๋ฐ๋ผ์ ๋ฒ์ฉ์ฑ์ด ๋์.
- 0 performance degradation when merging adapters โ : ํ์ต๋ adapter๋ฅผ base model ๋๋ dequantized model์ ์ด๋ ํ ์ฑ๋ฅ ์ ํ ์์ด ํฉ์น ์ ์์. merging์ GPTQ์์๋ ์ง์๋์ง ์์.
Rooms of Improvements
- slower than GPTQ for text generation ๐ข: bitsandbytes์ 4-bit model์ inference ์์ GPTQ๋ณด๋ค ๋๋ฆฐ ์๋๋ฅผ ๋ณด์ฌ์ค.
- 4-bit weights are nor serializable ๐: ํ์ฌ๋ก์๋ 4-bit model์ ์ง๋ ฌํํ ์ ์์.
The benefits & rooms of improvements of GPTQ
Benefits
- fast for text generation โฉ: text generation ์ธก๋ฉด์์ GPTQ quantized model์ bitsandbytes quantized model๋ณด๋ค ๋น ๋ฅธ ์๋๋ฅผ ๋ณด์ฌ์ค.
- n-bit support ๐ข: GPTQ ์๊ณ ๋ฆฌ์ฆ์ 2bit ์ด์์ผ๋ก ๋ชจ๋ธ์ ์์ํํ ์ ์์. ํ์ง๋ง, ์ถ์ฒ๋๋ bit์ ์๋ 4์.
- easily serializable ๐: GPTQ model์ ์ด๋ค ์์ bit๋ ์ง๋ ฌํ๋ฅผ ์ง์ํจ.
- AMD Support ๐ฝ: Nvidia GPU ๋ฟ๋ง ์๋๋ผ AMD GPU๋ ์ง์๋จ.
Rooms of Improvements
- calibration dataset ๐: GPTQ๋ฅผ ์ํด์๋ calibration dataset์ด ํ์ํ๋ฐ, ์ด๋ก ์ธํด GPTQ๋ฅผ ์ฌ์ฉํ๋ ค๋ ์ฌ์ฉ์๋ค์ด ์ค์ด๋ฆ. ๊ฒ๋ค๊ฐ model์ quantize ํ๊ธฐ ์ํด์๋ ์กฐ๊ธ ๋ง์ ์๊ฐ์ด ์์๋จ.
- works only for language models ๐ข: GPTQ๋ ์ค์ง language model์ ์ํด์๋ง ๋ง๋ค์ด์ก์.
Conclusion & Final Words of Blog ๐ซก
HuggingFace์ ๋ธ๋ก๊ทธ ํฌ์คํธ์์๋ ๊ฐ quantization method์ ๋น๊ต๋ฅผ ํ๊ณ ๋ง์ง๋ง ๋ถ๋ถ์ ์ด๋ฅผ ํ ๋๋ก ๋ค์๊ณผ ๊ฐ์ด quantization์ ์งํํ๋ ๊ฒ์ด ๊ฐ์ฅ ํจ์จ์ ์ด๋ผ๋ ๊ฒ์ ์ฃผ์ฅํ์๋ค. ํ์๊ฐ ์งํํ ํ๋ก์ ํธ์์๋ ์ด๋ฌํ ์ฃผ์ฅ์ ์ค์ ์คํ์ ํตํด ํจ์จ์ฑ์ ์ ์ฆํ๊ณ ์ ํ ๊ฒ์ด๋ค.
Suggestion of Blog
- bitsandbytes๋ฅผ ์ฌ์ฉํด์ base model์ ์์ํํจ
- adapter๋ฅผ ์ถ๊ฐํ๊ณ fine-tuning
- base model ๋๋ dequantized model์ ์์ ํ์ต๋ adapter๋ฅผ merge ํจ
- GPTQ๋ฅผ ์ฌ์ฉํด์ merged model์ quantize ํ๊ณ , ์ด๋ฅผ ์ด์ฉํด์ inference๋ฅผ ์งํ
Experiments ๐งช
๋ณธ ํ๋ก์ ํธ์์ ์งํํ ์คํ์ HuggingFace ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์ฃผ์ฅํ method๊ฐ ์ค์ ๋ก ํจ์จ์ ์ผ์ง fine-tuning ์์ ํจ์จ์ฑ๊ณผ inference ์์ ํจ์จ์ฑ์ ๋น๊ตํ๋ฉฐ ์คํ์ ์งํํ์๋ค. ์ด๋ฅผ ์ํด ๊ธฐ๋ณธ์ ์ธ setup์ ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์ฌ์ฉ๋ setup์ ๋ฐ๋๊ณ , ์คํ๊ณผ ๊ด๋ จํด์ ๋์ฑ ์์ธํ ๋ด์ฉ์ Github Repository๋ฅผ ์ฐธ๊ณ ํด ์ฃผ์๊ธธ ๋ฐ๋ผ๊ฒ ์ต๋๋ค. baseline์ ๋ค์๊ณผ ๊ฐ๋ค.
Baselines
- fine-tune w/ bitsandbytes & inference w/ bitsandbytes
- fine-tune w/ auto-GPTQ & inference w/ auto-GPTQ
- fine-tune w/ bitsandbytes & inference w/ auto-GPTQ(proposed method)
Results
Benchmark
๊ฐ baseline์ ํจ์จ์ฑ์ ํ๊ฐํ๊ธฐ ์ํด ๋ค์๊ณผ ๊ฐ์ ์นดํ ๊ณ ๋ฆฌ์์ ๋ชจ๋ธ์ ์ธก์ ํ์๋ค.
- Fine-tuning: Throughput per second(steps). ์ด ์งํ๋ fine-tuning ์์ ๋ชจ๋ธ์ด ์ด ๋น ์ฒ๋ฆฌํ๋ ์คํ ์ ์๋ฅผ ๋ํ๋.
- Inference: Average inference time(s). ์ด ์งํ๋ ํ ๋ฒ์ inference๋ฅผ ์ํํ๊ธฐ ์ํด ์์๋๋ ์๊ฐ์ ์๋ฏธํจ.
Fine-tuning
์๋์ ํ๋ฅผ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด, bitsandbytes๊ฐ GPTQ๋ณด๋ค ๋ ๋น ๋ฅธ fine-tuning ์๋๋ฅผ ๋ณด์ฌ์ค๋ค. ์ด ๊ฒฐ๊ณผ๋ HuggingFace ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์ ์๋์๋ method๋ฅผ ๋ท๋ฐ์นจํด ์ค๋ค(bitsandbytes๋ฅผ ์ฌ์ฉํด์ adapter๋ฅผ fine-tuning)!
Quantization Method | Throughput Per-Second(steps) โฌ๏ธ | Fine-tuning time(s) โฌ๏ธ |
GPTQ | 1.45 | 712 |
bitsandbytes | 2.18 | 469 |
Inference
๊ฐ baseline์ inference speed๋ฅผ ๋น๊ต ๊ฒฐ๊ณผ๋ ๋ค์์ ๊ทธ๋ํ์ ๊ฐ๋ค.
์ ๊ทธ๋ํ๋ฅผ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด HuggingFace ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์ ์๋ method(bnb-gptq)๊ฐ ๋ค๋ฅธ method์ ๋นํด์ ๋์ฑ ๋น ๋ฅธ ์๋๋ก inference๋ฅผ ์งํํ๋ค.
Final Results
์ด๋ ๊ฒ ํด์ fine-tuning & inference์ ๋ํ ๋ฒค์น๋งํน์ด ์๋ฃ๋์๋ค. ๋ค์์ ํ๋ ๊ฐ baseline์ ์ข ํฉ์ ์ธ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋ค. ๋ค์์ ํ๋ฅผ ๋ณด๋ฉด ์ ์ ์๋ฏ์ด HuggingFace ๋ธ๋ก๊ทธ ํฌ์คํธ์์ ์ ์๋ 'bnb-gptq'๊ฐ ๋ค๋ฅธ ๋ชจ๋ธ์ ๋นํด ๋์ฑ ํจ๊ณผ์ ์ด๋ผ๋ ๊ฒ์ ์ ์ ์๋ค!
Method(Baseline) | Throughput Per-Seconf(steps) โฌ๏ธ | Inference Speed(step/s) โฌ๏ธ |
bnb-bnb | 2.18 | 6.06 |
gptq-gptq | 1.45 | 2.04 |
bnb-gptq ๐ | 1.45 | 1.31 |
Closing post..
์ด ํ๋ก์ ํธ๋ ์์๋ ๋งํ๋ ๊ฒ์ฒ๋ผ HuggingFace์ ๋ธ๋ก๊ทธ ํฌ์คํธ์ธ 'Overview of natively supported quantization schemes in ๐ค Transformers' ์์์ ์ฃผ์ฅ์ ์ ์ฆํ๊ธฐ ์ํด ์งํ๋์๋ค. ์ค์ ๋ก ์คํ์ ํตํด ๋ธ๋ก๊ทธ ํฌ์คํธ์ ์ฃผ์ฅ์ด ํจ์จ์ ์ด๋ผ๋ ๊ฒ์ ์ ์ฆํ์์ผ๋, ์์์ ๋ถ์กฑ์ผ๋ก ์ธํด performance degradation ๋ฑ์ ํจ๊ณผ์ ์ธ ์ธก๋ฉด์ ๊ฒ์ฆํ์ง ๋ชปํ๋ค. ๋ฐ๋ผ์ ์ด๋ฌํ ๋ถ๋ถ์ future work๋ก ๋จ๊ฒจ๋๋๋ก ํ๊ฒ ๋ค. ๋ค์ ํ๋ฒ 'Overview of natively supported quantization schemes in ๐ค Transformers' ์ ๋ชจ๋ author ๋ถ๋ค๊ป ๊ฐ์ฌ๋๋ฆฐ๋ค๋ ๋ง์์ ๋๋ฆฌ๋ฉฐ ํฌ์คํธ๋ฅผ ๋ง์น๊ฒ ๋ค!
์ถ์ฒ
https://huggingface.co/blog/overview-quantization-transformers
Overview of natively supported quantization schemes in ๐ค Transformers
Overview of natively supported quantization schemes in ๐ค Transformers We aim to give a clear overview of the pros and cons of each quantization scheme supported in transformers to help you decide which one you should go for. Currently, quantizing models
huggingface.co
https://github.com/gauss5930/Quantization/tree/main
GitHub - gauss5930/Quantization: The comparison of most popular quantization methods, BitsAndBytes and GPTQ
The comparison of most popular quantization methods, BitsAndBytes and GPTQ - GitHub - gauss5930/Quantization: The comparison of most popular quantization methods, BitsAndBytes and GPTQ
github.com
'Research & Project ๐ฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
AlpaGasus2-QLoRA ๐ฆ๐ฆ๐ค (1) | 2023.09.05 |
---|