GPTQModel
GPTQModel
새로운 4비트 또는 8비트 GPTQ 양자화 모델을 만들려면 ModelCloud.AI의 GPTQModel 을 활용할 수 있어요.
양자화는 모델의 정밀도를 BF16/FP16(16비트)에서 INT4(4비트) 또는 INT8(8비트)로 줄여 전체 모델 메모리 풋프린트를 크게 줄이면서 동시에 추론 성능을 높입니다.
호환되는 GPTQModel 양자화 모델은 Marlin 및 Machete vLLM 커스텀 커널을 활용해 Ampere(A100+) 및 Hopper(H100+) NVIDIA GPU 모두에서 배칭 transactions-per-second(tps)와 토큰 지연 성능을 극대화할 수 있어요. 이 두 커널은 vLLM과 NeuralMagic(현재 Redhat 소속)이 고도로 최적화해 양자화된 GPTQ 모델의 세계적 수준의 추론 성능을 제공합니다.
GPTQModel은 언어 모델 내 서로 다른 레이어 및/또는 모듈을 커스텀 양자화 파라미터로 추가 최적화할 수 있는 Dynamic per-module 양자화를 지원하는 세계에서 몇 안 되는 양자화 툴킷 중 하나입니다. Dynamic 양자화는 vLLM에 완전히 통합되어 있으며 ModelCloud.AI 팀의 지원을 받습니다. 이와 다른 고급 기능에 대한 자세한 내용은 GPTQModel readme 를 참고하세요.
출처: 문서
본문
설치 (Installation)
GPTQModel 을 설치하거나 Huggingface의 5000+ 모델 중 하나를 골라 자신의 모델을 양자화할 수 있습니다.
pip install -U gptqmodel --no-build-isolation -v
모델 양자화 (Quantizing a model)
GPTQModel 설치 후 모델을 양자화할 준비가 됩니다. 자세한 내용은 GPTQModel readme 를 참고하세요.
meta-llama/Llama-3.2-1B-Instruct 를 양자화하는 예시입니다.
from datasets import load_dataset
from gptqmodel import GPTQModel, QuantizeConfig
model_id = "meta-llama/Llama-3.2-1B-Instruct"
quant_path = "Llama-3.2-1B-Instruct-gptqmodel-4bit"
calibration_dataset = load_dataset(
"allenai/c4",
data_files="en/c4-train.00001-of-01024.json.gz",
split="train",
).select(range(1024))["text"]
quant_config = QuantizeConfig(bits=4, group_size=128)
model = GPTQModel.load(model_id, quant_config)
# increase `batch_size` to match gpu/vram specs to speed up quantization
model.quantize(calibration_dataset, batch_size=2)
model.save(quant_path)
vLLM으로 양자화 모델 실행 (Running a quantized model with vLLM)
DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v2 를 다음 명령으로 사용할 수 있습니다.
python examples/deployment/llm_engine_example.py \
--model ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v2
vLLM Python API로 GPTQModel 사용
GPTQModel 양자화 모델은 LLM 엔트리포인트를 통해서도 직접 지원됩니다.
from vllm import LLM, SamplingParams
# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.6, top_p=0.9)
# Create an LLM.
llm = LLM(model="ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v2")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
# Print the outputs.
print("-"*50)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}\nGenerated text: {generated_text!r}")
print("-"*50)