Skip to content

Commit 78f884f

Browse files
Gasoonjiafacebook-github-bot
authored andcommitted
sdoc update (#422)
Summary: Pull Request resolved: #422 update static doc for bundled program api update Reviewed By: tarun292 Differential Revision: D49470936 fbshipit-source-id: db964e4ef4a43bff98cb845bacb40360bf232233
1 parent d9eef24 commit 78f884f

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

docs/website/docs/tutorials/bundled_program.md

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,36 @@ To execute the program on the bundled input, we need to load the bundled input i
7676
```c++
7777

7878
/**
79-
* Compare the execution plan's output with testset_idx-th bundled expected
80-
* output in plan_idx-th execution plan test.
79+
* Load testset_idx-th bundled input of method_idx-th Method test in
80+
* bundled_program_ptr to given Method.
8181
*
82-
* @param[in] plan The execution plan contains output.
82+
* @param[in] method The Method to verify.
8383
* @param[in] bundled_program_ptr The bundled program contains expected output.
84-
* @param[in] plan_idx The index of execution plan being verified.
85-
* @param[in] testset_idx The index of expected output needs to be compared.
86-
* @param[in] rtol Relative tolerance used for data comparsion.
87-
* @param[in] atol Absolute tolerance used for data comparsion.
84+
* @param[in] method_name The name of the Method being verified.
85+
* @param[in] testset_idx The index of input needs to be set into given Method.
8886
*
89-
* @returns Return Error::Ok if two outputs match, or the error happens during
87+
* @returns Return Error::Ok if load successfully, or the error happens during
9088
* execution.
9189
*/
9290
__ET_NODISCARD Error LoadBundledInput(
93-
ExecutionPlan& plan,
91+
Method& method,
9492
serialized_bundled_program* bundled_program_ptr,
95-
size_t plan_idx,
93+
MemoryAllocator* memory_allocator,
94+
const char* method_name,
9695
size_t testset_idx);
9796
```
9897
9998
### Verify the plan's output.
100-
We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify the plan's output with bundled expected outputs. Here's the details of this API:
99+
We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:
101100
102101
```c++
103102
/**
104-
* Compare the execution plan's output with testset_idx-th bundled expected
105-
* output in plan_idx-th execution plan test.
103+
* Compare the Method's output with testset_idx-th bundled expected
104+
* output in method_idx-th Method test.
106105
*
107-
* @param[in] plan The execution plan contains output.
106+
* @param[in] method The Method to extract outputs from.
108107
* @param[in] bundled_program_ptr The bundled program contains expected output.
109-
* @param[in] plan_idx The index of execution plan being verified.
108+
* @param[in] method_name The name of the Method being verified.
110109
* @param[in] testset_idx The index of expected output needs to be compared.
111110
* @param[in] rtol Relative tolerance used for data comparsion.
112111
* @param[in] atol Absolute tolerance used for data comparsion.
@@ -115,74 +114,62 @@ We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify
115114
* execution.
116115
*/
117116
__ET_NODISCARD Error VerifyResultWithBundledExpectedOutput(
118-
ExecutionPlan& plan,
117+
Method& method,
119118
serialized_bundled_program* bundled_program_ptr,
120-
size_t plan_idx,
119+
MemoryAllocator* memory_allocator,
120+
const char* method_name,
121121
size_t testset_idx,
122122
double rtol = 1e-5,
123123
double atol = 1e-8);
124+
124125
```
125126

126127
### Example
127128

128-
Here we provide an example about how to run the bundled program step by step. Most of the code are borrowed from "fbcode/executorch/sdk/runners/executor_runner.cpp":
129+
Here we provide an example about how to run the bundled program step by step. Most of the code are borrowed from "fbcode/executorch/sdk/runners/executor_runner.cpp" and please review that file if you need more info and context:
129130

130131
```c++
131-
// model path is the path to flatbuffer file.
132-
auto buff_ptr =
133-
torch::executor::util::read_file_content(model_path);
134-
135-
std::shared_ptr<char> buff_ptr;
136-
size_t buff_len;
137-
138-
// FILE_PATH here can be either BundledProgram or Program flatbuffer file.
139-
Error status = torch::executor::util::read_file_content(
140-
FILE_PATH, &buff_ptr, &buff_len);
141-
ET_CHECK_MSG(
142-
status == Error::Ok,
143-
"read_file_content() failed with status 0x%" PRIx32,
144-
status);
145-
146-
uint32_t prof_tok = EXECUTORCH_BEGIN_PROF("de-serialize model");
147-
148-
const void* program_ptr;
149-
size_t program_len;
150-
Error status = torch::executor::util::GetProgramData(
151-
buff_ptr.get(), buff_len, &program_ptr, &program_len);
152-
ET_CHECK_MSG(
153-
status == Error::Ok,
154-
"GetProgramData() failed with status 0x%" PRIx32,
155-
status);
156-
157-
const auto program = torch::executor::Program(program_ptr);
158-
132+
// method_name is the name for the method we want to test
159133
// memory_manager is the executor::MemoryManager variable for executor memory allocation.
160-
torch::executor::Executor executor(&program, &memory_manager);
161-
const auto plan_index = torch::executor::Program::kForwardMethodIndex;
162-
executor.init_execution_plan(plan_index);
134+
// program is the executorch program.
135+
Result<Method> method = program->load_method(method_name, &memory_manager);
136+
EXECUTORCH_END_PROF(prof_tok);
137+
ET_CHECK_MSG(
138+
method.ok(),
139+
"load_method() failed with status 0x%" PRIx32,
140+
method.error());
163141

164142
// Load testset_idx-th input in the buffer to plan
165143
status = torch::executor::util::LoadBundledInput(
166-
plan, file_data.get(), plan_index, FLAGS_testset_idx);
144+
*method,
145+
program_data.bundled_program_data(),
146+
&bundled_input_allocator,
147+
method_name,
148+
FLAGS_testset_idx);
149+
ET_CHECK_MSG(
150+
status == Error::Ok,
151+
"LoadBundledInput failed with status 0x%" PRIx32,
152+
status);
153+
154+
// Execute the plan
155+
status = method->execute();
167156
ET_CHECK_MSG(
168157
status == Error::Ok,
169-
"LoadBundledInput failed with status %" PRIu32,
158+
"method->execute() failed with status 0x%" PRIx32,
170159
status);
171160

172-
// Execute the plan
173-
plan.execute();
174-
175161
// Verify the result.
176162
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
177-
plan,
178-
file_data.get(),
179-
plan_index,
180-
FLAGS_testset_idx,
181-
FLAGS_rtol,
182-
FLAGS_atol);
183-
ET_CHECK_MSG(
184-
status == Error::Ok,
185-
"Bundle verification failed with status %" PRIu32,
186-
status);
163+
*method,
164+
program_data.bundled_program_data(),
165+
&bundled_input_allocator,
166+
method_name,
167+
FLAGS_testset_idx,
168+
FLAGS_rtol,
169+
FLAGS_atol);
170+
ET_CHECK_MSG(
171+
status == Error::Ok,
172+
"Bundle verification failed with status 0x%" PRIx32,
173+
status);
187174

188175
```

0 commit comments

Comments
 (0)