Transformers documentation

Quark

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Quark

Quark은 특정 데이터 유형, 알고리즘, 하드웨어에 종속되지 않도록 설계된 딥러닝 양자화 툴킷입니다. Quark에서는 다양한 전처리 전략, 알고리즘, 데이터 유형을 조합할 수 있습니다.

🤗 Transformers를 통해 통합된 PyTorch 지원은 주로 AMD CPU 및 GPU를 대상으로 하며, 평가 목적으로 사용하도록 설계되었습니다. 예를 들어, lm-evaluation-harness에 🤗 Transformers 백엔드를 사용하여 Quark를 통해 양자화된 다양한 모델을 원활하게 평가할 수 있습니다.

Quark에 관심이 있는 사용자는 문서를 참고하여 모델 양자화 시작 및 지원되는 오픈소스 라이브러리에서 모델을 사용하는 방법을 확인해 보세요!

Quark에는 자체적인 체크포인트 / 설정 형식이 있지만, 이 라이브러리는 다른 양자화/러타임 구현(AutoAWQ, 🤗 Transformers의 네이티브 fp8)과 호환되는 직렬화 레이아웃으로 모델을 생성하는 것도 지원합니다.

Transformers에서 Quark 양자화 모델을 로드하려면 먼저 라이브러리를 설치해야 합니다:

pip install amd-quark

지원 매트릭스

Quark를 통해 양자화된 모델은 다양한 기능을 지원하며, 이러한 기능들을 조합하여 사용할 수 있습니다. 설정과 무관하게 모든 양자화 모델은 PretrainedModel.from_pretrained를 통해 매끄럽게 다시 로드할 수 있습니다.

아래 표는 Quark가 지원하는 몇 가지 기능을 보여 줍니다:

기능Quark에서 지원되는 부분 집합
데이터 유형int8, int4, int2, bfloat16, float16, fp8_e5m2, fp8_e4m3, fp6_e3m2, fp6_e2m3, fp4, OCP MX, MX6, MX9, bfp16
양자화 전 변환SmoothQuant, QuaRot, SpinQuant, AWQ
양자화 알고리즘GPTQ
지원되는 연산자nn.Linear, nn.Conv2d, nn.ConvTranspose2d, nn.Embedding, nn.EmbeddingBag
Granularity텐서별, 채널별, 블록별, 레이어별, 레이어별 유형
KV 캐시fp8
활성화 보정MinMax / 백분위 / MSE
양자화 전략weight-only, static, dynamic, 출력 양자화 포함 또는 미포함

Hugging Face Hub의 모델

Quark 네이티브 직렬화를 사용하는 공개 모델은 https://huggingface.co/models?other=quark에서 찾을 수 있습니다.

Quark은 quant_method="fp8"를 사용하는 모델과 quant_method="awq"를 사용하는 모델도 지원하지만, Transformers는 이러한 모델을 AutoAWQ를 통해 로드하거나 🤗 Transformers의 네이티브 fp8 지원을 사용하는 방식으로 처리합니다.

Transformers에서 Quark 모델 사용

…에서 Quark 모델을 로드하는 예시는 다음과 같습니다:

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "EmbeddedLLM/Llama-3.1-8B-Instruct-w_fp8_per_channel_sym"
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

print(model.model.layers[0].self_attn.q_proj)
# QParamsLinear(
#   (weight_quantizer): ScaledRealQuantizer()
#   (input_quantizer): ScaledRealQuantizer()
#   (output_quantizer): ScaledRealQuantizer()
# )

tokenizer = AutoTokenizer.from_pretrained(model_id)
inp = tokenizer("Where is a good place to cycle around Tokyo?", return_tensors="pt")
inp = inp.to(model.device)

res = model.generate(**inp, min_new_tokens=50, max_new_tokens=100)

print(tokenizer.batch_decode(res)[0])
# <|begin_of_text|>Where is a good place to cycle around Tokyo? There are several places in Tokyo that are suitable for cycling, depending on your skill level and interests. Here are a few suggestions:
# 1. Yoyogi Park: This park is a popular spot for cycling and has a wide, flat path that's perfect for beginners. You can also visit the Meiji Shrine, a famous Shinto shrine located in the park.
# 2. Imperial Palace East Garden: This beautiful garden has a large, flat path that's perfect for cycling. You can also visit the
Update on GitHub