You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -24,47 +24,21 @@ ExecuTorch Program can be emitted from user's model by using ExecuTorch APIs. [H
24
24
25
25
`BundledConfig` is a class under `executorch/bundled_program/config.py` that contains all information to be bundled for model verification. Here's the constructor api to create `BundledConfig`:
- method_names (_List[str]_): All names of Methods to be verified in the program.
33
-
- inputs (_List[List[List[Union[torch.Tensor, int, float, bool]]]]_): All sets of input to be tested on forall methods. Each list
34
-
of `inputs`isall sets which will be run on the method in the
35
-
program with corresponding method name. Each set of any`inputs` element should contain all inputs required by Method with the same inference method name in ExecuTorch program for one-time execution.
36
-
37
-
It is worth mentioning that, although both bundled program andET runtime apis support setting input
38
-
other than torch.tensor type, only the inputin torch.tensor type will be actually updated in
39
-
the program, and the rest of the inputs will just do a sanity check if they match the default value in method.
40
-
41
-
- expected_outputs (_List[List[List[torch.Tensor]]]_): Expected outputs for inputs sharing same index. The size of
42
-
expected_outputs should be the same as the size of inputs and provided method_names.
43
-
44
-
__Returns:__
45
-
-self
46
-
47
-
__Return type:__
48
-
- BundledConfig
49
-
50
32
### Step 3: Generate `BundledProgram`
51
33
52
34
We provide `create_bundled_program` API under `executorch/bundled_program/core.py` to generate `BundledProgram` by bundling the emitted ExecuTorch program with the bundled_config:
- program (_Program_): The ExecuTorch program to be bundled.
60
-
- bundled_config (_BundledConfig_): The config to be bundled.
61
-
62
-
__Returns:__
63
-
- The `BundledProgram` variable contains given ExecuTorch program and test cases.
64
-
65
-
__Return type:__
66
-
-`BundledProgram`
67
-
68
42
`create_bundled_program` will do sannity check internally to see if the given BundledConfig matches the given Program's requirements. Specifically:
69
43
1. The name of methods we create BundledConfig for should be also in program. Please notice that it is no need to set testcases for every method in the Program.
70
44
2. The metadata of each testcase should meet the requirement of the coresponding inference methods input.
@@ -74,37 +48,18 @@ __Return type:__
74
48
To serialize `BundledProgram` to make runtime APIs use it, we provide two APIs, both under `executorch/bundled_program/serialize/__init__.py`.
- flatbuffer (_bytes_): The serialized `BundledProgram` in bytes to be deserialized.
101
-
102
-
__Returns:__
103
-
- The deserialized original `BundledProgram` variable, contains same information as input flatbuffer.
104
-
105
-
__Return type:__
106
-
-`BundledProgram`
107
-
108
63
### Emit Example
109
64
110
65
Here is a flow highlighting how to generate a `BundledProgram` given a PyTorch model and the representative inputs we want to test it along with.
@@ -231,33 +186,13 @@ This stage mainly focuses on executing the model with the bundled inputs and and
231
186
232
187
### Get ExecuTorch Program Pointer from `BundledProgram` Buffer
233
188
We need the pointer to ExecuTorch program to do the execution. To unify the process of loading and executing `BundledProgram` and Program flatbuffer, we create an API:
Finds the serialized ExecuTorch program data in the provided bundled program
244
-
file data.
245
-
246
-
The returned buffer is appropriate for constructing a
247
-
torch::executor::Program.
248
-
249
-
__Parameters:__
250
-
- @param[in] file_data The contents of an ExecuTorch program or bundled program
251
-
file.
252
-
- @param[in] file_data_len The length of file_data, in bytes.
253
-
- @param[out] out_program_data The serialized Program data, if found.
254
-
- @param[out] out_program_data_len The length of out_program_data, in bytes.
255
-
256
-
#### Returns
257
-
- Error::Ok if the given file is bundled program, a program was found
258
-
in it, and out_program_data/out_program_data_len point to the data. Other
259
-
values on failure.
260
-
261
196
Here's an example of how to use the `GetProgramData` API:
262
197
```c++
263
198
std::shared_ptr<char> buff_ptr;
@@ -284,55 +219,20 @@ ET_CHECK_MSG(
284
219
### Load Bundled Input to Method
285
220
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `torch::executor::util::LoadBundledInput`:
Load testset_idx-th bundled input of method_idx-th Method test in
297
-
bundled_program_ptr to given Method.
298
-
299
-
__Parameters:__
300
-
- @param[in] method The Method to verify.
301
-
- @param[in] bundled_program_ptr The bundled program contains expected output.
302
-
- @param[in] method_name The name of the Method being verified.
303
-
- @param[in] testset_idx The index of input to be set into given Method.
304
-
305
-
__Returns:__
306
-
- Return Error::Ok if load successfully, or the error happens during
307
-
execution.
308
-
309
228
### Verify the Method's Output.
310
229
We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:
0 commit comments