Skip to content

Commit d50c91a

Browse files
Songhao Jiafacebook-github-bot
authored andcommitted
update function doc to rst format for auto-gen (#823)
Summary: Update the documentation for function into rst format to make the documentation automatic generated from doc string in our codebase. Differential Revision: D50154620
1 parent 592ac12 commit d50c91a

File tree

5 files changed

+47
-128
lines changed

5 files changed

+47
-128
lines changed

bundled_program/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ def __init__(
9191
9292
expected_outputs: Expected outputs for inputs sharing same index. The size of
9393
expected_outputs should be the same as the size of inputs and provided method_names.
94+
95+
Returns:
96+
self
9497
"""
9598
BundledConfig._check_io_type(inputs)
9699
BundledConfig._check_io_type(expected_outputs)

bundled_program/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ def create_bundled_program(
271271
Args:
272272
program: The program to be bundled.
273273
bundled_config: The config to be bundled.
274+
275+
Returns: The `BundledProgram` variable contains given ExecuTorch program and test cases.
274276
"""
275277

276278
assert_valid_bundle(program, bundled_config)

bundled_program/serialize/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,30 @@ def convert_from_flatbuffer(program_flatbuffer: bytes) -> bytes:
7777
def serialize_from_bundled_program_to_flatbuffer(
7878
bundled_program: BundledProgram,
7979
) -> bytes:
80+
"""
81+
Serialize a BundledProgram into FlatBuffer binary format.
82+
83+
Args:
84+
bundled_program (BundledProgram): The `BundledProgram` variable to be serialized.
85+
86+
Returns:
87+
The serialized FlatBuffer binary data in bytes.
88+
"""
89+
8090
return convert_to_flatbuffer(
8191
serialize_from_bundled_program_to_json(bundled_program)
8292
)
8393

8494

8595
# from flatbuffer to general program
8696
def deserialize_from_flatbuffer_to_bundled_program(flatbuffer: bytes) -> BundledProgram:
97+
"""
98+
Deserialize a FlatBuffer binary format into a BundledProgram.
99+
100+
Args:
101+
flatbuffer (bytes): The FlatBuffer binary data in bytes.
102+
103+
Returns:
104+
A `BundledProgram` instance.
105+
"""
87106
return deserialize_from_json_to_bundled_program(convert_from_flatbuffer(flatbuffer))

docs/source/Doxyfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ INPUT = ../runtime/executor/memory_manager.h \
965965
../runtime/core/tensor_shape_dynamism.h \
966966
../runtime/platform/compiler.h \
967967
../runtime/executor/ \
968-
../runtime/platform/
968+
../runtime/platform/ \
969+
../util/
969970

970971

971972

docs/source/sdk-bundled-io.md

Lines changed: 21 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,21 @@ ExecuTorch Program can be emitted from user's model by using ExecuTorch APIs. [H
2424

2525
`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`:
2626

27-
```python
28-
class BundledConfig (method_names, inputs, expected_outputs)
27+
```{eval-rst}
28+
.. autofunction:: bundled_program.config.BundledConfig.__init__
29+
:noindex:
2930
```
3031

31-
__Parameters:__
32-
- 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 for all methods. Each list
34-
of `inputs` is all 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 and ET runtime apis support setting input
38-
other than torch.tensor type, only the input in 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-
5032
### Step 3: Generate `BundledProgram`
5133

5234
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:
5335

54-
```python
55-
def create_bundled_program(program, bundled_config)
36+
```{eval-rst}
37+
.. currentmodule:: bundled_program.core
38+
.. autofunction:: create_bundled_program
39+
:noindex:
5640
```
5741

58-
__Parameters:__
59-
- 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-
6842
`create_bundled_program` will do sannity check internally to see if the given BundledConfig matches the given Program's requirements. Specifically:
6943
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.
7044
2. The metadata of each testcase should meet the requirement of the coresponding inference methods input.
@@ -74,37 +48,18 @@ __Return type:__
7448
To serialize `BundledProgram` to make runtime APIs use it, we provide two APIs, both under `executorch/bundled_program/serialize/__init__.py`.
7549

7650

77-
```python
78-
def serialize_from_bundled_program_to_flatbuffer(bundled_program)
51+
```{eval-rst}
52+
.. currentmodule:: bundled_program.serialize
53+
.. autofunction:: serialize_from_bundled_program_to_flatbuffer
54+
:noindex:
7955
```
8056

81-
Serialize `BundledProgram` to flatbuffer:
82-
83-
__Parameters:__
84-
- bundled_program (_BundledProgram_): The `BundledProgram` variable to be serialized
85-
86-
__Returns:__
87-
- Serialized `BundledProgram` in bytes
88-
89-
__Return type:__
90-
- _bytes_
91-
92-
93-
```python
94-
def deserialize_from_flatbuffer_to_bundled_program(flatbuffer)
57+
```{eval-rst}
58+
.. currentmodule:: bundled_program.serialize
59+
.. autofunction:: deserialize_from_flatbuffer_to_bundled_program
60+
:noindex:
9561
```
9662

97-
Deserialize flatbuffer to BundledProgram:
98-
99-
__Parameters:__
100-
- 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-
10863
### Emit Example
10964

11065
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,11 @@ This stage mainly focuses on executing the model with the bundled inputs and and
231186

232187
### Get ExecuTorch Program Pointer from `BundledProgram` Buffer
233188
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:
234-
```c++
235189

236-
Error GetProgramData(
237-
void* file_data,
238-
size_t file_data_len,
239-
const void** out_program_data,
240-
size_t* out_program_data_len);
190+
```{eval-rst}
191+
.. doxygenfunction:: torch::executor::util::GetProgramData
241192
```
242193

243-
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-
261194
Here's an example of how to use the `GetProgramData` API:
262195
```c++
263196
std::shared_ptr<char> buff_ptr;
@@ -284,55 +217,16 @@ ET_CHECK_MSG(
284217
### Load Bundled Input to Method
285218
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`:
286219
287-
```c++
288-
__ET_NODISCARD Error LoadBundledInput(
289-
Method& method,
290-
serialized_bundled_program* bundled_program_ptr,
291-
MemoryAllocator* memory_allocator,
292-
const char* method_name,
293-
size_t testset_idx);
220+
```{eval-rst}
221+
.. doxygenfunction:: torch::executor::util::LoadBundledInput
294222
```
295223

296-
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-
309224
### Verify the Method's Output.
310225
We call `torch::executor::util::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:
311226

312-
```c++
313-
__ET_NODISCARD Error VerifyResultWithBundledExpectedOutput(
314-
Method& method,
315-
serialized_bundled_program* bundled_program_ptr,
316-
MemoryAllocator* memory_allocator,
317-
const char* method_name,
318-
size_t testset_idx,
319-
double rtol = 1e-5,
320-
double atol = 1e-8);
227+
```{eval-rst}
228+
.. doxygenfunction:: torch::executor::util::VerifyResultWithBundledExpectedOutput
321229
```
322-
Compare the Method's output with testset_idx-th bundled expected
323-
output in method_idx-th Method test.
324-
325-
__Parameters:__
326-
- @param[in] method The Method to extract outputs from.
327-
- @param[in] bundled_program_ptr The bundled program contains expected output.
328-
- @param[in] method_name The name of the Method being verified.
329-
- @param[in] testset_idx The index of expected output to be compared.
330-
- @param[in] rtol Relative tolerance used for data comparsion.
331-
- @param[in] atol Absolute tolerance used for data comparsion.
332-
333-
__Returns:__
334-
- Return Error::Ok if two outputs match, or the error happens during
335-
execution.
336230

337231

338232
### Runtime Example

0 commit comments

Comments
 (0)