Skip to content

Commit de718e6

Browse files
Add documentation. (#5611)
Add documentation. (#5562) Summary: https://docs-preview.pytorch.org/pytorch/executorch/5562/extension-tensor.html Pull Request resolved: #5562 Reviewed By: mergennachin Differential Revision: D63286312 fbshipit-source-id: c4192d7c1af2dd7b559eaa1ce3550f34e64918e4 (cherry picked from commit 99ee547) Co-authored-by: Anthony Shoumikhin <[email protected]>
1 parent 8d16c52 commit de718e6

File tree

3 files changed

+449
-6
lines changed

3 files changed

+449
-6
lines changed

docs/source/extension-module.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ In the [Running an ExecuTorch Model in C++ Tutorial](running-a-model-cpp-tutoria
66

77
## Example
88

9-
Let's see how we can run the `SimpleConv` model generated from the [Exporting to ExecuTorch tutorial](./tutorials/export-to-executorch-tutorial) using the `Module` APIs:
9+
Let's see how we can run the `SimpleConv` model generated from the [Exporting to ExecuTorch tutorial](./tutorials/export-to-executorch-tutorial) using the `Module` and [`TensorPtr`](extension-tensor.md) APIs:
1010

1111
```cpp
1212
#include <executorch/extension/module/module.h>
13+
#include <executorch/extension/tensor/tensor.h>
1314

14-
using namespace ::torch::executor;
15+
using namespace ::executorch::extension;
1516

1617
// Create a Module.
1718
Module module("/path/to/model.pte");
1819

1920
// Wrap the input data with a Tensor.
2021
float input[1 * 3 * 256 * 256];
21-
Tensor::SizesType sizes[] = {1, 3, 256, 256};
22-
TensorImpl tensor(ScalarType::Float, std::size(sizes), sizes, input);
22+
auto tensor = from_blob(input, {1, 3, 256, 256});
2323

2424
// Perform an inference.
25-
const auto result = module.forward(Tensor(&tensor));
25+
const auto result = module.forward(tensor);
2626

2727
// Check for success or failure.
2828
if (result.ok()) {
@@ -62,6 +62,14 @@ assert(module.is_method_loaded("forward"));
6262
```
6363
Note: the `Program` is loaded automatically before any `Method` is loaded. Subsequent attemps to load them have no effect if one of the previous attemps was successful.
6464

65+
You can also force-load the "forward" method with a convenience syntax:
66+
67+
```cpp
68+
const auto error = module.load_forward();
69+
70+
assert(module.is_method_loaded("forward"));
71+
```
72+
6573
### Querying for Metadata
6674

6775
Get a set of method names that a Module contains udsing the `method_names()` function:
@@ -131,10 +139,11 @@ Use [ExecuTorch Dump](sdk-etdump.md) to trace model execution. Create an instanc
131139
```cpp
132140
#include <fstream>
133141
#include <memory>
142+
134143
#include <executorch/extension/module/module.h>
135144
#include <executorch/devtools/etdump/etdump_flatcc.h>
136145

137-
using namespace ::torch::executor;
146+
using namespace ::executorch::extension;
138147

139148
Module module("/path/to/model.pte", Module::LoadMode::MmapUseMlock, std::make_unique<ETDumpGen>());
140149

0 commit comments

Comments
 (0)