Skip to content

Commit 4ac3bd1

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
make bundled_executor_runner only for bp (#532)
Summary: Pull Request resolved: #532 bundled executor runner should only focus on bundled program. remove the support for normal ExecuTorch Program. Reviewed By: tarun292 Differential Revision: D49761307 fbshipit-source-id: 73edc68cede7b9a4b499dc0638703d62daf85821
1 parent c2e7bb0 commit 4ac3bd1

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

examples/bundled_executor_runner/bundled_executor_runner.cpp

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <executorch/runtime/platform/log.h>
2929
#include <executorch/runtime/platform/profiler.h>
3030
#include <executorch/runtime/platform/runtime.h>
31+
#include <executorch/schema/bundled_program_schema_generated.h>
3132
#include <executorch/util/bundled_program_verification.h>
3233
#include <executorch/util/util.h>
3334

@@ -36,19 +37,14 @@ static constexpr size_t kBundledAllocatorPoolSize = 16 * 1024U;
3637
static uint8_t bundled_allocator_pool[kBundledAllocatorPoolSize];
3738

3839
DEFINE_string(
39-
model_path,
40-
"model.pte",
40+
bundled_program_path,
41+
"model_bundled.bp",
4142
"Model serialized in flatbuffer format.");
4243
DEFINE_string(
4344
prof_result_path,
4445
"prof_result.bin",
4546
"ExecuTorch profiler output path.");
4647

47-
DEFINE_bool(
48-
bundled_program,
49-
false,
50-
"True for running bundled program, false for executorch_flatbuffer::program");
51-
5248
DEFINE_int32(
5349
testset_idx,
5450
0,
@@ -74,8 +70,8 @@ int main(int argc, char** argv) {
7470
// Create a loader to get the data of the program file. There are other
7571
// DataLoaders that use mmap() or point to data that's already in memory, and
7672
// users can create their own DataLoaders to load from arbitrary sources.
77-
const char* model_path = FLAGS_model_path.c_str();
78-
Result<FileDataLoader> loader = FileDataLoader::from(model_path);
73+
const char* bundled_program_path = FLAGS_bundled_program_path.c_str();
74+
Result<FileDataLoader> loader = FileDataLoader::from(bundled_program_path);
7975
ET_CHECK_MSG(
8076
loader.ok(), "FileDataLoader::from() failed: 0x%" PRIx32, loader.error());
8177

@@ -84,9 +80,16 @@ int main(int argc, char** argv) {
8480
ET_CHECK_MSG(
8581
file_data.ok(),
8682
"Could not load contents of file '%s': 0x%x",
87-
model_path,
83+
bundled_program_path,
8884
(unsigned int)file_data.error());
8985

86+
// Check whether the file is a bundled program.
87+
ET_CHECK_MSG(
88+
executorch_flatbuffer::BundledProgramBufferHasIdentifier(
89+
file_data->data()),
90+
"The file '%s' is not a bundled program.",
91+
bundled_program_path);
92+
9093
// Find the offset to the embedded Program.
9194
const void* program_data;
9295
size_t program_data_len;
@@ -98,7 +101,7 @@ int main(int argc, char** argv) {
98101
ET_CHECK_MSG(
99102
status == Error::Ok,
100103
"GetProgramData() failed on file '%s': 0x%x",
101-
model_path,
104+
bundled_program_path,
102105
(unsigned int)status);
103106

104107
auto buffer_data_loader =
@@ -108,10 +111,10 @@ int main(int argc, char** argv) {
108111
// between multiple execution invocations across multiple threads.
109112
Result<Program> program = Program::load(&buffer_data_loader);
110113
if (!program.ok()) {
111-
ET_LOG(Error, "Failed to parse model file %s", model_path);
114+
ET_LOG(Error, "Failed to parse model file %s", bundled_program_path);
112115
return 1;
113116
}
114-
ET_LOG(Info, "Model file %s is loaded.", model_path);
117+
ET_LOG(Info, "Model file %s is loaded.", bundled_program_path);
115118

116119
// Use the first method in the program.
117120
const char* method_name = nullptr;
@@ -198,22 +201,18 @@ int main(int argc, char** argv) {
198201
MemoryAllocator bundled_input_allocator{
199202
MemoryAllocator(kBundledAllocatorPoolSize, bundled_allocator_pool)};
200203
exec_aten::ArrayRef<void*> inputs;
201-
if (FLAGS_bundled_program) {
202-
// Use the inputs embedded in the bundled program.
203-
status = torch::executor::util::LoadBundledInput(
204-
*method,
205-
file_data->data(),
206-
&bundled_input_allocator,
207-
0, // Using the 0th indexed program
208-
FLAGS_testset_idx);
209-
ET_CHECK_MSG(
210-
status == Error::Ok,
211-
"LoadBundledInput failed with status 0x%" PRIx32,
212-
status);
213-
} else {
214-
// Use ones-initialized inputs.
215-
inputs = torch::executor::util::PrepareInputTensors(*method);
216-
}
204+
// Use the inputs embedded in the bundled program.
205+
status = torch::executor::util::LoadBundledInput(
206+
*method,
207+
file_data->data(),
208+
&bundled_input_allocator,
209+
method_name,
210+
FLAGS_testset_idx);
211+
ET_CHECK_MSG(
212+
status == Error::Ok,
213+
"LoadBundledInput failed with status 0x%" PRIx32,
214+
status);
215+
217216
ET_LOG(Info, "Inputs prepared.");
218217

219218
// Run the model.
@@ -249,24 +248,21 @@ int main(int argc, char** argv) {
249248
fclose(ptr);
250249
}
251250

252-
// Handle the outputs.
253-
if (FLAGS_bundled_program) {
254-
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
255-
*method,
256-
file_data->data(),
257-
&bundled_input_allocator,
258-
0,
259-
FLAGS_testset_idx,
260-
1e-5, // rtol
261-
1e-8 // atol
262-
);
263-
ET_CHECK_MSG(
264-
status == Error::Ok,
265-
"Bundle verification failed with status 0x%" PRIx32,
266-
status);
267-
ET_LOG(Info, "Model verified successfully.");
268-
} else {
269-
torch::executor::util::FreeInputs(inputs);
270-
}
251+
// Verify the outputs.
252+
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
253+
*method,
254+
file_data->data(),
255+
&bundled_input_allocator,
256+
method_name,
257+
FLAGS_testset_idx,
258+
1e-5, // rtol
259+
1e-8 // atol
260+
);
261+
ET_CHECK_MSG(
262+
status == Error::Ok,
263+
"Bundle verification failed with status 0x%" PRIx32,
264+
status);
265+
ET_LOG(Info, "Model verified successfully.");
266+
271267
return 0;
272268
}

examples/bundled_executor_runner/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def define_common_targets():
1919
"//executorch/runtime/executor:program",
2020
"//executorch/extension/data_loader:file_data_loader",
2121
"//executorch/extension/data_loader:buffer_data_loader",
22+
"//executorch/schema:bundled_program_schema",
2223
"//executorch/util:util",
2324
"//executorch/util:bundled_program_verification",
2425
],

schema/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def define_common_targets():
113113
visibility = [
114114
"//executorch/bundled_program/...",
115115
"//executorch/extension/pybindings/...",
116+
"//executorch/examples/bundled_executor_runner/...",
116117
"//executorch/util/...", # bundled_program_verification
117118
],
118119
exported_headers = {

0 commit comments

Comments
 (0)