Skip to content

Commit d757776

Browse files
authored
Add extension_llm_runner to CMake deps (#19749)
Differential Revision: D106162684 Pull Request resolved: #19749
1 parent 7d8063f commit d757776

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

examples/models/parakeet/main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ int main(int argc, char** argv) {
152152
ET_LOG(Error, "Preprocessing failed.");
153153
return 1;
154154
}
155-
auto mel_features = preprocess_result.get();
155+
auto preprocess_out = preprocess_result.get();
156156

157157
// --- Transcribe ---
158158
ET_LOG(Info, "Running TDT greedy decode...");
159-
auto result = runner.transcribe(mel_features, [](const std::string& piece) {
160-
std::cout << piece << std::flush;
161-
});
159+
auto result = runner.transcribe(
160+
preprocess_out.features,
161+
[](const std::string& piece) { std::cout << piece << std::flush; },
162+
preprocess_out.length);
162163

163164
if (!result.ok()) {
164165
ET_LOG(Error, "Transcription failed.");

extension/asr/runner/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif()
2222
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
2323

2424
set(runner_deps executorch_core extension_module extension_tensor
25-
tokenizers::tokenizers
25+
extension_llm_runner tokenizers::tokenizers
2626
)
2727

2828
# Define runner library

extension/asr/runner/transducer_runner.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Error TransducerRunner::load() {
200200
return Error::Ok;
201201
}
202202

203-
Result<::executorch::extension::TensorPtr> TransducerRunner::preprocess(
203+
Result<PreprocessResult> TransducerRunner::preprocess(
204204
::executorch::extension::TensorPtr raw_audio) {
205205
if (!is_loaded()) {
206206
ET_CHECK_OK_OR_RETURN_ERROR(load());
@@ -229,20 +229,28 @@ Result<::executorch::extension::TensorPtr> TransducerRunner::preprocess(
229229
"Preprocessor returned unexpected output.");
230230

231231
auto mel = outputs[0].toTensor();
232-
return std::make_shared<::executorch::aten::Tensor>(std::move(mel));
232+
int64_t mel_len = mel.sizes()[1]; // default to tensor dim
233+
if (outputs.size() >= 2 && outputs[1].isTensor()) {
234+
mel_len = outputs[1].toTensor().const_data_ptr<int64_t>()[0];
235+
}
236+
return PreprocessResult{
237+
std::make_shared<::executorch::aten::Tensor>(std::move(mel)), mel_len};
233238
}
234239

235240
Result<std::vector<Token>> TransducerRunner::transcribe(
236241
::executorch::extension::TensorPtr preprocessed_features,
237-
std::function<void(const std::string&)> token_callback) {
242+
std::function<void(const std::string&)> token_callback,
243+
int64_t features_length) {
238244
if (!is_loaded()) {
239245
ET_CHECK_OK_OR_RETURN_ERROR(load());
240246
}
241247

242248
stats_.inference_start_ms = ::executorch::extension::llm::time_in_ms();
243249

244250
// --- Encode ---
245-
int64_t mel_len_value = preprocessed_features->size(1);
251+
// Use provided length, or fall back to tensor dimension
252+
int64_t mel_len_value =
253+
features_length > 0 ? features_length : preprocessed_features->size(1);
246254
std::vector<int64_t> mel_len_data = {mel_len_value};
247255
auto mel_len = ::executorch::extension::from_blob(
248256
mel_len_data.data(), {1}, ::executorch::aten::ScalarType::Long);

extension/asr/runner/transducer_runner.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ using ::executorch::extension::llm::Stats;
2929
using ::executorch::runtime::Error;
3030
using ::executorch::runtime::Result;
3131

32+
/**
33+
* Preprocessed audio features with actual (unpadded) length.
34+
*/
35+
struct PreprocessResult {
36+
::executorch::extension::TensorPtr features;
37+
int64_t length; // Actual number of valid frames (excluding padding)
38+
};
39+
3240
/**
3341
* A decoded token with frame-level timing information.
3442
*/
@@ -97,7 +105,7 @@ class ET_EXPERIMENTAL TransducerRunner {
97105
* @returns Preprocessed features tensor (e.g., mel spectrogram),
98106
* ready to pass to transcribe().
99107
*/
100-
Result<::executorch::extension::TensorPtr> preprocess(
108+
Result<PreprocessResult> preprocess(
101109
::executorch::extension::TensorPtr raw_audio);
102110

103111
/**
@@ -112,7 +120,8 @@ class ET_EXPERIMENTAL TransducerRunner {
112120
*/
113121
Result<std::vector<Token>> transcribe(
114122
::executorch::extension::TensorPtr preprocessed_features,
115-
std::function<void(const std::string&)> token_callback = {});
123+
std::function<void(const std::string&)> token_callback = {},
124+
int64_t features_length = -1);
116125

117126
/**
118127
* Returns a reference to the loaded tokenizer, or nullptr if not loaded.

0 commit comments

Comments
 (0)