Skip to content

Commit 419427c

Browse files
Add parakeet to examples/models (pytorch#16349)
Specifically the parakeet-tdt-0.6b-v3 checkpoint For the most part this was pretty fast and easy. 90% of the time was just me catching up on how the parakeet model was structured and what the decode loop looks like. An even better solution would be to merge this runner with the one we use for whisper asr. Manually verified against no backend targeting (so Its kinda slow).
1 parent 850f154 commit 419427c

6 files changed

Lines changed: 1155 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
cmake_minimum_required(VERSION 3.24)
8+
project(parakeet_runner)
9+
10+
set(CMAKE_CXX_STANDARD 17)
11+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12+
13+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
14+
15+
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
16+
17+
# Let files say "include <executorch/path/to/header.h>"
18+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
19+
20+
# Need this for gflags
21+
set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags)
22+
find_package(gflags REQUIRED)
23+
24+
# Find executorch libraries
25+
list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..)
26+
find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH)
27+
executorch_target_link_options_shared_lib(executorch)
28+
29+
set(link_libraries executorch gflags)
30+
31+
# Common ops for all builds
32+
list(APPEND link_libraries optimized_native_cpu_ops_lib cpublas eigen_blas)
33+
executorch_target_link_options_shared_lib(optimized_native_cpu_ops_lib)
34+
35+
# CPU-only builds need quantized and custom ops
36+
if(NOT EXECUTORCH_BUILD_CUDA AND MSVC)
37+
list(APPEND link_libraries quantized_ops_lib custom_ops)
38+
executorch_target_link_options_shared_lib(quantized_ops_lib)
39+
executorch_target_link_options_shared_lib(custom_ops)
40+
endif()
41+
42+
# XNNPACK
43+
if(TARGET xnnpack_backend)
44+
set(xnnpack_backend_libs xnnpack_backend XNNPACK xnnpack-microkernels-prod)
45+
if(TARGET kleidiai)
46+
list(APPEND xnnpack_backend_libs kleidiai)
47+
endif()
48+
list(APPEND link_libraries ${xnnpack_backend_libs})
49+
executorch_target_link_options_shared_lib(xnnpack_backend)
50+
endif()
51+
52+
# Needed for cpuinfo where it uses android specific log lib
53+
if(ANDROID)
54+
list(APPEND link_libraries log)
55+
endif()
56+
57+
# Add the required ExecuTorch extensions
58+
list(
59+
APPEND
60+
link_libraries
61+
extension_llm_runner
62+
extension_module
63+
extension_data_loader
64+
extension_tensor
65+
extension_flat_tensor
66+
tokenizers::tokenizers
67+
)
68+
69+
# Link CUDA backend
70+
if(EXECUTORCH_BUILD_CUDA)
71+
find_package(CUDAToolkit REQUIRED)
72+
list(APPEND link_libraries aoti_cuda_backend)
73+
if(NOT MSVC)
74+
executorch_target_link_options_shared_lib(aoti_cuda_backend)
75+
endif()
76+
endif()
77+
78+
if(EXECUTORCH_BUILD_METAL)
79+
list(APPEND link_libraries metal_backend)
80+
executorch_target_link_options_shared_lib(metal_backend)
81+
endif()
82+
83+
add_executable(parakeet_runner main.cpp)
84+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
85+
target_link_options_gc_sections(parakeet_runner)
86+
if(NOT APPLE AND NOT MSVC)
87+
target_link_options(parakeet_runner PRIVATE "LINKER:-s")
88+
endif()
89+
endif()
90+
91+
target_include_directories(
92+
parakeet_runner PUBLIC ${_common_include_directories}
93+
)
94+
target_link_libraries(parakeet_runner PUBLIC ${link_libraries})
95+
target_compile_options(parakeet_runner PUBLIC ${_common_compile_options})
96+
97+
# On Windows, copy required DLLs to the executable directory
98+
if(MSVC AND EXECUTORCH_BUILD_CUDA)
99+
add_custom_command(
100+
TARGET parakeet_runner
101+
POST_BUILD
102+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:aoti_cuda_shims>
103+
$<TARGET_FILE_DIR:parakeet_runner>
104+
COMMENT "Copying aoti_cuda_shims.dll to parakeet_runner directory"
105+
)
106+
endif()
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "parakeet-base",
6+
"hidden": true,
7+
"binaryDir": "${sourceDir}/../../../cmake-out/examples/models/parakeet",
8+
"cacheVariables": {
9+
"CMAKE_BUILD_TYPE": "Release",
10+
"CMAKE_FIND_ROOT_PATH": "${sourceDir}/../../../cmake-out",
11+
"CMAKE_PREFIX_PATH": "${sourceDir}/../../../cmake-out"
12+
}
13+
},
14+
{
15+
"name": "parakeet-cpu",
16+
"displayName": "Parakeet runner (CPU)",
17+
"inherits": ["parakeet-base"]
18+
},
19+
{
20+
"name": "parakeet-cuda",
21+
"displayName": "Parakeet runner (CUDA)",
22+
"inherits": ["parakeet-base"],
23+
"cacheVariables": {
24+
"EXECUTORCH_BUILD_CUDA": "ON"
25+
},
26+
"condition": {
27+
"type": "inList",
28+
"string": "${hostSystemName}",
29+
"list": ["Linux", "Windows"]
30+
}
31+
},
32+
{
33+
"name": "parakeet-metal",
34+
"displayName": "Parakeet runner (Metal)",
35+
"inherits": ["parakeet-base"],
36+
"cacheVariables": {
37+
"EXECUTORCH_BUILD_METAL": "ON"
38+
},
39+
"condition": {
40+
"lhs": "${hostSystemName}",
41+
"type": "equals",
42+
"rhs": "Darwin"
43+
}
44+
}
45+
],
46+
"buildPresets": [
47+
{
48+
"name": "parakeet-cpu",
49+
"displayName": "Build Parakeet runner (CPU)",
50+
"configurePreset": "parakeet-cpu",
51+
"targets": ["parakeet_runner"]
52+
},
53+
{
54+
"name": "parakeet-cuda",
55+
"displayName": "Build Parakeet runner (CUDA)",
56+
"configurePreset": "parakeet-cuda",
57+
"targets": ["parakeet_runner"]
58+
},
59+
{
60+
"name": "parakeet-metal",
61+
"displayName": "Build Parakeet runner (Metal)",
62+
"configurePreset": "parakeet-metal",
63+
"targets": ["parakeet_runner"]
64+
}
65+
],
66+
"workflowPresets": [
67+
{
68+
"name": "parakeet-cpu",
69+
"displayName": "Configure and build Parakeet runner (CPU)",
70+
"steps": [
71+
{
72+
"type": "configure",
73+
"name": "parakeet-cpu"
74+
},
75+
{
76+
"type": "build",
77+
"name": "parakeet-cpu"
78+
}
79+
]
80+
},
81+
{
82+
"name": "parakeet-cuda",
83+
"displayName": "Configure and build Parakeet runner (CUDA)",
84+
"steps": [
85+
{
86+
"type": "configure",
87+
"name": "parakeet-cuda"
88+
},
89+
{
90+
"type": "build",
91+
"name": "parakeet-cuda"
92+
}
93+
]
94+
},
95+
{
96+
"name": "parakeet-metal",
97+
"displayName": "Configure and build Parakeet runner (Metal)",
98+
"steps": [
99+
{
100+
"type": "configure",
101+
"name": "parakeet-metal"
102+
},
103+
{
104+
"type": "build",
105+
"name": "parakeet-metal"
106+
}
107+
]
108+
}
109+
]
110+
}

‎examples/models/parakeet/README.md‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Parakeet TDT Export for ExecuTorch
2+
3+
Export [nvidia/parakeet-tdt-0.6b-v3](https://huggingface.co/nvidia/parakeet-tdt-0.6b-v3) speech recognition model to ExecuTorch.
4+
5+
## Installation
6+
7+
```bash
8+
pip install -r install_requirements.txt
9+
```
10+
11+
## Export
12+
13+
Export the model:
14+
```bash
15+
python export_parakeet_tdt.py
16+
```
17+
18+
Test transcription on an audio file and compare eager vs lowered results:
19+
```bash
20+
python export_parakeet_tdt.py --audio /path/to/audio.wav
21+
```
22+
23+
### Export Arguments
24+
25+
| Argument | Description |
26+
|----------|-------------|
27+
| `--output-dir` | Output directory for exports (default: `./parakeet_tdt_exports`) |
28+
| `--backend` | Backend for acceleration: `portable`, `xnnpack`, `cuda`, `cuda-windows` (default: `portable`) |
29+
| `--audio` | Path to audio file for transcription test |
30+
31+
**Note:** The preprocessor is always lowered with the portable backend regardless of the `--backend` setting.
32+
33+
## C++ Runner
34+
35+
### Building
36+
37+
First, build ExecuTorch with the LLM preset from the executorch root directory:
38+
39+
```bash
40+
cmake --workflow --preset llm-release
41+
```
42+
43+
Then build the parakeet runner:
44+
45+
```bash
46+
cd examples/models/parakeet
47+
cmake --workflow --preset parakeet-cpu
48+
```
49+
50+
Available presets:
51+
- `parakeet-cpu` - CPU-only build
52+
- `parakeet-cuda` - CUDA acceleration (Linux/Windows)
53+
- `parakeet-metal` - Metal acceleration (macOS)
54+
55+
### Running
56+
57+
From the executorch root directory:
58+
59+
```bash
60+
./cmake-out/examples/models/parakeet/parakeet_runner \
61+
--model_path examples/models/parakeet/parakeet_tdt_exports/parakeet_tdt.pte \
62+
--audio_path /path/to/audio.wav \
63+
--tokenizer_path examples/models/parakeet/tokenizer.model
64+
```
65+
66+
### Runner Arguments
67+
68+
| Argument | Description |
69+
|----------|-------------|
70+
| `--model_path` | Path to Parakeet model (.pte) |
71+
| `--audio_path` | Path to input audio file (.wav) |
72+
| `--tokenizer_path` | Path to tokenizer file (default: `tokenizer.json`) |
73+
| `--data_path` | Path to data file (.ptd) for delegate data (optional, required for CUDA) |

0 commit comments

Comments
 (0)