Quark (original) (raw)

Quark is a deep learning quantization toolkit designed to be agnostic to specific data types, algorithms, and hardware. Different pre-processing strategies, algorithms and data-types can be combined in Quark.

The PyTorch support integrated through πŸ€— Transformers primarily targets AMD CPUs and GPUs, and is primarily meant to be used for evaluation purposes. For example, it is possible to use lm-evaluation-harness with πŸ€— Transformers backend and evaluate a wide range of models quantized through Quark seamlessly.

Users interested in Quark can refer to its documentation to get started quantizing models and using them in supported open-source libraries!

Although Quark has its own checkpoint / configuration format, the library also supports producing models with a serialization layout compliant with other quantization/runtime implementations (AutoAWQ, native fp8 in πŸ€— Transformers).

To be able to load Quark quantized models in Transformers, the library first needs to be installed:

Support matrix

Models quantized through Quark support a large range of features, that can be combined together. All quantized models independently of their configuration can seamlessly be reloaded through PretrainedModel.from_pretrained.

The table below shows a few features supported by 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

Public models using Quark native serialization can be found at https://huggingface.co/models?other=quark.

Although Quark also supports models using quant_method="fp8" and models using quant_method="awq", Transformers loads these models rather through AutoAWQ or uses the native fp8 support in πŸ€— Transformers.

Using Quark models in Transformers

Here is an example of how one can load a Quark model in Transformers:

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)

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])

< > Update on GitHub