CoolFace
Modelpublic

RedHatAI/Llama-Guard-4-12B-quantized.w4a16

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes2kdownloads
Model Card

Evaluations are produced with https://github.com/neuralmagic/GuardBench and vLLM as an inference engine.

Evaluations are obtained with vllm==0.15.0 and bug fixes from this PR.

Datasetmeta-llama/Llama-Guard-4-12B<br>F1RedHatAI/Llama-Guard-4-12B-quantized.w4a16<br>(this model)<br>F1F1 Recovery %meta-llama/Llama-Guard-4-12B<br>RecallRedHatAI/Llama-Guard-4-12B-quantized.w4a16<br>RecallRecall<br>Recovery %
AART0.8740.86598.970.7760.76198.07
AdvBench Behaviors0.9640.968100.410.9310.938100.75
AdvBench Strings0.830.82399.160.7090.69998.59
BeaverTails 330k0.7320.72799.320.5910.58498.82
Bot-Adversarial Dialogue0.5130.49997.270.3760.36196.01
CatQA0.9320.92799.460.8730.86498.97
ConvAbuse0.2410.248102.90.1480.156105.41
DecodingTrust Stereotypes0.5910.5491.370.4190.3788.31
DICES 3500.1180.1181000.0630.063100
DICES 9900.2190.226103.20.1350.135100
Do Anything Now Questions0.7460.7499.20.5950.58798.66
DoNotAnswer0.5460.53998.720.3760.36897.87
DynaHate0.6030.58797.350.4810.45995.43
HarmEval0.560.571101.960.3890.4102.83
HarmBench Behaviors0.9590.95499.480.9220.91298.92
HarmfulQ0.860.85799.650.7550.7599.34
HarmfulQA Questions0.5880.58399.150.4160.41198.8
HarmfulQA0.3740.34792.780.2310.2190.91
HateCheck0.7820.7798.470.6670.64997.3
Hatemoji Check0.6250.60997.440.4740.45796.41
HEx-PHI0.9660.95598.860.9330.91397.86
I-CoNa0.8370.81397.130.7190.68595.27
I-Controversial0.5960.621104.190.4250.45105.88
I-MaliciousInstructions0.8240.81799.150.70.6998.57
I-Physical-Safety0.4930.48297.770.340.3397.06
JBB Behaviors0.860.861000.860.86100
MaliciousInstruct0.9530.958100.520.910.92101.1
MITRE0.6630.64997.890.4950.4896.97
NicheHazardQA0.460.469101.960.2990.307102.68
OpenAI Moderation Dataset0.7390.741100.270.7870.7899.11
ProsocialDialog0.4270.41496.960.2760.26596.01
SafeText0.3720.36898.920.2540.24696.85
SimpleSafetyTests0.9850.99100.510.970.98101.03
StrongREJECT Instructions0.910.90299.120.8360.82298.33
TDCRedTeaming0.9470.958101.160.90.92102.22
TechHazardQA0.7580.7598.940.610.698.36
Toxic Chat0.4330.4331000.5190.50897.88
ToxiGen0.460.44496.520.3150.395.24
XSTest0.8340.83299.760.780.76598.08
Average Score0.67112820510.665487179599.125384620.57064102560.562948717998.45897436

Model creation

This model is created with compressed-tensors==0.13.0 and llmcompressor==0.9.0.1, and the following LLM-Compressor quantization script:

bash
CUDA_VISIBLE_DEVICES=0 python quantize.py --model_path meta-llama/Llama-Guard-4-12B --quant_path RedHatAI/Llama-Guard-4-12B-quantized.w4a16 --group_size 128 --calib_size 1024 --dampening_frac 0.01 --observer minmax --sym True --actorder False --pipeline independent
python
from datasets import load_dataset
from transformers import AutoProcessor, Llama4ForConditionalGeneration
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor import oneshot
import argparse
from compressed_tensors.quantization import QuantizationScheme, QuantizationArgs, QuantizationType, QuantizationStrategy

def parse_actorder(value):
    # Interpret the input value for --actorder
    if value.lower() == "false":
        return False
    elif value.lower() == "group":
        return "group"
    elif value.lower() == "weight":
        return "weight"
    else:
        raise argparse.ArgumentTypeError("Invalid value for --actorder. Use 'group', 'weight', or 'False'.")

def parse_sym(value):
    if value.lower() == "false":
        return False
    elif value.lower() == "true":
        return True
    else:
        raise argparse.ArgumentTypeError(f"Invalid value for --sym. Use false or true, but got {value}")

parser = argparse.ArgumentParser()
parser.add_argument('--model_path', type=str, required=True)
parser.add_argument('--quant_path', type=str, required=True)
parser.add_argument('--group_size', type=int, required=True)
parser.add_argument('--calib_size', type=int, required=True)
parser.add_argument('--dampening_frac', type=float, required=True)
parser.add_argument('--observer', type=str, required=True) # mse or minmax
parser.add_argument('--sym', type=parse_sym, required=True) # true or false
parser.add_argument('--actorder', type=parse_actorder, required=True) # group or weight or false
parser.add_argument('--pipeline', type=str, default="basic") # ['basic', 'datafree', 'sequential', independent]

args = parser.parse_args()

model = Llama4ForConditionalGeneration.from_pretrained(
    args.model_path,
    torch_dtype="auto",
    trust_remote_code=True,
)
processor = AutoProcessor.from_pretrained(args.model_path, trust_remote_code=True)

def preprocess_fn(example):
    # prepare for multimodal processor
    for msg in example["messages"]:
        msg["content"] = [{'type': 'text', 'text': msg['content']}]

    return {"text": processor.apply_chat_template(example["messages"], add_generation_prompt=False, tokenize=False)}

ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
ds = ds.map(preprocess_fn)

print(f"================================================================================")
print(f"[For debugging] Calibration data sample is:\n{repr(ds[0]['text'])}")
print(f"================================================================================")

quant_scheme = QuantizationScheme(
    targets=["Linear"],
    weights=QuantizationArgs(
        num_bits=4,
        type=QuantizationType.INT,
        symmetric=args.sym,
        group_size=args.group_size,
        strategy=QuantizationStrategy.GROUP,
        observer=args.observer,
        actorder=args.actorder
    ),
    input_activations=None,
    output_activations=None,
)

recipe = [
    GPTQModifier(
        targets=["Linear"],
        ignore=[
            "re:.*lm_head",
            "re:.*multi_modal_projector",
            "re:.*vision_model",
        ],
        dampening_frac=args.dampening_frac,
        config_groups={"group_0": quant_scheme},
    )
]
oneshot(
    model=model,
    dataset=ds,
    recipe=recipe,
    num_calibration_samples=args.calib_size,
    max_seq_length=4096,
    pipeline=args.pipeline,
)

SAVE_DIR = args.quant_path
model.save_pretrained(SAVE_DIR)
print(f"Model saved to {SAVE_DIR}. Please manually copy other files like tokenizer, proprocessors, etc.")