BitsAndBytes
BitsAndBytes
vLLM은 이제 더 효율적인 모델 추론을 위해 BitsAndBytes 를 지원해요. BitsAndBytes는 정확도를 크게 희생하지 않으면서 메모리 사용량을 줄이고 성능을 높이도록 모델을 양자화합니다. 다른 양자화 방법과 달리 BitsAndBytes는 입력 데이터로 양자화된 모델을 보정(calibrate)할 필요가 없습니다.
BitsAndBytes 지원은 트리 밖의 vllm-bnb-plugin 이 제공합니다. vLLM과 함께 BitsAndBytes를 사용하기 전에 플러그인을 설치하세요.
출처: 문서
본문
uv pip install vllm-bnb-plugin
vLLM은 모델의 구성 파일을 읽고, 인플라이트(in-flight) 양자화와 사전 양자화된 체크포인트를 모두 지원합니다.
bitsandbytes 양자화 모델은 Hugging Face 에서 찾을 수 있어요. 보통 이러한 저장소는 quantization_config 섹션을 포함하는 config.json 파일을 갖고 있습니다.
양자화된 체크포인트 읽기 (Read quantized checkpoint)
사전 양자화된 체크포인트의 경우 vLLM은 구성 파일에서 양자화 방법을 추론하려 시도하므로 quantization 인자를 명시적으로 지정할 필요가 없습니다.
from vllm import LLM
import torch
# unsloth/tinyllama-bnb-4bit is a pre-quantized checkpoint.
model_id = "unsloth/tinyllama-bnb-4bit"
llm = LLM(
model=model_id,
dtype=torch.bfloat16,
trust_remote_code=True,
)
인플라이트 양자화: 4bit 양자화로 로드 (Inflight quantization: load as 4bit quantization)
BitsAndBytes로 인플라이트 4bit 양자화를 하려면 quantization 인자를 명시적으로 지정해야 합니다.
from vllm import LLM
import torch
model_id = "huggyllama/llama-7b"
llm = LLM(
model=model_id,
dtype=torch.bfloat16,
trust_remote_code=True,
quantization="bitsandbytes",
)
OpenAI 호환 서버 (OpenAI Compatible Server)
4bit 인플라이트 양자화를 위해 모델 인자에 다음을 추가하세요.
--quantization bitsandbytes