Transformers documentation
Quark
Quark
Quark๋ ํน์ ๋ฐ์ดํฐ ํ์ , ์๊ณ ๋ฆฌ์ฆ, ํ๋์จ์ด์ ๊ตฌ์ ๋ฐ์ง ์๋๋ก ์ค๊ณ๋ ๋ฅ๋ฌ๋ ์์ํ ํดํท์ ๋๋ค. Quark์์๋ ๋ค์ํ ์ ์ฒ๋ฆฌ ์ ๋ต, ์๊ณ ๋ฆฌ์ฆ, ๋ฐ์ดํฐ ํ์ ์ ์กฐํฉํ์ฌ ์ฌ์ฉํ ์ ์์ต๋๋ค.
๐ค Transformers๋ฅผ ํตํด ํตํฉ๋ PyTorch ์ง์์ ์ฃผ๋ก AMD CPU ๋ฐ GPU๋ฅผ ๋์์ผ๋ก ํ๋ฉฐ, ์ฃผ๋ก ํ๊ฐ ๋ชฉ์ ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. ์๋ฅผ ๋ค์ด, lm-evaluation-harness๋ฅผ ๐ค Transformers ๋ฐฑ์๋์ ํจ๊ป ์ฌ์ฉํ์ฌ Quark๋ก ์์ํ๋ ๋ค์ํ ๋ชจ๋ธ์ ์ํํ๊ฒ ํ๊ฐํ ์ ์์ต๋๋ค.
Quark์ ๊ด์ฌ์ด ์๋ ์ฌ์ฉ์๋ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋ชจ๋ธ ์์ํ๋ฅผ ์์ํ๊ณ ์ง์๋๋ ์คํ ์์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค!
Quark๋ ์์ฒด ์ฒดํฌํฌ์ธํธ/์ค์ ํฌ๋งท๋ฅผ ๊ฐ์ง๊ณ ์์ง๋ง, ๋ค๋ฅธ ์์ํ/๋ฐํ์ ๊ตฌํ์ฒด (AutoAWQ, ๋ค์ดํฐ๋ธ fp8)์ ํธํ๋๋ ์ง๋ ฌํ ๋ ์ด์์์ผ๋ก ๋ชจ๋ธ์ ์์ฑํ๋ ๊ฒ๋ ์ง์ํฉ๋๋ค.
Transformer์์ 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) | per-tensor, per-channel, per-block, per-layer, per-layer type | |
KV ์บ์ | fp8 | |
ํ์ฑํ ์บ๋ฆฌ๋ธ๋ ์ด์ | MinMax / Percentile / MSE | |
์์ํ ์ ๋ต | weight-only, static, dynamic, with or without output quantization |
Hugging Face Hub์ ๋ชจ๋ธ
Quark ๋ค์ดํฐ๋ธ ์ง๋ ฌํ๋ฅผ ์ฌ์ฉํ๋ ๊ณต๊ฐ ๋ชจ๋ธ์ https://huggingface.co/models?other=quark ์์ ์ฐพ์ ์ ์์ต๋๋ค.
Quark๋ quant_method="fp8"
์ ์ด์ฉํ๋ ๋ชจ๋ธ๊ณผ quant_method="awq"
์ ์ฌ์ฉํ๋ ๋ชจ๋ธ๋ ์ง์ํ์ง๋ง, Transformers๋ ์ด๋ฌํ ๋ชจ๋ธ์ AutoAWQ๋ฅผ ํตํด ๋ถ๋ฌ์ค๊ฑฐ๋
๐ค Transformers์ ๋ค์ดํฐ๋ธ fp8 ์ง์์ ์ฌ์ฉํฉ๋๋ค.
Transformers์์ Quark๋ชจ๋ธ ์ฌ์ฉํ๊ธฐ
๋ค์์ 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)
model = model.to("cuda")
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("cuda")
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