Quark

Quark

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

출처: 문서

본문

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

🤗 Transformers를 통해 통합된 PyTorch 지원은 주로 AMD CPU와 GPU를 대상으로 하며, 주로 평가 목적으로 사용됩니다. 예를 들어 🤗 Transformers 백엔드에서 lm-evaluation-harness를 사용해 Quark로 양자화된 다양한 모델을 매끄럽게 평가할 수 있습니다.

Quark에 관심이 있는 사용자는 문서를 참고해 모델 양자화를 시작하고 지원되는 오픈소스 라이브러리에서 사용할 수 있습니다!

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

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

pip install amd-quark

Support matrix

Quark로 양자화된 모델은 함께 결합할 수 있는 다양한 기능을 지원합니다. 설정과 무관하게 모든 양자화된 모델은 PretrainedModel.from_pretrained를 통해 매끄럽게 다시 로드할 수 있습니다.

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

Feature Supported subset in Quark
Data types int8, int4, int2, bfloat16, float16, fp8_e5m2, fp8_e4m3, fp6_e3m2, fp6_e2m3, fp4, OCP MX, MX6, MX9, bfp16
Pre-quantization transformation SmoothQuant, QuaRot, SpinQuant, AWQ
Quantization algorithm GPTQ
Supported operators nn.Linear, nn.Conv2d, nn.ConvTranspose2d, nn.Embedding, nn.EmbeddingBag
Granularity per-tensor, per-channel, per-block, per-layer, per-layer type
KV cache fp8
Activation calibration MinMax / Percentile / MSE
Quantization strategy weight-only, static, dynamic, with or without output quantization

Models on Hugging Face Hub

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

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

Using Quark models in Transformers

Transformers에서 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

더 알아보기 (Learn more)