Skip to content

Commit 1e7be61

Browse files
dbortfacebook-github-bot
authored andcommitted
Update docs to stop referring to old namespaces (#6084)
Summary: Audit all instances of `\bexec_aten::` and `\btorch::` under `docs/`, updating where appropriate. The only remaining `torch::` instances are for kernels, which I didn't get a chance to migrate before v0.4.0. Also update the LLM Manual code to be consistent between the doc and main.cpp. Reviewed By: mergennachin Differential Revision: D64152344
1 parent e28cb76 commit 1e7be61

File tree

10 files changed

+155
-148
lines changed

10 files changed

+155
-148
lines changed

docs/source/Doxyfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ WARN_LOGFILE =
943943
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
944944
# Note: If this tag is empty the current directory is searched.
945945

946-
INPUT = ../runtime/executor/memory_manager.h \
946+
INPUT = ../devtools/bundled_program/bundled_program.h \
947+
../runtime/executor/memory_manager.h \
947948
../runtime/executor/method.h \
948949
../runtime/executor/method_meta.h \
949950
../runtime/executor/program.h \

docs/source/build-run-coreml.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ libsqlite3.tbd
147147

148148
7. Update the code to load the program from the Application's bundle.
149149
``` objective-c
150-
using namespace torch::executor;
151-
152150
NSURL *model_url = [NBundle.mainBundle URLForResource:@"mv3_coreml_all" extension:@"pte"];
153151

154-
Result<util::FileDataLoader> loader = util::FileDataLoader::from(model_url.path.UTF8String);
152+
Result<executorch::extension::FileDataLoader> loader =
153+
executorch::extension::FileDataLoader::from(model_url.path.UTF8String);
155154
```
156155
157156
8. Use [Xcode](https://developer.apple.com/documentation/xcode/building-and-running-an-app#Build-run-and-debug-your-app) to deploy the application on the device.

docs/source/bundled-io.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,51 +201,51 @@ This stage mainly focuses on executing the model with the bundled inputs and and
201201
### Get ExecuTorch Program Pointer from `BundledProgram` Buffer
202202
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:
203203

204-
:::{dropdown} `GetProgramData`
204+
:::{dropdown} `get_program_data`
205205

206206
```{eval-rst}
207-
.. doxygenfunction:: torch::executor::bundled_program::GetProgramData
207+
.. doxygenfunction:: ::executorch::bundled_program::get_program_data
208208
```
209209
:::
210210

211-
Here's an example of how to use the `GetProgramData` API:
211+
Here's an example of how to use the `get_program_data` API:
212212
```c++
213213
// Assume that the user has read the contents of the file into file_data using
214214
// whatever method works best for their application. The file could contain
215215
// either BundledProgram data or Program data.
216216
void* file_data = ...;
217217
size_t file_data_len = ...;
218218

219-
// If file_data contains a BundledProgram, GetProgramData() will return a
219+
// If file_data contains a BundledProgram, get_program_data() will return a
220220
// pointer to the Program data embedded inside it. Otherwise it will return
221221
// file_data, which already pointed to Program data.
222222
const void* program_ptr;
223223
size_t program_len;
224-
status = torch::executor::bundled_program::GetProgramData(
224+
status = executorch::bundled_program::get_program_data(
225225
file_data, file_data_len, &program_ptr, &program_len);
226226
ET_CHECK_MSG(
227227
status == Error::Ok,
228-
"GetProgramData() failed with status 0x%" PRIx32,
228+
"get_program_data() failed with status 0x%" PRIx32,
229229
status);
230230
```
231231
232232
### Load Bundled Input to Method
233-
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::bundled_program::LoadBundledInput`:
233+
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `executorch::bundled_program::load_bundled_input`:
234234
235-
:::{dropdown} `LoadBundledInput`
235+
:::{dropdown} `load_bundled_input`
236236
237237
```{eval-rst}
238-
.. doxygenfunction:: torch::executor::bundled_program::LoadBundledInput
238+
.. doxygenfunction:: ::executorch::bundled_program::load_bundled_input
239239
```
240240
:::
241241

242242
### Verify the Method's Output.
243-
We call `torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput` to verify the method's output with bundled expected outputs. Here's the details of this API:
243+
We call `executorch::bundled_program::verify_method_outputs` to verify the method's output with bundled expected outputs. Here's the details of this API:
244244

245-
:::{dropdown} `VerifyResultWithBundledExpectedOutput`
245+
:::{dropdown} `verify_method_outputs`
246246

247247
```{eval-rst}
248-
.. doxygenfunction:: torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput
248+
.. doxygenfunction:: ::executorch::bundled_program::verify_method_outputs
249249
```
250250
:::
251251

@@ -266,13 +266,13 @@ ET_CHECK_MSG(
266266
method.error());
267267

268268
// Load testset_idx-th input in the buffer to plan
269-
status = torch::executor::bundled_program::LoadBundledInput(
269+
status = executorch::bundled_program::load_bundled_input(
270270
*method,
271271
program_data.bundled_program_data(),
272272
FLAGS_testset_idx);
273273
ET_CHECK_MSG(
274274
status == Error::Ok,
275-
"LoadBundledInput failed with status 0x%" PRIx32,
275+
"load_bundled_input failed with status 0x%" PRIx32,
276276
status);
277277

278278
// Execute the plan
@@ -283,7 +283,7 @@ ET_CHECK_MSG(
283283
status);
284284

285285
// Verify the result.
286-
status = torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput(
286+
status = executorch::bundled_program::verify_method_outputs(
287287
*method,
288288
program_data.bundled_program_data(),
289289
FLAGS_testset_idx,

docs/source/concepts.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The goal of ATen dialect is to capture users’ programs as faithfully as possib
2626

2727
## ATen mode
2828

29-
ATen mode uses the ATen implementation of Tensor (`at::Tensor`) and related types, such as `ScalarType`, from the PyTorch core. This is in contrast to portable mode, which uses ExecuTorch’s smaller implementation of tensor (`torch::executor::Tensor`) and related types, such as `torch::executor::ScalarType`.
29+
ATen mode uses the ATen implementation of Tensor (`at::Tensor`) and related types, such as `ScalarType`, from the PyTorch core. This is in contrast to ETensor mode, which uses ExecuTorch’s smaller implementation of tensor (`executorch::runtime::etensor::Tensor`) and related types, such as `executorch::runtime::etensor::ScalarType`.
3030
- ATen kernels that rely on the full `at::Tensor` API are usable in this configuration.
3131
- ATen kernels tend to do dynamic memory allocation and often have extra flexibility (and thus overhead) to handle cases not needed by mobile/embedded clients. e.g., CUDA support, sparse tensor support, and dtype promotion.
3232
- Note: ATen mode is currently a WIP.
@@ -244,10 +244,10 @@ Kernels that support a subset of tensor dtypes and/or dim orders.
244244

245245
Parts of a model may be delegated to run on an optimized backend. The partitioner splits the graph into the appropriate sub-networks and tags them for delegation.
246246

247-
## Portable mode (lean mode)
247+
## ETensor mode
248248

249-
Portable mode uses ExecuTorch’s smaller implementation of tensor (`torch::executor::Tensor`) along with related types (`torch::executor::ScalarType`, etc.). This is in contrast to ATen mode, which uses the ATen implementation of Tensor (`at::Tensor`) and related types (`ScalarType`, etc.)
250-
- `torch::executor::Tensor`, also known as ETensor, is a source-compatible subset of `at::Tensor`. Code written against ETensor can build against `at::Tensor`.
249+
ETensor mode uses ExecuTorch’s smaller implementation of tensor (`executorch::runtime::etensor::Tensor`) along with related types (`executorch::runtime::etensor::ScalarType`, etc.). This is in contrast to ATen mode, which uses the ATen implementation of Tensor (`at::Tensor`) and related types (`ScalarType`, etc.)
250+
- `executorch::runtime::etensor::Tensor`, also known as ETensor, is a source-compatible subset of `at::Tensor`. Code written against ETensor can build against `at::Tensor`.
251251
- ETensor does not own or allocate memory on its own. To support dynamic shapes, kernels can allocate Tensor data using the MemoryAllocator provided by the client.
252252

253253
## Portable kernels

docs/source/etdump.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Generating an ETDump is a relatively straightforward process. Users can follow t
1515
2. ***Create*** an Instance of the ETDumpGen class and pass it into the `load_method` call that is invoked in the runtime.
1616

1717
```C++
18-
torch::executor::ETDumpGen etdump_gen = torch::executor::ETDumpGen();
18+
executorch::etdump::ETDumpGen etdump_gen;
1919
Result<Method> method =
2020
program->load_method(method_name, &memory_manager, &etdump_gen);
2121
```

docs/source/executorch-runtime-api-reference.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ For detailed information on how APIs evolve and the deprecation process, please
1111
Model Loading and Execution
1212
---------------------------
1313

14-
.. doxygenclass:: executorch::runtime::DataLoader
14+
.. doxygenclass:: executorch::runtime::Program
1515
:members:
1616

17-
.. doxygenclass:: executorch::runtime::MemoryAllocator
17+
.. doxygenclass:: executorch::runtime::Method
1818
:members:
1919

20-
.. doxygenclass:: executorch::runtime::HierarchicalAllocator
20+
.. doxygenclass:: executorch::runtime::MethodMeta
2121
:members:
2222

23-
.. doxygenclass:: executorch::runtime::MemoryManager
23+
.. doxygenclass:: executorch::runtime::DataLoader
2424
:members:
2525

26-
.. doxygenclass:: executorch::runtime::Program
26+
.. doxygenclass:: executorch::runtime::MemoryAllocator
2727
:members:
2828

29-
.. doxygenclass:: executorch::runtime::Method
29+
.. doxygenclass:: executorch::runtime::HierarchicalAllocator
3030
:members:
3131

32-
.. doxygenclass:: executorch::runtime::MethodMeta
32+
.. doxygenclass:: executorch::runtime::MemoryManager
3333
:members:
3434

3535
Values
@@ -38,5 +38,5 @@ Values
3838
.. doxygenstruct:: executorch::runtime::EValue
3939
:members:
4040

41-
.. doxygenclass:: executorch::aten::Tensor
41+
.. doxygenclass:: executorch::runtime::etensor::Tensor
4242
:members:

docs/source/llm/getting-started.md

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ Create a file called main.cpp with the following contents:
208208
#include <executorch/runtime/core/exec_aten/exec_aten.h>
209209
#include <executorch/runtime/core/result.h>
210210

211-
using exec_aten::ScalarType;
212-
using exec_aten::Tensor;
211+
using executorch::aten::ScalarType;
212+
using executorch::aten::Tensor;
213213
using executorch::extension::from_blob;
214214
using executorch::extension::Module;
215215
using executorch::runtime::EValue;
@@ -235,56 +235,56 @@ std::string generate(
235235
BasicSampler& sampler,
236236
size_t max_input_length,
237237
size_t max_output_length) {
238+
// Convert the input text into a list of integers (tokens) that represents it,
239+
// using the string-to-token mapping that the model was trained on. Each token
240+
// is an integer that represents a word or part of a word.
241+
std::vector<int64_t> input_tokens = tokenizer.encode(prompt);
242+
std::vector<int64_t> output_tokens;
243+
244+
for (auto i = 0u; i < max_output_length; i++) {
245+
// Convert the input_tokens from a vector of int64_t to EValue. EValue is a
246+
// unified data type in the ExecuTorch runtime.
247+
auto inputs = from_blob(
248+
input_tokens.data(),
249+
{1, static_cast<int>(input_tokens.size())},
250+
ScalarType::Long);
251+
252+
// Run the model. It will return a tensor of logits (log-probabilities).
253+
auto logits_evalue = llm_model.forward(inputs);
254+
255+
// Convert the output logits from EValue to std::vector, which is what the
256+
// sampler expects.
257+
Tensor logits_tensor = logits_evalue.get()[0].toTensor();
258+
std::vector<float> logits(
259+
logits_tensor.data_ptr<float>(),
260+
logits_tensor.data_ptr<float>() + logits_tensor.numel());
261+
262+
// Sample the next token from the logits.
263+
int64_t next_token = sampler.sample(logits);
264+
265+
// Break if we reached the end of the text.
266+
if (next_token == ENDOFTEXT_TOKEN) {
267+
break;
268+
}
269+
270+
// Add the next token to the output.
271+
output_tokens.push_back(next_token);
272+
273+
std::cout << tokenizer.decode({next_token});
274+
std::cout.flush();
238275

239-
// Convert the input text into a list of integers (tokens) that represents
240-
// it, using the string-to-token mapping that the model was trained on.
241-
// Each token is an integer that represents a word or part of a word.
242-
std::vector<int64_t> input_tokens = tokenizer.encode(prompt);
243-
std::vector<int64_t> output_tokens;
244-
245-
for (auto i = 0u; i < max_output_length; i++) {
246-
// Convert the input_tokens from a vector of int64_t to EValue.
247-
// EValue is a unified data type in the ExecuTorch runtime.
248-
auto inputs = from_blob(
249-
input_tokens.data(),
250-
{1, static_cast<int>(input_tokens.size())},
251-
ScalarType::Long);
252-
253-
// Run the model. It will return a tensor of logits (log-probabilities).
254-
auto logits_evalue = llm_model.forward(inputs);
255-
256-
// Convert the output logits from EValue to std::vector, which is what
257-
// the sampler expects.
258-
Tensor logits_tensor = logits_evalue.get()[0].toTensor();
259-
std::vector<float> logits(logits_tensor.data_ptr<float>(),
260-
logits_tensor.data_ptr<float>() + logits_tensor.numel());
261-
262-
// Sample the next token from the logits.
263-
int64_t next_token = sampler.sample(logits);
264-
265-
// Break if we reached the end of the text.
266-
if (next_token == ENDOFTEXT_TOKEN) {
267-
break;
268-
}
269-
270-
// Add the next token to the output.
271-
output_tokens.push_back(next_token);
272-
273-
std::cout << tokenizer.decode({ next_token });
274-
std::cout.flush();
275-
276-
// Update next input.
277-
input_tokens.push_back(next_token);
278-
if (input_tokens.size() > max_input_length) {
279-
input_tokens.erase(input_tokens.begin());
280-
}
276+
// Update next input.
277+
input_tokens.push_back(next_token);
278+
if (input_tokens.size() > max_input_length) {
279+
input_tokens.erase(input_tokens.begin());
281280
}
281+
}
282282

283-
std::cout << std::endl;
283+
std::cout << std::endl;
284284

285-
// Convert the output tokens into a human-readable string.
286-
std::string output_string = tokenizer.decode(output_tokens);
287-
return output_string;
285+
// Convert the output tokens into a human-readable string.
286+
std::string output_string = tokenizer.decode(output_tokens);
287+
return output_string;
288288
}
289289
```
290290
@@ -309,32 +309,32 @@ penalties for repeated tokens, and biases to prioritize or de-prioritize specifi
309309
```cpp
310310
// main.cpp
311311
312-
using namespace torch::executor;
313-
314312
int main() {
315-
// Set up the prompt. This provides the seed text for the model to elaborate.
316-
std::cout << "Enter model prompt: ";
317-
std::string prompt;
318-
std::getline(std::cin, prompt);
319-
320-
// The tokenizer is used to convert between tokens (used by the model) and
321-
// human-readable strings.
322-
BasicTokenizer tokenizer("vocab.json");
323-
324-
// The sampler is used to sample the next token from the logits.
325-
BasicSampler sampler = BasicSampler();
326-
327-
// Load the exported nanoGPT program, which was generated via the previous steps.
328-
Module model("nanogpt.pte", Module::LoadMode::MmapUseMlockIgnoreErrors);
329-
330-
const auto max_input_tokens = 1024;
331-
const auto max_output_tokens = 30;
332-
std::cout << prompt;
333-
generate(model, prompt, tokenizer, sampler, max_input_tokens, max_output_tokens);
313+
// Set up the prompt. This provides the seed text for the model to elaborate.
314+
std::cout << "Enter model prompt: ";
315+
std::string prompt;
316+
std::getline(std::cin, prompt);
317+
318+
// The tokenizer is used to convert between tokens (used by the model) and
319+
// human-readable strings.
320+
BasicTokenizer tokenizer("vocab.json");
321+
322+
// The sampler is used to sample the next token from the logits.
323+
BasicSampler sampler = BasicSampler();
324+
325+
// Load the exported nanoGPT program, which was generated via the previous
326+
// steps.
327+
Module model("nanogpt.pte", Module::LoadMode::MmapUseMlockIgnoreErrors);
328+
329+
const auto max_input_tokens = 1024;
330+
const auto max_output_tokens = 30;
331+
std::cout << prompt;
332+
generate(
333+
model, prompt, tokenizer, sampler, max_input_tokens, max_output_tokens);
334334
}
335335
```
336336

337-
Finally, download the following files into the same directory as main.h:
337+
Finally, download the following files into the same directory as main.cpp:
338338

339339
```
340340
curl -O https://raw.githubusercontent.com/pytorch/executorch/main/examples/llm_manual/basic_sampler.h
@@ -524,20 +524,20 @@ option(EXECUTORCH_BUILD_XNNPACK "" ON) # Build with Xnnpack backend
524524
525525
# Include the executorch subdirectory.
526526
add_subdirectory(
527-
${CMAKE_CURRENT_SOURCE_DIR}/third-party/executorch
528-
${CMAKE_BINARY_DIR}/executorch)
529-
530-
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
527+
${CMAKE_CURRENT_SOURCE_DIR}/third-party/executorch
528+
${CMAKE_BINARY_DIR}/executorch
529+
)
531530
532531
add_executable(nanogpt_runner main.cpp)
533532
target_link_libraries(
534-
nanogpt_runner
535-
PRIVATE
536-
executorch
537-
extension_module_static # Provides the Module class
538-
extension_tensor # Provides the TensorPtr class
539-
optimized_native_cpu_ops_lib # Provides baseline cross-platform kernels
540-
xnnpack_backend) # Provides the XNNPACK CPU acceleration backend
533+
nanogpt_runner
534+
PRIVATE executorch
535+
extension_module_static # Provides the Module class
536+
extension_tensor # Provides the TensorPtr class
537+
optimized_native_cpu_ops_lib # Provides baseline cross-platform
538+
# kernels
539+
xnnpack_backend # Provides the XNNPACK CPU acceleration backend
540+
)
541541
```
542542

543543
Keep the rest of the code the same. For more details refer to [Exporting

0 commit comments

Comments
 (0)