Abstract
This paper presents Llama Guard 3-1B-INT4, a compact and efficient Llama Guard model, which has been open-sourced to the community during Meta Connect 2024. We demonstrate that Llama Guard 3-1B-INT4 can be deployed on resource-constrained devices, achieving a throughput of at least 30 tokens per second and a time-to-first-token of 2.5 seconds or less on a commodity Android mobile CPU. Notably, our experiments show that Llama Guard 3-1B-INT4 attains comparable or superior safety moderation scores to its larger counterpart, Llama Guard 3-1B, despite being approximately 7 times smaller in size (440MB).
Introduction
As Generative AI shifts from large-scale data centers to on-device applications, maintaining safety standards is a critical requirement. Standard safety protocols involve pairing a generative Large Language Model (LLM) with a "guard" model to filter unsafe inputs and outputs. However, existing 1B-parameter guard models often exceed the memory (DRAM) limitations of mobile hardware, where operating systems frequently throttle or terminate applications with high memory footprints. To address this, Llama Guard 3-1B-INT4 was developed to provide a significantly smaller and faster safety solution without compromising the ability to detect nuanced policy violations.
Methods
The development of Llama Guard 3-1B-INT4 involved a multi-stage compression pipeline designed to shrink the Llama 3.2 1B model from its original 2.8GB size to a mobile-friendly 440MB.
- Pruning: The architecture was streamlined by reducing decoder blocks from 16 to 12 and narrowing the MLP hidden dimension. A sensitivity analysis using cosine similarity helped identify components with the lowest contribution to final performance.
- Quantization-Aware Training (QAT): Rather than post-training quantization, the model underwent fine-tuning with 4-bit per-channel weight quantization and 8-bit dynamic activation quantization integrated into the training loop.
- Unembedding Layer Pruning: Since Llama Guard only requires a small set of output tokens (e.g., "safe," "unsafe"), the output layer was pruned from 128,000 tokens to approximately 20, saving 131MB of space.
- Knowledge Distillation: To mitigate accuracy loss from compression, Llama Guard 3-8B served as a teacher model, guiding the smaller student model to replicate its output distributions.
- Deployment: The model is optimized for the ExecuTorch runtime using the XNNPACK backend, enabling efficient 4-bit inference on ARM CPUs.
Evaluation and Results
Performance was evaluated using an internal test dataset based on the MLCommons (2024) hazard taxonomy, comparing the INT4 model against Llama Guard 3-1B, 3-8B, and GPT-4.
Key Findings
- Efficiency: The model achieved a throughput of ≥ 30 tokens per second on a commodity Android mobile CPU (Moto-Razor), with a time-to-first-token of ≤ 2.5 seconds.
- Accuracy: Surprisingly, the 1B-INT4 model outperformed the uncompressed 1B model on English safety benchmarks. This suggests that the combination of distillation and QAT may serve as an effective form of regularization.
- Multilingual Performance: The model remained competitive in 5 out of 8 non-English languages and significantly outperformed zero-shot GPT-4 in safety moderation tasks across nearly all tested languages.
Conclusion
Llama Guard 3-1B-INT4 demonstrates that extreme model compression can be achieved without sacrificing safety performance. By leveraging task-specific optimizations like unembedding pruning and knowledge distillation, it is possible to bring robust AI safety to resource-constrained edge devices. Future work will focus on closing knowledge gaps in complex categories like Intellectual Property and enhancing resilience against sophisticated adversarial prompt injections.
Summary updated