Skip to content

Commit ce131c7

Browse files
authored
Merge pull request #1987 from NinaARM/documentation-updates
Documentation updates - add macOS build instructions
2 parents c8b69f9 + 12a963f commit ce131c7

File tree

7 files changed

+136
-36
lines changed

7 files changed

+136
-36
lines changed

assets/contributors.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ Yiyang Fan,Arm,,,,
8585
Julien Jayat,Arm,,,,
8686
Geremy Cohen,Arm,geremyCohen,geremyinanutshell,,
8787
Barbara Corriero,Arm,,,,
88-
Nina Drozd,Arm,,ninadrozd,,
88+
Nina Drozd,Arm,NinaARM,ninadrozd,,
8989
Jun He,Arm,JunHe77,jun-he-91969822,,
90+
Gian Marco Iodice,Arm,,,,
91+
Aude Vuilliomenet,Arm,,,,

content/learning-paths/mobile-graphics-and-gaming/run-stable-audio-open-small-with-lite-rt/1-prerequisites.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Your first task is to prepare a development environment with the required softwa
1515
- Android NDK: version r25b or newer.
1616
- Python: version 3.10 or newer (tested with 3.10).
1717
- CMake: version 3.16.0 or newer (tested with 3.28.1).
18-
- [Arm GNU Toolchain](/install-guides/gcc/arm-gnu).
1918

2019
### Create workspace directory
2120

@@ -79,14 +78,26 @@ Bazel is an open-source build tool which you will use to build LiteRT libraries.
7978
{{< tabpane code=true >}}
8079
{{< tab header="Linux">}}
8180
cd $WORKSPACE
82-
wget https://github.com/bazelbuild/bazel/releases/download/7.4.1/bazel-7.4.1-installer-linux-x86_64.sh
81+
export BAZEL_VERSION=7.4.1
82+
wget https://github.com/bazelbuild/bazel/releases/download/{$BAZEL_VERSION}/bazel-{$BAZEL_VERSION}-installer-linux-x86_64.sh
8383
sudo bash bazel-7.4.1-installer-linux-x86_64.sh
84+
export PATH="/usr/local/bin:$PATH"
8485
{{< /tab >}}
8586
{{< tab header="MacOS">}}
86-
brew install bazel@7
87+
cd $WORKSPACE
88+
export BAZEL_VERSION=7.4.1
89+
curl -fLO "https://github.com/bazelbuild/bazel/releases/download/{$BAZEL_VERSION}/bazel-{$BAZEL_VERSION}-installer-darwin-arm64.sh"
90+
sudo bash bazel-7.4.1-installer-darwin-arm64.sh
91+
export PATH="/usr/local/bin:$PATH"
8792
{{< /tab >}}
8893
{{< /tabpane >}}
8994

95+
You can verify the installation and check the version with:
96+
97+
```console
98+
bazel --version
99+
```
100+
90101
### Install Android NDK
91102

92103
To run the model on Android, install Android Native Development Kit (Android NDK):
@@ -98,9 +109,9 @@ wget https://dl.google.com/android/repository/android-ndk-r25b-linux.zip
98109
unzip android-ndk-r25b-linux.zip
99110
{{< /tab >}}
100111
{{< tab header="MacOS">}}
112+
cd $WORKSPACE
101113
wget https://dl.google.com/android/repository/android-ndk-r25b-darwin.zip
102-
unzip android-ndk-r25b-darwin
103-
mv android-ndk-r25b-darwin ~/Library/Android/android-ndk-r25b
114+
unzip android-ndk-r25b-darwin.zip
104115
{{< /tab >}}
105116
{{< /tabpane >}}
106117

@@ -109,12 +120,13 @@ For easier access and execution of Android NDK tools, add these to the `PATH` an
109120
{{< tabpane code=true >}}
110121
{{< tab header="Linux">}}
111122
export NDK_PATH=$WORKSPACE/android-ndk-r25b/
123+
export ANDROID_NDK_HOME=$NDK_PATH
112124
export PATH=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
113125
{{< /tab >}}
114126
{{< tab header="MacOS">}}
115-
export NDK_PATH=~/Library/Android/android-ndk-r25b
116-
export PATH=$PATH:$NDK_PATH/toolchains/llvm/prebuilt/darwin-x86_64/bin
117-
export PATH=$PATH:~/Library/Android/sdk/cmdline-tools/latest/bin
127+
export NDK_PATH=$WORKSPACE/android-ndk-r25b/
128+
export ANDROID_NDK_HOME=$NDK_PATH
129+
export PATH=$NDK_PATH/toolchains/llvm/prebuilt/darwin-x86_64/bin/:$PATH
118130
{{< /tab >}}
119131
{{< /tabpane >}}
120132

content/learning-paths/mobile-graphics-and-gaming/run-stable-audio-open-small-with-lite-rt/3-converting-model.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,28 @@ In this section, you will explore two different conversion routes, to convert th
2424

2525
1. **ONNX to LiteRT**: using the `onnx2tf` tool. This is the traditional two-step approach (PyTorch -> ONNX -> LiteRT). You will use it to convert the Conditioners submodule.
2626

27-
2. **PyTorch to LiteRT**: using the Google AI Edge Torch tool. You will use this tool to convert the DiT and AutoEncoder submodules.
27+
2. **PyTorch to LiteRT**: using the [Google AI Edge Torch](https://developers.googleblog.com/en/ai-edge-torch-high-performance-inference-of-pytorch-models-on-mobile-devices/) tool. You will use this tool to convert the DiT and AutoEncoder submodules.
2828

2929

30-
## Download the sample code
31-
32-
The Conditioners submodule is made of the T5Encoder model. You will use the ONNX to TFLite conversion for this submodule.
30+
## Create a virtual environment
3331

3432
To avoid dependency issues, create a virtual environment. For example, you can use the following command:
3533

3634
```bash
3735
cd $WORKSPACE
38-
python3.10 -m venv env
39-
source env/bin/activate
36+
python3.10 -m venv .venv
37+
source .venv/bin/activate
4038
```
4139

42-
Clone the examples repository:
40+
## Clone the examples repository
4341

4442
```bash
4543
cd $WORKSPACE
4644
git clone https://github.com/ARM-software/ML-examples.git
4745
cd ML-examples/kleidiai-examples/audiogen/
4846
```
4947

50-
Install the required Python packages for this, including *onnx2tf* and *ai_edge_litert*
48+
## Install the required dependencies
5149

5250
```bash
5351
bash install_requirements.sh
@@ -58,13 +56,13 @@ bash install_requirements.sh
5856
If you are using GPU on your machine, you may notice the following error:
5957
```text
6058
Traceback (most recent call last):
61-
File "$WORKSPACE/env/lib/python3.10/site-packages/torch/_inductor/runtime/hints.py",
59+
File "$WORKSPACE/.venv/lib/python3.10/site-packages/torch/_inductor/runtime/hints.py",
6260
line 46, in <module> from triton.backends.compiler import AttrsDescriptor
6361
ImportError: cannot import name 'AttrsDescriptor' from 'triton.backends.compiler'
64-
($WORKSPACE/env/lib/python3.10/site-packages/triton/backends/compiler.py)
62+
($WORKSPACE/.venv/lib/python3.10/site-packages/triton/backends/compiler.py)
6563
.
6664
ImportError: cannot import name 'AttrsDescriptor' from 'triton.compiler.compiler'
67-
($WORKSPACE/env/lib/python3.10/site-packages/triton/compiler/compiler.py)
65+
($WORKSPACE/.venv/lib/python3.10/site-packages/triton/compiler/compiler.py)
6866
```
6967

7068
Reinstall the following dependency:
@@ -89,13 +87,14 @@ You can use the provided script to convert the Conditioners submodule:
8987
python3 ./scripts/export_conditioners.py --model_config "$WORKSPACE/model_config.json" --ckpt_path "$WORKSPACE/model.ckpt"
9088
```
9189

92-
After successful conversion, you now have a `tflite_conditioners` directory containing models with different precision (e.g., float16, float32).
90+
91+
After successful conversion, you now have a `conditioners_tflite` directory containing models with different precisions (e.g., float16, float32).
9392

9493
You will be using the float32.tflite model for on-device inference.
9594

96-
### Convert DiT and AutoEncoder
95+
### Convert DiT and AutoEncoder Submodules
9796

98-
To convert the DiT and AutoEncoder submodules, use the [Generative API](https://github.com/google-ai-edge/ai-edge-torch/tree/main/ai_edge_torch/generative/) provided by the ai-edge-torch tools. This enables you to export a generative PyTorch model directly to `.tflite` using three main steps:
97+
To convert the DiT and AutoEncoder submodules, use the [Generative API](https://github.com/google-ai-edge/ai-edge-torch/tree/main/ai_edge_torch/generative/) provided by the `ai-edge-torch` tools. This enables you to export a generative PyTorch model directly to `.tflite` using three main steps:
9998

10099
1. Model re-authoring.
101100
2. Quantization.

content/learning-paths/mobile-graphics-and-gaming/run-stable-audio-open-small-with-lite-rt/4-building-litert.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ Ensure the `NDK_PATH` variable is set to your previously installed Android NDK:
3333
{{< tabpane code=true >}}
3434
{{< tab header="Linux">}}
3535
export NDK_PATH=$WORKSPACE/android-ndk-r25b/
36+
export ANDROID_NDK_HOME=$NDK_PATH
3637
export PATH=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
3738
{{< /tab >}}
3839
{{< tab header="MacOS">}}
39-
export NDK_PATH=~/Library/Android/android-ndk-r25b
40-
export PATH=$PATH:$NDK_PATH/toolchains/llvm/prebuilt/darwin-x86_64/bin
40+
export NDK_PATH=$WORKSPACE/android-ndk-r25b/
41+
export ANDROID_NDK_HOME=$NDK_PATH
42+
export PATH=$NDK_PATH/toolchains/llvm/prebuilt/darwin-x86_64/bin/:$PATH
4143
{{< /tab >}}
4244
{{< /tabpane >}}
4345
{{% /notice %}}
@@ -54,6 +56,7 @@ python3 ./configure.py
5456
|Please input the desired Python library path to use[$WORKSPACE/lib/python3.10/site-packages] | Enter |
5557
|Do you wish to build TensorFlow with ROCm support? [y/N]|N (No)|
5658
|Do you wish to build TensorFlow with CUDA support?|N|
59+
|Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]:| Enter |
5760
|Do you want to use Clang to build TensorFlow? [Y/n]|N|
5861
|Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]|y (Yes) |
5962
|Please specify the home path of the Android NDK to use. [Default is /home/user/Android/Sdk/ndk-bundle]| Enter |
@@ -63,15 +66,24 @@ python3 ./configure.py
6366
|Please specify an Android build tools version to use. [Default is 35.0.0]| Enter |
6467
|Do you wish to build TensorFlow with iOS support? [y/N]:| n |
6568

66-
Once the Bazel configuration is complete, you can build TFLite as follows:
69+
Once the Bazel configuration is complete, you can build LiteRT for your target platform as follows:
6770

68-
```console
71+
{{< tabpane code=true >}}
72+
{{< tab header="Android">}}
6973
bazel build -c opt --config android_arm64 //tensorflow/lite:libtensorflowlite.so \
7074
--define tflite_with_xnnpack=true \
7175
--define=xnn_enable_arm_i8mm=true \
7276
--define tflite_with_xnnpack_qs8=true \
7377
--define tflite_with_xnnpack_qu8=true
74-
```
78+
{{< /tab >}}
79+
{{< tab header="MacOS">}}
80+
bazel build -c opt --config macos //tensorflow/lite:libtensorflowlite.so \
81+
--define tflite_with_xnnpack=true \
82+
--define xnn_enable_arm_i8mm=true \
83+
--define tflite_with_xnnpack_qs8=true \
84+
--define tflite_with_xnnpack_qu8=true
85+
{{< /tab >}}
86+
{{< /tabpane >}}
7587

7688
The final step is to build flatbuffers used by the application:
7789
```
@@ -81,7 +93,7 @@ cmake ../tensorflow/lite/tools/cmake/native_tools/flatbuffers
8193
cmake --build .
8294
```
8395

84-
Now that LiteRT and FlatBuffers are built, you're ready to compile and deploy the Stable Audio Open Small inference application on your Android device.
96+
Now that LiteRT and FlatBuffers are built, you're ready to compile and deploy the Stable Audio Open Small inference application on your Android or macOS device.
8597

8698

8799

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Create a simple program
2+
title: Create a simple program for Android target
33
weight: 6
44

55
### FIXED, DO NOT MODIFY
@@ -36,7 +36,7 @@ A SentencePiece model is a type of subword tokenizer which is used by the audiog
3636

3737
```bash
3838
cd $WORKSPACE
39-
wget https://huggingface.co/google-t5/t5-base/tree/main
39+
wget https://huggingface.co/google-t5/t5-base/resolve/main/spiece.model
4040
```
4141

4242
Verify this model was downloaded to your `WORKSPACE`.
@@ -76,7 +76,13 @@ Start a new shell to access the device's system from your development machine:
7676
adb shell
7777
```
7878

79-
Finally, run the program on your Android device. Play around with the advice from [Download the model](../2-testing-model) section.
79+
From there, you can then run the audiogen application, which requires just three input arguments:
80+
81+
* **Model Path:** The directory containing your LiteRT models and spiece.model files
82+
* **Prompt:** A text description of the desired audio (e.g., warm arpeggios on house beats 120BPM with drums effect)
83+
* **CPU Threads:** The number of CPU threads to use (e.g., 4)
84+
85+
Play around with the advice from [Download and test the model](../2-testing-model) section.
8086

8187
```bash
8288
cd /data/local/tmp/app
@@ -90,4 +96,4 @@ You can now pull the generated `output.wav` back to your host machine and listen
9096
adb pull /data/local/tmp/app/output.wav
9197
```
9298

93-
You should now have gained hands-on experience running the Stable Audio Open Small model with LiteRT on Arm-based devices. This includes setting up the environment, optimizing the model for on-device inference, and understanding how efficient runtimes like LiteRT make low-latency generative AI possible at the edge. You’re now better equipped to explore and deploy AI-powered audio applications on mobile and embedded platforms.
99+
You should now have gained hands-on experience running the Stable Audio Open Small model with LiteRT on Arm-based devices. This includes setting up the environment, optimizing the model for on-device inference, and understanding how efficient runtimes like LiteRT make low-latency generative AI possible at the edge. You’re now better equipped to explore and deploy AI-powered audio applications on mobile and embedded platforms.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Create a simple program for macOS target
3+
weight: 7
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Create and build a simple program
10+
11+
As a final step, you’ll build a simple program that runs inference on all three submodules directly on a macOS device.
12+
13+
The program takes a text prompt as input and generates an audio file as output.
14+
15+
```bash
16+
cd $WORKSPACE/ML-examples/kleidiai-examples/audiogen/app
17+
mkdir build && cd build
18+
```
19+
20+
Ensure the NDK path is set correctly and build with `cmake`:
21+
22+
```bash
23+
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
24+
-DTF_INCLUDE_PATH=$TF_SRC_PATH \
25+
-DTF_LIB_PATH=$TF_SRC_PATH/bazel-bin/tensorflow/lite \
26+
-DFLATBUFFER_INCLUDE_PATH=$TF_SRC_PATH/flatc-native-build/flatbuffers/include \
27+
..
28+
29+
make -j
30+
```
31+
After the example application builds successfully, a binary file named `audiogen` is created.
32+
33+
A SentencePiece model is a type of subword tokenizer which is used by the audiogen application, you’ll need to download the *spiece.model* file from:
34+
35+
```bash
36+
cd $LITERT_MODELS_PATH
37+
wget https://huggingface.co/google-t5/t5-base/resolve/main/spiece.model
38+
```
39+
40+
Verify this model was downloaded to your `WORKSPACE`.
41+
42+
```text
43+
ls $LITERT_MODELS_PATH/spiece.model
44+
```
45+
46+
Copy the shared LiteRT dynamic library to the $LITERT_MODELS_PATH.
47+
```bash
48+
cp $TF_SRC_PATH/bazel-bin/tensorflow/lite/libtensorflowlite.so $LITERT_MODELS_PATH/
49+
```
50+
51+
From there, you can then run the audiogen application, which requires just three input arguments:
52+
53+
* **Model Path:** The directory containing your LiteRT models and spiece.model files
54+
* **Prompt:** A text description of the desired audio (e.g., warm arpeggios on house beats 120BPM with drums effect)
55+
* **CPU Threads:** The number of CPU threads to use (e.g., 4)
56+
57+
Play around with the advice from [Download and test the model](../2-testing-model) section.
58+
59+
```bash
60+
cd $WORKSPACE/ML-examples/kleidiai-examples/audiogen/app/
61+
./build/audiogen $LITERT_MODELS_PATH "warm arpeggios on house beats 120BPM with drums effect" 4
62+
```
63+
64+
You can now check the generated `output.wav` and listen to the result.
65+
66+
You should now have gained hands-on experience running the Stable Audio Open Small model with LiteRT on Arm-based devices. This includes setting up the environment, optimizing the model for on-device inference, and understanding how efficient runtimes like LiteRT make low-latency generative AI possible at the edge. You’re now better equipped to explore and deploy AI-powered audio applications on mobile and embedded platforms.

content/learning-paths/mobile-graphics-and-gaming/run-stable-audio-open-small-with-lite-rt/_index.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Generate audio with Stable Audio Open Small on LiteRT
33

44
minutes_to_complete: 30
55

6-
who_is_this_for: This is an introductory topic for developers looking to deploy the Stable Audio Open Small text-to-audio model using LiteRT on an Android device.
6+
who_is_this_for: This is an introductory topic for developers looking to deploy the Stable Audio Open Small text-to-audio model using LiteRT on an Android device or on a reasonably modern platform with macOS®.
77

88
learning_objectives:
99
- Download and test the Stable Audio Open Small model.
@@ -19,6 +19,9 @@ prerequisites:
1919

2020
author:
2121
- Nina Drozd
22+
- Gian Marco Iodice
23+
- Adnan AlSinan
24+
- Aude Vuilliomenet
2225
- Annie Tallund
2326

2427
### Tags
@@ -42,8 +45,8 @@ further_reading:
4245
link: https://stability.ai/news/stability-ai-and-arm-release-stable-audio-open-small-enabling-real-world-deployment-for-on-device-audio-control
4346
type: blog
4447
- resource:
45-
title: Stability AI optimized its audio generation model to run on Arm chips
46-
link: https://techcrunch.com/2025/03/03/stability-ai-optimized-its-audio-generation-model-to-run-on-arm-chips/
48+
title: "Unlocking audio generation on Arm CPUs to all: Running Stable Audio Open Small with KleidiAI"
49+
link: https://community.arm.com/arm-community-blogs/b/ai-blog/posts/audio-generation-arm-cpus-stable-audio-open-small-kleidiai
4750
type: blog
4851
- resource:
4952
title: Fast Text-to-Audio Generation with Adversarial Post-Training

0 commit comments

Comments
 (0)