Skip to content

Commit c6a57b2

Browse files
authored
Merge pull request #2715 from pareenaverma/content_review
New Stability Audio LP with Executorch
2 parents be45887 + 62c0549 commit c6a57b2

7 files changed

Lines changed: 639 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: Set up your development environment
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
In this Learning Path, you will learn how to convert the Stable Audio Open Small model to ExecuTorch (.pte) format, then build an audio generation application to run on Android or macOS. ExecuTorch is a PyTorch framework designed for on-device inference on edge and mobile devices.
12+
13+
## Identify requirements
14+
15+
Before you begin, you need a development environment with the required software:
16+
17+
- An Android device with an Arm CPU supporting FEAT_DotProd (dotprod) and optionally FEAT_I8MM (i8mm), with at least 8 GB of RAM.
18+
- Python 3.10 or newer.
19+
- CMake version 3.16.0 or newer.
20+
- Android NDK r27c (if building for Android).
21+
22+
## Create workspace directory
23+
24+
Create a workspace directory to manage the dependencies and repositories.
25+
26+
Export the `WORKSPACE` variable to point to this directory:
27+
28+
```bash
29+
mkdir my-workspace
30+
export WORKSPACE=$PWD/my-workspace
31+
cd $WORKSPACE
32+
```
33+
34+
## Install Python 3.10
35+
36+
You need Python 3.10 or newer for compatibility with the required packages.
37+
38+
{{< tabpane code=true >}}
39+
{{< tab header="Linux">}}
40+
sudo apt install -y python3.10 python3.10-venv
41+
{{< /tab >}}
42+
{{< tab header="macOS">}}
43+
brew install python@3.10
44+
brew link python@3.10 --force
45+
{{< /tab >}}
46+
{{< /tabpane >}}
47+
48+
Verify the installation:
49+
50+
```console
51+
python3 --version
52+
```
53+
54+
The output is similar to:
55+
56+
```output
57+
Python 3.10.19
58+
```
59+
60+
## Install CMake
61+
62+
CMake automates the build process for the audio generation application.
63+
64+
{{< tabpane code=true >}}
65+
{{< tab header="Linux">}}
66+
sudo apt update
67+
sudo apt install cmake g++ git
68+
{{< /tab >}}
69+
{{< tab header="macOS">}}
70+
brew install cmake
71+
{{< /tab >}}
72+
{{< /tabpane >}}
73+
74+
Verify the installation:
75+
76+
```console
77+
cmake --version
78+
```
79+
80+
The output is similar to:
81+
82+
```output
83+
cmake version 4.2.1
84+
```
85+
86+
See the [CMake install guide](/install-guides/cmake/) for additional help.
87+
88+
## Clone the ML examples repository
89+
90+
Clone the Arm ML examples repository, which contains the scripts and application code:
91+
92+
```bash
93+
cd $WORKSPACE
94+
git clone https://github.com/Arm-Examples/ML-examples.git
95+
cd ML-examples/kleidiai-examples/audiogen-et/
96+
```
97+
98+
You now have the necessary tools and repository to proceed with model setup.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: Download the Stable Audio Open Small model
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## About the Stable Audio Open Small model
10+
11+
Stable Audio Open Small is an open-source model optimized for generating short audio samples, sound effects, and production elements using text prompts. The model consists of three main submodules:
12+
13+
- **Conditioners**: Include a T5-based text encoder for input prompts and a numerical duration encoder. These components encode the inputs into numerical values to be passed to the DiT model.
14+
- **Diffusion Transformer (DiT)**: Takes random noise and denoises it through multiple steps to produce structured latent audio, guided by conditioner embeddings.
15+
- **AutoEncoder**: Compresses input waveforms into a manageable sequence length for processing by the DiT model. At the end of the denoising step, it decompresses the result into a waveform.
16+
17+
You can learn more about [stable-audio-open-small on Hugging Face](https://huggingface.co/stabilityai/stable-audio-open-small).
18+
19+
## Download model files
20+
21+
[Log in](https://huggingface.co/login) to HuggingFace and navigate to the model landing page:
22+
23+
```url
24+
https://huggingface.co/stabilityai/stable-audio-open-small/tree/main
25+
```
26+
27+
You will need to fill out a form with your contact information to access the model.
28+
29+
Download the following files:
30+
- `model_config.json` (configuration file)
31+
- `model.ckpt` (model checkpoint)
32+
33+
Copy both files to your workspace directory.
34+
35+
Verify the files exist:
36+
37+
```bash
38+
ls $WORKSPACE/model_config.json
39+
ls $WORKSPACE/model.ckpt
40+
```
41+
42+
43+
## Understand prompt structure
44+
45+
A good prompt for Stable Audio Open Small includes:
46+
47+
- Music genre and subgenre
48+
- Musical elements (texture, rhythm, articulation)
49+
- Musical atmosphere (mood and emotion)
50+
- Tempo in beats per minute (BPM)
51+
52+
The order of prompt parameters matters. For example:
53+
54+
```text
55+
warm arpeggios on house beats 120BPM with drums effect
56+
```
57+
58+
For more information, see the [Prompt structure user guide](https://stableaudio.com/user-guide/prompt-structure).
59+
60+
You can explore additional training and inference code in the [Stable Audio Tools repository](https://github.com/Stability-AI/stable-audio-tools).
61+
62+
You now have the model files ready for conversion to ExecuTorch format.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: Convert the model to ExecuTorch format
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Create a virtual environment
10+
11+
Create and activate a Python virtual environment to manage dependencies. Python 3.10 is recommended for compatibility with the required packages:
12+
13+
```bash
14+
cd $WORKSPACE/ML-examples/kleidiai-examples/audiogen-et/
15+
python3.10 -m venv .venv
16+
source .venv/bin/activate
17+
```
18+
19+
## Install ExecuTorch
20+
21+
Install the ExecuTorch package version 1.0.0:
22+
23+
```bash
24+
pip install executorch==1.0.0
25+
```
26+
27+
Alternatively, you can clone the ExecuTorch repository and run the installation script:
28+
29+
```bash
30+
git clone https://github.com/pytorch/executorch.git
31+
cd executorch
32+
git checkout v1.0.0
33+
bash ./install_executorch.sh
34+
cd ..
35+
```
36+
37+
## Install Stable Audio tools
38+
39+
Install the Stable Audio Open tools dependency:
40+
41+
```bash
42+
pip install git+https://github.com/Stability-AI/stable-audio-tools.git@31932349d98c550c48711e7a5a40b24aa3d7c509
43+
```
44+
45+
## Export the model submodules
46+
47+
Now you can export the three model submodules to ExecuTorch format using the provided script.
48+
49+
Run the export script from the `audiogen-et` directory:
50+
51+
```bash
52+
python ./scripts/export_sao.py --ckpt_path $WORKSPACE/model.ckpt --model_config $WORKSPACE/model_config.json
53+
```
54+
55+
The script converts all three submodules (Conditioners, DiT, and AutoEncoder) and exports them to `.pte` files.
56+
57+
### Troubleshooting conversion issues
58+
59+
If you see a `FileNotFoundError` related to missing `.fbs` files during conversion:
60+
61+
```output
62+
FileNotFoundError: [Errno 2] No such file or directory: '../kleidiai-examples/audiogen-et/scripts/executorch/exir/_serialize/program.fbs'
63+
```
64+
65+
Run these commands to copy the required schema files:
66+
67+
```bash
68+
export EXECUTORCH_ROOT=<PATH-TO-EXECUTORCH>
69+
cp $EXECUTORCH_ROOT/schema/program.fbs $EXECUTORCH_ROOT/exir/_serialize/program.fbs
70+
cp $EXECUTORCH_ROOT/schema/scalar_type.fbs $EXECUTORCH_ROOT/exir/_serialize/scalar_type.fbs
71+
```
72+
73+
Then retry the export script.
74+
75+
## Verify exported models
76+
77+
After successful conversion, three `.pte` model files are created in the current directory:
78+
- `conditioners_model.pte`
79+
- `dit_model.pte`
80+
- `autoencoder_model.pte`
81+
82+
These files are required to run the audio generation application on Android or macOS.
83+
84+
Verify the files were created:
85+
86+
```bash
87+
ls -lh conditioners_model.pte dit_model.pte autoencoder_model.pte
88+
```
89+
90+
The files should be in `$WORKSPACE/ML-examples/kleidiai-examples/audiogen-et/`.
91+
92+
93+
In this section, you installed Executorch and the Stable Audio tools dependencies. You converted the three Stable Audio Open Small submodules to ExecuTorch format.
94+
95+
In the following sections, you will build the audio generation application for your target platform (Android or macOS).
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: Build and run on macOS
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
In this section, you will build and run the audio generation application on macOS. The application uses ExecuTorch with XNNPack and Arm KleidiAI for optimized inference on Arm CPUs.
12+
13+
## Set up the environment
14+
15+
Start a fresh virtual environment:
16+
17+
```bash
18+
cd $WORKSPACE/ML-examples/kleidiai-examples/audiogen-et/
19+
python3.10 -m venv new-venv
20+
source new-venv/bin/activate
21+
```
22+
23+
If you haven't already installed ExecuTorch, install it now:
24+
25+
```bash
26+
pip install executorch==1.0.0
27+
```
28+
29+
## Set model path
30+
31+
Set the `EXECUTORCH_MODELS_PATH` environment variable to the directory containing your exported ExecuTorch models:
32+
33+
```bash
34+
export EXECUTORCH_MODELS_PATH=$WORKSPACE/ML-examples/kleidiai-examples/audiogen-et
35+
```
36+
37+
This should be the directory where the `.pte` model files were created during the conversion step.
38+
39+
## Build the application
40+
41+
Navigate to the `app` directory and create a build directory:
42+
43+
```bash
44+
cd app
45+
mkdir build && cd build
46+
```
47+
48+
Run CMake to configure the build:
49+
50+
```bash
51+
cmake ..
52+
```
53+
54+
Build the application:
55+
56+
```bash
57+
make -j8
58+
```
59+
60+
The build process creates an `audiogen` executable in the `build` directory.
61+
62+
## Download the tokenizer model
63+
64+
The audio generation application uses a SentencePiece-based tokenizer. Download the `spiece.model` file from HuggingFace:
65+
66+
```bash
67+
curl -L https://huggingface.co/google-t5/t5-base/resolve/main/spiece.model -o $EXECUTORCH_MODELS_PATH/spiece.model
68+
```
69+
70+
Verify the file was downloaded:
71+
72+
```bash
73+
ls -lh $EXECUTORCH_MODELS_PATH/spiece.model
74+
```
75+
76+
## Run the application
77+
78+
Run the `audiogen` application with three required arguments:
79+
80+
- Model Path (`-m`): Directory containing your ExecuTorch models and `spiece.model` files
81+
- Prompt (`-p`): Text description of the desired audio
82+
- CPU Threads (`-t`): Number of CPU threads to use
83+
84+
Run the application with an example prompt:
85+
86+
```bash
87+
./audiogen -m $EXECUTORCH_MODELS_PATH -p "warm arpeggios on house beats 120BPM with drums effect" -t 4
88+
```
89+
90+
The application processes the prompt through the three model submodules and generates audio.
91+
92+
The output should look like:
93+
94+
```output
95+
I 00:00:00.002858 executorch:main.cpp:280] Resetting threadpool with num threads = 4
96+
I 00:00:00.003228 executorch:threadpool.cpp:48] Resetting threadpool to 4 threads.
97+
I 00:00:00.003543 executorch:main.cpp:288] Using 4 threads
98+
I 00:00:00.003620 executorch:main.cpp:294] Model (/Users/parver01/my-workspace/ML-examples/kleidiai-examples/audiogen-et/conditioners_model.pte) loaded
99+
I 00:00:00.003627 executorch:main.cpp:298] Model (/Users/parver01/my-workspace/ML-examples/kleidiai-examples/audiogen-et/dit_model.pte) loaded
100+
I 00:00:00.003629 executorch:main.cpp:302] Model (/Users/parver01/my-workspace/ML-examples/kleidiai-examples/audiogen-et/autoencoder_model.pte) loaded
101+
I 00:00:04.723761 executorch:main.cpp:478] Output saved to warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav
102+
I 00:00:04.723770 executorch:main.cpp:487] T5: 72 ms
103+
I 00:00:04.723771 executorch:main.cpp:488] DiT: 1474 ms
104+
I 00:00:04.723772 executorch:main.cpp:489] DiT Avg per step: 184.250000 ms
105+
I 00:00:04.723784 executorch:main.cpp:490] AutoEncoder: 3127 ms
106+
I 00:00:04.723785 executorch:main.cpp:491] Total execution time: 4673 ms
107+
```
108+
## Verify the output
109+
110+
If successful, the generated audio is saved as a `.wav` file in the current directory. The filename is based on the prompt text:
111+
112+
```bash
113+
ls -lh warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav
114+
```
115+
116+
You can play the audio file using any audio player on your macOS system:
117+
118+
```bash
119+
open warm_arpeggios_on_house_beats_120bpm_with_drums_effect_99.wav
120+
```
121+
122+
In this section:
123+
- You built the audio generation application for macOS
124+
- You downloaded the required tokenizer model
125+
- You generated audio from a text prompt using ExecuTorch
126+
- You verified the generated audio output
127+
128+
You can now experiment with different prompts to generate various audio samples. The application uses Arm KleidiAI optimizations to accelerate inference on Arm CPUs.
129+
130+
If you want to deploy to Android instead, proceed to the next section.

0 commit comments

Comments
 (0)