Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,74 +1,28 @@
---
title: Benchmark Gemma 4 LiteRT-LM prefill performance with KleidiAI and SME2 on macOS
description: Benchmark Gemma 4 prefill performance on macOS by comparing baseline and SME2-optimized XNNPACK paths in LiteRT-LM with KleidiAI.
title: Benchmark Gemma 4 CPU inference with KleidiAI and SME2
description: Benchmark Gemma 4 prefill and decode on macOS with LiteRT-LM and KleidiAI SME2 kernels, and compare results from two devices.

minutes_to_complete: 45
minutes_to_complete: 90

draft: true
draft: false
cascade:
draft: true
draft: false

who_is_this_for: This is an advanced topic for software developers and performance engineers who want a reproducible Gemma 4 prefill benchmark workflow using LiteRT-LM, KleidiAI, and XNNPACK on macOS.
who_is_this_for: Software developers and performance engineers evaluating Gemma 4 CPU inference with LiteRT-LM, KleidiAI, and XNNPACK on SME2 hardware.

learning_objectives:
- Create a workspace with pinned LiteRT-LM and KleidiAI versions.
- Create upstream-optimized and historical-baseline XNNPACK worktrees.
- Download a LiteRT-LM-compatible Gemma 4 model from Hugging Face.
- Compare baseline and upstream SME2 benchmark results.
- Build LiteRT-LM with baseline and optimized XNNPACK kernels
- Download and verify the Gemma 4 E2B LiteRT-LM model
- Measure prefill and decode throughput at one and four CPU threads
- Compare throughput and verify the accelerated operator

prerequisites:
- An SME2 device (macOS on Apple M4 is used in this Learning Path for demonstrative purposes)
- An [SME2-capable device](/learning-paths/cross-platform/multiplying-matrices-with-sme2/1-get-started/#devices), such as an M4-family Mac
- Git, Homebrew, and Xcode Command Line Tools
- At least 25 GB of free disk space for model files and local builds

# START generated_summary_faq
generated_summary_faq:
template_version: summary-faq-v3
generated_at: '2026-09-14T20:55:19Z'
generator: ai
ai_assisted: true
ai_review_required: true
model: gpt-5
prompt_template: summary-faq-v3
source_hash: 87d7867854c80eb5b1a520c8958d4251d51e5e33c98f4d7b1890431ca82cfe8b
summary_generated_at: '2026-09-14T20:55:19Z'
summary_source_hash: 87d7867854c80eb5b1a520c8958d4251d51e5e33c98f4d7b1890431ca82cfe8b
faq_generated_at: '2026-09-14T20:55:19Z'
faq_source_hash: 87d7867854c80eb5b1a520c8958d4251d51e5e33c98f4d7b1890431ca82cfe8b
summary: >-
You'll benchmark Gemma 4 prefill performance on macOS by comparing an upstream SME2-optimized
XNNPACK path with a historical baseline in LiteRT-LM and KleidiAI. First, you'll set up a workspace and
verify SME and SME2 availability. Then, you'll install Bazelisk and the Hugging Face Hub CLI, and download
a LiteRT-LM-compatible Gemma 4 E2B `.litertlm` model. You'll build both XNNPACK variants with
identical settings, then compare three-iteration results at one and four CPU threads.
faqs:
- question: How do I check that my device supports SME2 before running the benchmarks?
answer: >-
Run `uname -m` and the `sysctl` checks for `hw.optional.arm.FEAT_SME` and
`hw.optional.arm.FEAT_SME2`. Proceed when the architecture is `arm64` and both feature flags
report `1`.
- question: Which Gemma 4 model should I download?
answer: >-
Download the Gemma 4 E2B `.litertlm` model from Hugging
Face. Place it in the shared model directory at `$HOME/gemma4-prefill-bench/models`.
- question: How do I confirm that Bazel is the version expected by LiteRT-LM?
answer: >-
From the LiteRT-LM repository, check `.bazelversion` and run `bazelisk version`. Confirm that the Bazel version is `7.6.1`.
- question: Why should I create separate baseline and upstream XNNPACK trees?
answer: >-
You'll use separate trees to build and benchmark both variants with identical settings while
recording the exact repository revisions. This enables a clean side-by-side comparison through
the same LiteRT-LM entrypoint.
- question: What does the benchmark function run, and where are the results saved?
answer: >-
When you run the benchmark function, it builds the selected XNNPACK variant and runs
three-iteration prefill benchmarks at one and four CPU threads. Results are written under the
workspace results directory, so you can compare baseline and SME2-optimized runs.
# END generated_summary_faq

author: Annie Tallund

generate_summary_faq: false
generate_summary_faq: true
rerun_summary: false
rerun_faqs: false

Expand All @@ -91,10 +45,6 @@ further_reading:
title: Arm Scalable Matrix Extension introduction, part 1
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-scalable-matrix-extension-introduction
type: blog
- resource:
title: Arm Scalable Matrix Extension instructions, part 2
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-scalable-matrix-extension-introduction-p2
type: blog
- resource:
title: Arm SME2 introduction, part 4
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/part4-arm-sme2-introduction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
---
title: Install prerequisites on macOS and download Gemma 4
description: Install Bazelisk and the Hugging Face Hub CLI on macOS, then download the Gemma 4 LiteRT-LM model artifact for benchmarking.
description: Install the macOS build tools and verify the Gemma 4 E2B LiteRT-LM model used for both XNNPACK variants.
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Install Bazelisk and the Hugging Face Hub CLI
## Install prerequisites on macOS

Install the prerequisite software for the benchmark.

Install Bazelisk:
Install Xcode Command Line Tools if they are not already available:

```bash
brew install bazelisk
xcode-select --install
```

Install the Hugging Face Hub CLI:
Install Bazelisk:

```bash
python3 -m pip install -U huggingface_hub
brew install bazelisk
```

Confirm that LiteRT-LM pins Bazel `7.6.1`:
Install the Hugging Face Hub CLI in a virtual environment:

```bash
cd $HOME/gemma4-prefill-bench/LiteRT-LM
cat .bazelversion
bazelisk version
python3 -m venv "$HOME/gemma4-prefill-bench/.venv"
source "$HOME/gemma4-prefill-bench/.venv/bin/activate"
python3 -m pip install -U huggingface_hub
```

## Download Gemma 4 from Hugging Face

With the prerequisites installed, download the Gemma 4 E2B `.litertlm` model from Hugging Face.

Create a shared model directory in the workspace:

```bash
Expand All @@ -47,18 +43,17 @@ Download the CPU-compatible Gemma 4 E2B LiteRT-LM artifact:
```bash
hf download litert-community/gemma-4-E2B-it-litert-lm \
gemma-4-E2B-it.litertlm \
--revision 6b78abd019e61a1ca4cbe3b212d2c9ce8ff38a94 \
--local-dir models/gemma-4-E2B-it-litert-lm
```

The model repository is public. If Hugging Face asks for credentials, run
`hf auth login` and repeat the download.
If Hugging Face asks for credentials, run `hf auth login` and repeat the download.

Verify the downloaded file:

```bash
shasum -a 256 \
models/gemma-4-E2B-it-litert-lm/gemma-4-E2B-it.litertlm
ls -lh models/gemma-4-E2B-it-litert-lm/gemma-4-E2B-it.litertlm
```

The expected SHA-256 checksum is:
Expand All @@ -68,13 +63,8 @@ The expected SHA-256 checksum is:
```

{{% notice Note %}}
The file is about 2.6 GB. LiteRT-LM requires the `.litertlm` artifact. A
Transformers repository containing only `safetensors` files isn't a direct
replacement.
Download the `.litertlm` artifact used by LiteRT-LM; the file is about 2.6 GB.
{{% /notice %}}

## What you've accomplished and what's next

You've installed prerequisite software on your macOS device and downloaded Gemma 4 from Hugging Face.

Next, you'll build each XNNPACK variant and run the benchmark.
You've installed the build tools and verified the shared model artifact.
Next, build each XNNPACK variant and run the benchmark.
Loading
Loading