ipeline to convert Llama-Prompt-Guard-2 models into ONNX format
Python
1
2 commits
updated Sep 22, 2025
This repository provides a pipeline to convert Llama-Prompt-Guard-2 models into ONNX format, perform optional optimizations and quantization, and evaluate performance on classification datasets.
AutoModelForSequenceClassification models to ONNX.pip install -r requirements.txt
python convert_to_onnx.py \
--model-name meta-llama/Llama-Prompt-Guard-2-22M \
--export-onnx \
--quantize-onnx \
--update-config
This will:
gravitee-io/Llama-Prompt-Guard-2-22M-onnxmodel.onnx)model.optim.onnx and model.quant.onnx)config.json with id2label and label2idpython evaluate.py \
--dataset jackhhao/jailbreak-classification \
--model-path gravitee-io/Llama-Prompt-Guard-2-22M-onnx \
--quantized \
--plot-roc
You can toggle --quantized to evaluate either the full or quantized model.
| Model | Accuracy | Precision | Recall | F1 Score | AUC-ROC |
|---|---|---|---|---|---|
| Llama-Prompt-Guard-2-22M | 0.9564 | 0.9888 | 0.9249 | 0.9558 | 0.9234 |
| Llama-Prompt-Guard-2-22M-q | 0.9579 | 0.9967 | 0.9204 | 0.9449 | 0.9180 |
| Llama-Prompt-Guard-2-86M | 0.9801 | 0.9984 | 0.9625 | 0.9801 | 0.9519 |
| Llama-Prompt-Guard-2-86M-q | 0.8989 | 1.0000 | 0.8018 | 0.89 | 0.7452 |
We use jackhhao/jailbreak-classification
for the evaluation
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification
import numpy as np
# Load model and tokenizer using optimum
model = ORTModelForSequenceClassification.from_pretrained("gravitee-io/Llama-Prompt-Guard-2-22M-onnx", file_name="model.quant.onnx")
tokenizer = AutoTokenizer.from_pretrained("gravitee-io/Llama-Prompt-Guard-2-22M-onnx")
# Tokenize input
text = "Your comment here"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
# Run inference
outputs = model(**inputs)
logits = outputs.logits
# Optional: convert to probabilities
probs = 1 / (1 + np.exp(-logits))
print(probs)
You can find and use the quantized ONNX model from the Hugging:xFace repository:
2 commits
Python
100.0%
ipeline to convert Llama-Prompt-Guard-2 models into ONNX format
Python
1
2 commits
updated Sep 22, 2025
This repository provides a pipeline to convert Llama-Prompt-Guard-2 models into ONNX format, perform optional optimizations and quantization, and evaluate performance on classification datasets.
AutoModelForSequenceClassification models to ONNX.pip install -r requirements.txt
python convert_to_onnx.py \
--model-name meta-llama/Llama-Prompt-Guard-2-22M \
--export-onnx \
--quantize-onnx \
--update-config
This will:
gravitee-io/Llama-Prompt-Guard-2-22M-onnxmodel.onnx)model.optim.onnx and model.quant.onnx)config.json with id2label and label2idpython evaluate.py \
--dataset jackhhao/jailbreak-classification \
--model-path gravitee-io/Llama-Prompt-Guard-2-22M-onnx \
--quantized \
--plot-roc
You can toggle --quantized to evaluate either the full or quantized model.
| Model | Accuracy | Precision | Recall | F1 Score | AUC-ROC |
|---|---|---|---|---|---|
| Llama-Prompt-Guard-2-22M | 0.9564 | 0.9888 | 0.9249 | 0.9558 | 0.9234 |
| Llama-Prompt-Guard-2-22M-q | 0.9579 | 0.9967 | 0.9204 | 0.9449 | 0.9180 |
| Llama-Prompt-Guard-2-86M | 0.9801 | 0.9984 | 0.9625 | 0.9801 | 0.9519 |
| Llama-Prompt-Guard-2-86M-q | 0.8989 | 1.0000 | 0.8018 | 0.89 | 0.7452 |
We use jackhhao/jailbreak-classification
for the evaluation
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification
import numpy as np
# Load model and tokenizer using optimum
model = ORTModelForSequenceClassification.from_pretrained("gravitee-io/Llama-Prompt-Guard-2-22M-onnx", file_name="model.quant.onnx")
tokenizer = AutoTokenizer.from_pretrained("gravitee-io/Llama-Prompt-Guard-2-22M-onnx")
# Tokenize input
text = "Your comment here"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
# Run inference
outputs = model(**inputs)
logits = outputs.logits
# Optional: convert to probabilities
probs = 1 / (1 + np.exp(-logits))
print(probs)
You can find and use the quantized ONNX model from the Hugging:xFace repository:
2 commits
Python
100.0%