Skip to content

Commit b978075

Browse files
mikekgfbmalfet
authored andcommitted
Update runner_build.md (#530)
Update description of runner and build process in runner_build.md
1 parent 68b53f3 commit b978075

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

docs/runner_build.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
# Building runner-aoti and runner-et
2-
Building the runners is straightforward and is covered in the next sections. We will showcase the runners using stories15M.
1+
# Native Execution
32

4-
The runners accept the following CLI arguments:
3+
While Python offers a great environment for training models and experimentation and research with models, developers
4+
often are looking to use a native execution environment, either to achieve a certain performance level, or when
5+
including a Python is undesirable (e.g., in a game application that wants to use an LLM for user interaction) or impossible (devices
6+
with limited functionality and memory capacity).
7+
8+
The 'llama runner' is a native standalone application capable of running a model exported and compiled ahead-of-time with either Executorch (ET) or AOT Inductor (AOTI). Which model format to use depends on your requirements and preferences. Executorch modelsare optimized for portability across a range of decices, including mobile and edge devices. AOT Inductor models are optimized for a particular target architecture, which may result in better performance and efficiency.
9+
10+
Building the runners is straightforward with the included cmake build files and is covered in the next sections. We will showcase the runners using ~~stories15M~~ llama2 7B and llama3.
11+
12+
## What can you do with torchchat's llama runner for native execution?
13+
14+
* Run models natively:
15+
* [Chat](#chat)
16+
* [Generate](#generate)
17+
* ~~[Run via Browser](#browser)~~
18+
* [Building and using llama runner for exported .so files](#run-server)
19+
* in Chat mode
20+
* in Generate mode
21+
* [Building and using llama runner for exported .pe files](#run-portable)
22+
* in Chat mode
23+
* in Generate mode
24+
* [Building and using llama runner on mobile devices](#run-mobile)
25+
* Appendix:
26+
* [Tokenizers](#tokenizers)
27+
* [Validation](#validation)
28+
29+
30+
The runners accept the following command-line arguments:
531

632
```
733
Options:
@@ -76,3 +102,22 @@ We can now execute the runner with:
76102
wget -O ./tokenizer.bin https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin
77103
./cmake-out/et_run ./model.pte -z ./tokenizer.bin -i "Once upon a time"
78104
```
105+
106+
## Appendix: Llama runner tokenizers
107+
108+
Tokenizers are essential tools in Natural Language Processing (NLP) that convert text into smaller units, such as words or phrases, known as tokens. Two popular tokenizers are SentencePiece and Tiktoken. [SentencePiece](https://github.com/google/sentencepiece) is an unsupervised text tokenizer and detokenizer mainly for Neural Network-based text generation systems where the vocabulary size is predetermined prior to the neural model training. Llama2-style models typically use the SentencePiece tokenizer. Tiktoken is a newer tokenizer originally developed by OpenAI that allows you to see how many tokens a text string will use without making an API call. Llama3 uses the Tiktoken tokenizer.
109+
Torchchat includes both Python and C/C++ implementations of both the SentencePiece and Tiktoken tokenizers that may be used with the Python and native execution environments, respectively.
110+
111+
The SentencePiece tokenizer implementations for Python (developed by Google) and the C/C++ implementation (developed by Andrej Karpathy) use different input formats. The Python implementation reads a tokenizer specification in `tokenizer.model` format. The C/C++ tokenizer that reads the tokenizer instructions from a file in `tokenizer.bin` format. We include Andrej's SentencePiece converter which translates a SentencePiece tokenizer in `tokenizer.model` format to `tokenizer.bin` in the utils subdirectory:
112+
```
113+
python3 utils/tokenizer.py --tokenizer-model=${MODEL_DIR}/tokenizer.model
114+
```
115+
116+
## Appendix: Native model verification using the Python environment
117+
118+
After exporting a model, you will want to verify that the model delivers output of high quality, and works as expected.
119+
Both can be achieved with the Python environment. All torchchat Python comands can work with exported models. Instead of loading the model from a checkpoint or GGUF file, use the the `--dso-path model.so` and `--pte-path model.pte` for loading both types of exported models. This enables you to verify the quality of the exported models, and run any tests that you may have developed in conjunction with exported models to enable you to validate model quality.
120+
121+
The `eval` tool evaluates model quality using metrics such as 'perplexity' that are commonly used in the NLP community to evaluate output quality. Load your model exported model to evaluate quality metrics for exported models. You can find an introduction to the eval tool in the [README](../README.md) file.
122+
123+
The `generate`, `chat` and `browser` tools enable you to verify that the exported model works correctly, as a debugging aid if you are developing your own native execution environment based on the llama runner provided with torchchat.

0 commit comments

Comments
 (0)