Skip to content

Commit 99c14e1

Browse files
author
ssjia
committed
[ET-VK] Buckify parakeet
Add Buck build targets for the Parakeet runner in both fbcode and xplat environments. This includes: - New BUCK and targets.bzl files for the parakeet_runner and parakeet_utils targets - Platform-specific include guards for the unicode header, which is accessed via a different path in the Buck build vs. the OSS CMake build - A cast fix for encoder_subsampling_factor to suppress a compiler warning Differential Revision: [D95970164](https://our.internmc.facebook.com/intern/diff/D95970164/) ghstack-source-id: 349969162 Pull Request resolved: #18062
1 parent a23ed70 commit 99c14e1

4 files changed

Lines changed: 138 additions & 1 deletion

File tree

examples/models/parakeet/BUCK

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target", "non_fbcode_target")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
3+
load(":targets.bzl", "define_common_targets")
4+
5+
oncall("executorch")
6+
7+
# C++ targets shared between fbcode and xplat are defined in targets.bzl.
8+
9+
non_fbcode_target(_kind = define_common_targets,)
10+
11+
fbcode_target(_kind = define_common_targets,)
12+
13+
fbcode_target(_kind = runtime.python_library,
14+
name = "quantize",
15+
srcs = [
16+
"quantize.py",
17+
],
18+
_is_external_target = True,
19+
base_module = "executorch.examples.models.parakeet",
20+
visibility = ["//executorch/..."],
21+
deps = [
22+
"//executorch/extension/llm/export:export_lib",
23+
],
24+
)
25+
26+
fbcode_target(_kind = runtime.python_library,
27+
name = "export_library",
28+
srcs = [
29+
"export_parakeet_tdt.py",
30+
],
31+
_is_external_target = True,
32+
base_module = "executorch.examples.models.parakeet",
33+
visibility = ["//executorch/..."],
34+
deps = [
35+
":quantize",
36+
"//caffe2:torch",
37+
"fbsource//third-party/pypi/torchaudio:torchaudio",
38+
"//executorch/exir:lib",
39+
"//executorch/exir/passes:memory_planning_pass",
40+
"//executorch/runtime:runtime",
41+
# Backend deps (lazy imports per --backend flag)
42+
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
43+
"//executorch/backends/cuda:cuda_backend",
44+
"//executorch/backends/cuda:cuda_partitioner",
45+
"//executorch/backends/vulkan/partitioner:vulkan_partitioner",
46+
# Model loading deps
47+
"fbsource//third-party/pypi/nemo-toolkit:nemo-toolkit",
48+
"fbsource//third-party/pypi/huggingface-hub:huggingface-hub",
49+
# Transitive dep required by NeMo
50+
"fbsource//third-party/pypi/onnx:onnx",
51+
],
52+
)
53+
54+
fbcode_target(_kind = runtime.python_binary,
55+
name = "export_parakeet_tdt",
56+
main_function = "executorch.examples.models.parakeet.export_parakeet_tdt.main",
57+
preload_deps = [
58+
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
59+
"//executorch/kernels/quantized:aot_lib",
60+
],
61+
deps = [
62+
":export_library",
63+
"//caffe2:torch",
64+
"//executorch/extension/pybindings:aten_lib",
65+
],
66+
)

examples/models/parakeet/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#include <executorch/extension/llm/runner/stats.h>
3030
#include <executorch/extension/llm/runner/util.h>
3131
#include <executorch/extension/llm/runner/wav_loader.h>
32+
#ifdef EXECUTORCH_FB_BUCK
33+
#include <unicode.h>
34+
#else
3235
#include <executorch/extension/llm/tokenizers/third-party/llama.cpp-unicode/include/unicode.h>
36+
#endif
3337
#include <executorch/extension/module/module.h>
3438
#include <executorch/extension/tensor/tensor_ptr_maker.h>
3539
#include <executorch/runtime/core/evalue.h>
@@ -489,7 +493,7 @@ int main(int argc, char** argv) {
489493
static_cast<long long>(pred_hidden),
490494
static_cast<long long>(sample_rate),
491495
window_stride,
492-
encoder_subsampling_factor);
496+
static_cast<long long>(encoder_subsampling_factor));
493497

494498
ET_LOG(Info, "Running TDT greedy decode...");
495499
auto decoded_tokens = greedy_decode_executorch(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_aten_mode_options", "runtime")
2+
3+
def _get_operator_lib(aten = False):
4+
if aten:
5+
return ["//executorch/kernels/aten:generated_lib"]
6+
else:
7+
return [
8+
"//executorch/configurations:optimized_native_cpu_ops",
9+
"//executorch/extension/llm/custom_ops:custom_ops",
10+
]
11+
12+
def define_common_targets():
13+
for aten in get_aten_mode_options():
14+
aten_suffix = "_aten" if aten else ""
15+
16+
runtime.cxx_library(
17+
name = "parakeet_utils" + aten_suffix,
18+
srcs = [
19+
"timestamp_utils.cpp",
20+
"tokenizer_utils.cpp",
21+
],
22+
exported_headers = [
23+
"timestamp_utils.h",
24+
"tokenizer_utils.h",
25+
"types.h",
26+
],
27+
preprocessor_flags = [] if runtime.is_oss else ["-DEXECUTORCH_FB_BUCK"],
28+
visibility = ["PUBLIC"],
29+
exported_deps = [
30+
"//pytorch/tokenizers:headers",
31+
"//pytorch/tokenizers/third-party:unicode",
32+
"//executorch/runtime/platform:platform",
33+
],
34+
)
35+
36+
runtime.cxx_binary(
37+
name = "parakeet_runner" + aten_suffix,
38+
srcs = ["main.cpp"],
39+
compiler_flags = ["-Wno-global-constructors"],
40+
preprocessor_flags = [] if runtime.is_oss else ["-DEXECUTORCH_FB_BUCK"],
41+
deps = [
42+
":parakeet_utils" + aten_suffix,
43+
"//executorch/extension/llm/runner:stats" + aten_suffix,
44+
"//executorch/extension/llm/runner:runner_lib" + aten_suffix,
45+
"//executorch/extension/llm/runner:multimodal_runner_lib" + aten_suffix,
46+
"//executorch/extension/module:module" + aten_suffix,
47+
"//executorch/extension/tensor:tensor" + aten_suffix,
48+
"//executorch/runtime/core:evalue" + aten_suffix,
49+
"//executorch/runtime/core/exec_aten/util:scalar_type_util" + aten_suffix,
50+
"//executorch/runtime/platform:platform",
51+
"//pytorch/tokenizers:sentencepiece",
52+
"//executorch/backends/xnnpack:xnnpack_backend",
53+
"//executorch/backends/vulkan:vulkan_backend_lib",
54+
"//executorch/kernels/quantized:generated_lib" + aten_suffix,
55+
] + _get_operator_lib(aten),
56+
external_deps = [
57+
"gflags",
58+
] + (["libtorch"] if aten else []),
59+
)

examples/models/parakeet/tokenizer_utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
#include <exception>
44

5+
#ifdef EXECUTORCH_FB_BUCK
6+
#include <unicode.h>
7+
#else
58
#include <executorch/extension/llm/tokenizers/third-party/llama.cpp-unicode/include/unicode.h>
9+
#endif
610
#include <executorch/runtime/platform/log.h>
711
#include <pytorch/tokenizers/tokenizer.h>
812

@@ -36,7 +40,11 @@ bool is_special_token(const std::string& token) {
3640
if (token.rfind("##", 0) == 0) {
3741
return true;
3842
}
43+
#ifdef EXECUTORCH_FB_BUCK
44+
if (token.rfind("\xe2\x96\x81", 0) == 0) {
45+
#else
3946
if (token.rfind(u8"", 0) == 0) {
47+
#endif
4048
return true;
4149
}
4250
if (is_whitespace_only(token)) {

0 commit comments

Comments
 (0)