AutoAWQ

AutoAWQ

AutoAWQ로 새로운 4비트 양자화 모델을 만들 수 있어요. 양자화는 모델의 정밀도를 BF16/FP16에서 INT4로 줄여 전체 모델 메모리 풋프린트를 효과적으로 줄입니다. 주요 이점은 더 낮은 지연 시간과 메모리 사용량입니다.

⚠️ 경고: AutoAWQ 라이브러리는 deprecated입니다. 이 기능은 vLLM 프로젝트의 llm-compressor 로 채택되었습니다. 권장 양자화 워크플로우는 llm-compressor 의 AWQ 예시를 참고하세요. deprecated에 대한 자세한 내용은 원본 AutoAWQ 저장소 를 참고하세요.

출처: 문서

본문

AutoAWQ를 설치하거나 Huggingface의 6500+ 모델 중 하나를 골라 자신의 모델을 양자화할 수 있습니다.

pip install autoawq

AutoAWQ를 설치한 후 모델을 양자화할 준비가 됩니다. 자세한 내용은 AutoAWQ 문서 를 참고하세요. mistralai/Mistral-7B-Instruct-v0.2 를 양자화하는 예시입니다.

from awq import AutoAWQForCausalLM
from transformers import AutoTokenizer

model_path = "mistralai/Mistral-7B-Instruct-v0.2"
quant_path = "mistral-instruct-v0.2-awq"
quant_config = {"zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM"}

# Load model
model = AutoAWQForCausalLM.from_pretrained(
    model_path,
    low_cpu_mem_usage=True,
    use_cache=False,
)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)

# Quantize
model.quantize(tokenizer, quant_config=quant_config)

# Save quantized model
model.save_quantized(quant_path)
tokenizer.save_pretrained(quant_path)

print(f'Model is quantized and saved at "{quant_path}"')

vLLM으로 AWQ 모델을 실행하려면 TheBloke/Llama-2-7b-Chat-AWQ 를 다음 명령으로 사용할 수 있습니다.

python examples/deployment/llm_engine_example.py \
    --model TheBloke/Llama-2-7b-Chat-AWQ \
    --quantization auto_awq

AWQ 모델은 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.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="TheBloke/Llama-2-7b-Chat-AWQ", quantization="auto_awq")
# 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.
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

더 알아보기 (Learn more)