Llama-3.1-8B optimized for Arm-based Cloud CPU
A quantized version of meta-llama/Llama-3.1-8B for text generation, provided in ONNX for the ONNX Runtime GenAI runtime with INT4 weights, dynamic INT8 activations and INT8 embeddings, and optimized for Arm-based Cloud CPU systems.
Summary
This repository contains an Arm-optimized version of meta-llama/Llama-3.1-8B for text generation. The model is provided in ONNX for the ONNX Runtime GenAI runtime, targeting Cloud CPU systems.
The weights are quantized with GPTQ to 4-bit asymmetric per-group values (group size 32), activations are quantized to INT8 per-token dynamic, and the token-embedding table and LM head weights are kept in INT8. The composite scheme is labelled W4A8_dyn_emb_int8. The graph is packed for the ONNX Runtime GenAI runtime, which fuses attention into a single GroupQueryAttention operator and wires up the KV cache.
This version is intended to demonstrate efficient inference on Arm-based platforms while preserving the original model's intended behavior. Arm has evaluated this model on MMLU and measured performance on a representative evaluation target.
Note that this is the base (pretrained) checkpoint, not an instruction-tuned one. No chat template is applied and the model will not reliably follow chat-style instructions.
Key results
| Area | Result |
|---|---|
| Model format | ONNX |
| Target device class | Cloud CPU |
| Reference device | AWS Graviton G4 (Neoverse-V2, Linux Ubuntu 24.04.4 LTS) |
| Primary performance result | 11.57 tokens/sec decode, 2443.74 ms time to first token |
| Accuracy result | MMLU 65.01% |
| Size / memory result | 5410.05 MB model size (5.67x smaller than the FP32 baseline), peak memory 5634.72 MB |
Original model
| Field | Value |
|---|---|
| Original model | meta-llama/Llama-3.1-8B |
| Original source | Hugging Face |
| Original developer | Meta |
| Original model card | meta-llama/Llama-3.1-8B |
| Original license | Llama 3.1 Community License |
Model files
| File | Description |
|---|---|
model.onnx |
Arm-optimized INT4-weight model graph for deployment; weights ship in the model.onnx.data side-car |
example.py |
Minimal inference example |
pyproject.toml |
Pinned runtime dependencies for example.py, resolved with uv |
uv.lock |
Locked dependency resolution for pyproject.toml |
config.yaml |
Model I/O contract used by the example |
benchmarks/ |
FP32 baseline and Arm-optimized benchmark records |
Performance
Performance was measured on the reference configuration below. Results are intended to make the optimization reproducible but do not guarantee identical performance on every Arm-based system.
Reference configuration
| Field | Value |
|---|---|
| Device / platform | AWS Graviton G4 |
| Instance | c8g.12xlarge |
| CPU / accelerator | Neoverse-V2 (CPU execution backend) |
| OS | Linux, Ubuntu 24.04.4 LTS |
| Runtime | ONNX Runtime 1.26.0 |
| Backend / delegate | MLAS, KleidiAI |
| Batch size | 1 |
| Threads | 4 intra-op threads |
| Precision | INT4 weights, dynamic INT8 activations, INT8 embeddings and LM head (GPTQ, W4A8_dyn_emb_int8) |
| Runs | 10 warmup runs + 50 measured runs |
Benchmark workload: 128 prompt tokens, 60 generated tokens.
Performance results
| Metric | Original / baseline | Arm-optimized | Improvement |
|---|---|---|---|
| p50 latency | 28947.46 ms | 7640.80 ms | 3.79x faster |
| p90 latency | 29060.25 ms | 7664.59 ms | 3.79x faster |
| p99 latency | 29158.13 ms | 7707.41 ms | 3.78x faster |
| Time to first token | 6423.90 ms | 2443.74 ms | 2.63x faster |
| Decode throughput | 2.67 tokens/sec | 11.57 tokens/sec | 4.33x |
| Model load time | 15399.74 ms | 6774.83 ms | 2.27x faster |
| Model size | 30697.24 MB | 5410.05 MB | 5.67x smaller |
| Peak memory | 28891.88 MB | 5634.72 MB | 5.13x less |
| Average memory | 28891.64 MB | 5612.54 MB | 5.15x less |
Accuracy
Accuracy was evaluated using the same preprocessing, input resolution, and evaluation protocol described below. Where possible, the optimized model is compared against the original model under the same evaluation conditions.
Evaluation setup
| Field | Value |
|---|---|
| Dataset | MMLU |
| Split | 5-shot |
| Number of samples | 3990 |
| Metric(s) | MMLU accuracy |
| Evaluation runtime | ONNX Runtime 1.26.0 |
Accuracy results
| Metric | Original / baseline | Arm-optimized | Change |
|---|---|---|---|
| MMLU accuracy (5-shot) | 66.09% | 65.01% | -1.08 pp |
Accuracy was measured using the evaluation setup described above. Users should re-evaluate the model on their own data before production use.
Arm optimization approach
Arm optimized this model for efficient inference on Arm-based platforms using a hardware-aware conversion and validation flow.
For this release, Arm used:
| Optimization area | Applied? | Notes |
|---|---|---|
| Model conversion | Yes | Exported to ONNX in the ONNX Runtime GenAI graph layout |
| Quantization | Yes | GPTQ INT4 asymmetric per-group weights (group size 32) after a QuaRot R1+R2 rotation, dynamic INT8 per-token activations, and an INT8 token-embedding table and LM head; calibrated on 256 WikiText samples |
| Runtime/backend selection | Yes | ONNX Runtime CPU execution provider with MLAS and KleidiAI |
| Graph/runtime compatibility updates | Yes | Performed as part of the shared PT2E export pipeline, with ONNX-specific graph translation |
| Accuracy validation | Yes | Compared against the original model or published baseline |
| Performance validation | Yes | Measured on the reference Arm platform |
The goal of this process is to improve deployment characteristics such as latency, memory use, model size, and runtime compatibility while preserving the model's intended behavior. Detailed conversion scripts, calibration configuration, or backend-specific implementation details may be provided separately where appropriate.
Using this model
Install dependencies
Dependencies are declared in pyproject.toml, which ships with this repository. Resolve and install them into a local virtual environment with uv:
uv python install
uv sync --frozen
Run the example
uv run example.py
Expected input
| Property | Value |
|---|---|
| Input shape | [1, T], where T is the runtime sequence length (variable) |
| Input type | int64 token ids (input_ids) |
| Input range | Token ids in the vocabulary range, vocabulary size 128256 |
| Preprocessing | Tokenize the raw prompt with tokenizer.json, adding special tokens. No chat template is applied. position_ids is not an input; the ONNX Runtime GenAI graph derives positions internally, and KV-cache I/O is handled by the ONNX Runtime GenAI Generator. |
Expected output
| Property | Value |
|---|---|
| Output shape | One token id per generation step, streamed by the ONNX Runtime GenAI Generator |
| Output type | Token ids |
| Postprocessing | Decode with tokenizer.json; stop on the eos token or on max length |
Intended use
This model is intended for developers evaluating text-generation workloads on Arm-based platforms. It is suitable as a reference implementation for benchmarking, prototyping, and integration exploration.
Limitations
- Performance depends on the target device, runtime version, backend/delegate support, memory configuration, and system load.
- Accuracy was evaluated on MMLU, 5-shot, and may not generalize to all domains.
- This release preserves the original model's intended task and behavior, but users should validate it for their own application, data, and deployment environment.
- This repository is not a replacement for the original model documentation.
Additional notes
- The ONNX Runtime GenAI artifacts use the fixed names
model.onnx(graph) andmodel.onnx.data(external weights); the runtime requires the.datasidecar to sit alongsidemodel.onnx. - The exported graph is packed for the ONNX Runtime GenAI runtime: attention is fused into a single GroupQueryAttention operator, the KV cache is wired up by the runtime, and the INT4 weights are packed into MatMulNBits.
- A QuaRot R1+R2 rotation is baked into the weights before GPTQ: R1 on the residual stream and R2 on the per-head dimension.
- The k_quant_last recipe leaves the token-embedding table and the final LM head projection at INT8 instead of INT4. Those layers were kept at higher precision to keep accuracy within acceptable ranges.
- The published
genai_config.jsonclamps context_length and max_length to 4096 tokens so the runtime KV cache fits a bounded buffer. The checkpoint's native context is 131072 tokens; longer-context inference requires raising the clamp and re-allocating the KV buffer. - This is the base (pretrained) checkpoint, not instruction-tuned, and no chat template is applied.
example.pyuses few-shot prompting — three English to Spanish exemplars — to elicit task behavior from the base model. - MMLU is an auxiliary upstream measurement, evaluated with lm-evaluation-harness in the cloze (continuation log-likelihood) format, scoring the four answer letters as continuations of the 5-shot prompt, on 3990 questions (70 per subject across 57 subjects).
About this version
Original Model: meta-llama/Llama-3.1-8B by Meta - Repository
Optimization/conversion: Arm-Optimized version for execution on Arm-based platforms.
Converted/optimized by: Arm
License: The Original Model and the Optimized Model are subject to Llama 3.1 Community License.
This repository contains a converted or optimized version of the Original Model (the “Optimized Model”). The Original Model has been converted or optimized as described above for execution on Arm-based platforms.
No retraining or fine-tuning of the Original Model was performed as part of the conversion or optimization. The conversion or optimization was not intended to change the Original Model’s behavior or intended use.
Original Model and Documentation
For information about the Original Model, including its development, training data, intended uses, limitations and other relevant information, please refer to the Original Model repository. Information in that repository was provided by the original developer or other third parties and, unless expressly stated otherwise, has not been independently verified by Arm.
Licenses and Third-Party Terms
Use of the Original Model and the Optimized Model is subject to the applicable licenses, usage restrictions and other terms identified above and in the relevant repositories. Publication of the Optimized Model does not grant any rights beyond those provided under the applicable license terms.
You are responsible for reviewing those terms and ensuring that your use of the Original Model and the Optimized Model is permitted.
Purpose of this Release
The Optimized Model is provided as a reference implementation to demonstrate and evaluate execution and performance on Arm-based systems. It is not a production-ready or supported solution.
Arm’s publication of the Optimized Model does not constitute an endorsement or certification of the Original Model or a representation that the Optimized Model is suitable for production use or any particular purpose.
To the fullest extent permitted by applicable law (i) the Optimized Model is provided “as is.” Arm makes no representations or warranties that the Original Model, the Optimized Model or their outputs are accurate, safe, secure, non-infringing, legally compliant, suitable for production use or fit for any particular purpose; and (ii) Arm will not be liable for any loss or damage arising from or in connection with the Optimized Model, its use or its outputs.
You are responsible for independently evaluating the Optimized Model, its outputs and its suitability for your intended use, including compliance with applicable legal, regulatory, safety and security requirements.
Arm does not commit to provide ongoing support, maintenance or updates for the Optimized Model. Any use of or reliance on the Optimized Model or its outputs is at your own risk.
- Downloads last month
- 26
Model tree for Arm/llama-3-1-8b-base-onnx-genai-int4-kquantlast-emb-int8
Base model
meta-llama/Llama-3.1-8B