diff --git a/docs/docs/computer-vision/useClassification.mdx b/docs/docs/computer-vision/useClassification.mdx index 0e31ad1..cb39d07 100644 --- a/docs/docs/computer-vision/useClassification.mdx +++ b/docs/docs/computer-vision/useClassification.mdx @@ -61,9 +61,9 @@ A string that specifies the location of the model binary. For more information, ## Running the model -To run the model, you can use the `forward` method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise, which can resolve either to error or an object containing categories with their probabilities. +To run the model, you can use the `forward` method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise, which can resolve either to an error or an object containing categories with their probabilities. -:::info[Info] +:::info Images from external sources are stored in your application's temporary directory. ::: diff --git a/docs/docs/computer-vision/useObjectDetection.mdx b/docs/docs/computer-vision/useObjectDetection.mdx index 30a8b0d..0e40076 100644 --- a/docs/docs/computer-vision/useObjectDetection.mdx +++ b/docs/docs/computer-vision/useObjectDetection.mdx @@ -120,7 +120,7 @@ function App() { } ``` -## Supported Models +## Supported models | Model | Number of classes | Class list | | --------------------------------------------------------------------------------------------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | diff --git a/docs/docs/computer-vision/useStyleTransfer.mdx b/docs/docs/computer-vision/useStyleTransfer.mdx index cd9198e..b6f4f4b 100644 --- a/docs/docs/computer-vision/useStyleTransfer.mdx +++ b/docs/docs/computer-vision/useStyleTransfer.mdx @@ -60,7 +60,7 @@ A string that specifies the location of the model binary. For more information, ## Running the model -To run the model, you can use `forward` method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise which can resolve either to error or a URL to generated image. +To run the model, you can use `forward` method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise which can resolve either to an error or a URL to generated image. :::info Images from external sources and the generated image are stored in your application's temporary directory. @@ -86,7 +86,7 @@ function App(){ } ``` -## Supported Models +## Supported models - [Candy](https://github.com/pytorch/examples/tree/main/fast_neural_style) - [Mosaic](https://github.com/pytorch/examples/tree/main/fast_neural_style) diff --git a/docs/docs/fundamentals/getting-started.mdx b/docs/docs/fundamentals/getting-started.mdx index 3e9b2d7..a53be6d 100644 --- a/docs/docs/fundamentals/getting-started.mdx +++ b/docs/docs/fundamentals/getting-started.mdx @@ -50,7 +50,7 @@ When using Expo, please note that you need to use a custom development build of ::: :::info -Because we are using ExecuTorch under the hood, you won't be able to build ios app for release with simulator selected as the target device. Make sure to test release builds on real devices. +Because we are using ExecuTorch under the hood, you won't be able to build iOS app for release with simulator selected as the target device. Make sure to test release builds on real devices. ::: Running the app with the library: diff --git a/docs/docs/fundamentals/loading-models.md b/docs/docs/fundamentals/loading-models.md index 0140159..e538188 100644 --- a/docs/docs/fundamentals/loading-models.md +++ b/docs/docs/fundamentals/loading-models.md @@ -5,13 +5,13 @@ sidebar_position: 1 There are three different methods available for loading model files, depending on their size and location. -**1. Load from React-Native assets folder (For Files < **512MB**)** +**1. Load from React Native assets folder (For Files < 512MB)** ```typescript modelSource: require('../assets/llama3_2.pte'); ``` -**2. Load from Remote URL:** +**2. Load from remote URL:** For files larger than 512MB or when you want to keep size of the app smaller, you can load the model from a remote URL (e.g. HuggingFace). diff --git a/docs/docs/llms/exporting-llama.mdx b/docs/docs/llms/exporting-llama.mdx index e7c2f99..63e045f 100644 --- a/docs/docs/llms/exporting-llama.mdx +++ b/docs/docs/llms/exporting-llama.mdx @@ -6,10 +6,10 @@ sidebar_position: 2 In order to make the process of export as simple as possible for you, we created a script that runs a Docker container and exports the model. ## Steps to export Llama -### 1. Create an Account +### 1. Create an account Get a [HuggingFace](https://huggingface.co/) account. This will allow you to download needed files. You can also use the [official Llama website](https://www.llama.com/llama-downloads/). -### 2. Select a Model +### 2. Select a model Pick the model that suits your needs. Before you download it, you'll need to accept a license. For best performance, we recommend using Spin-Quant or QLoRA versions of the model: - [Llama 3.2 3B](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct/tree/main/original) - [Llama 3.2 1B](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct/tree/main/original) @@ -18,22 +18,22 @@ Pick the model that suits your needs. Before you download it, you'll need to acc - [Llama 3.2 3B QLoRA](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct-QLORA_INT4_EO8/tree/main) - [Llama 3.2 1B QLoRA](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct-QLORA_INT4_EO8/tree/main) -### 3. Download Files +### 3. Download files Download the `consolidated.00.pth`, `params.json` and `tokenizer.model` files. If you can't see them, make sure to check the `original` directory. -### 4. Rename the Tokenizer File +### 4. Rename the tokenizer file Rename the `tokenizer.model` file to `tokenizer.bin` as required by the library: ```bash mv tokenizer.model tokenizer.bin ``` -### 5. Run the Export Script +### 5. Run the export script Navigate to the `llama_export` directory and run the following command: ```bash ./build_llama_binary.sh --model-path /path/to/consolidated.00.pth --params-path /path/to/params.json ``` -The script will pull a Docker image from docker hub, and then run it to export the model. By default the output (llama3_2.pte file) will be saved in the `llama-export/outputs` directory. However, you can override that behavior with the `--output-path [path]` flag. +The script will pull a Docker image from Docker Hub, and then run it to export the model. By default the output (llama3_2.pte file) will be saved in the `llama-export/outputs` directory. However, you can override that behavior with the `--output-path [path]` flag. :::note[Note] This Docker image was tested on MacOS with ARM chip. This might not work in other environments. diff --git a/docs/docs/llms/running-llms.md b/docs/docs/llms/running-llms.md index fcbbc73..93a3e4e 100644 --- a/docs/docs/llms/running-llms.md +++ b/docs/docs/llms/running-llms.md @@ -5,8 +5,8 @@ sidebar_position: 1 React Native ExecuTorch supports Llama 3.2 models, including quantized versions. Before getting started, you’ll need to obtain the .pte binary—a serialized model—and the tokenizer. There are various ways to accomplish this: -- For your convienience, it's best if you use models exported by us, you can get them from our hugging face repository. You can also use [constants](https://github.com/software-mansion/react-native-executorch/tree/main/src/constants/modelUrls.ts) shipped with our library. -- If you want to export model by yourself,you can use a Docker image that we've prepared. To see how it works, check out [exporting Llama](./exporting-llama) +- For your convienience, it's best if you use models exported by us, you can get them from our [HuggingFace repository](https://huggingface.co/software-mansion/react-native-executorch-llama-3.2). You can also use [constants](https://github.com/software-mansion/react-native-executorch/tree/main/src/constants/modelUrls.ts) shipped with our library. +- If you want to export model by yourself, you can use a Docker image that we've prepared. To see how it works, check out [exporting Llama](./exporting-llama) - Follow the official [tutorial](https://github.com/pytorch/executorch/blob/fe20be98c/examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md) made by ExecuTorch team to build the model and tokenizer yourself ## Initializing @@ -55,7 +55,7 @@ Given computational constraints, our architecture is designed to support only on | `isReady` | `boolean` | Indicates whether the model is ready | | `downloadProgress` | `number` | Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval. | -### Sending a message +## Sending a message In order to send a message to the model, one can use the following code: @@ -71,7 +71,7 @@ await llama.generate(message); ... ``` -### Listening for the response +## Listening for the response As you might've noticed, there is no return value from the `runInference` function. Instead, the `.response` field of the model is updated with each token. This is how you can render the response of the model: diff --git a/docs/docs/module-api/executorch-bindings.md b/docs/docs/module-api/executorch-bindings.md index ea2c5f2..c7c6ecd 100644 --- a/docs/docs/module-api/executorch-bindings.md +++ b/docs/docs/module-api/executorch-bindings.md @@ -38,7 +38,7 @@ The `modelSource` parameter expects a location string pointing to the model bina | `loadForward` | `() => Promise` | Loads resources specific to `forward` method into memory before execution. Uses `loadMethod` under the hood. | | `forward` | `(input: ETInput, shape: number[]) => Promise` | Executes the model's forward pass, where `input` is a Javascript typed array and `shape` is an array of integers representing input Tensor shape. The output is a Tensor - raw result of inference. | -### ETInput +## ETInput The `ETInput` type defines the typed arrays that can be used as inputs in the `forward` method: @@ -48,7 +48,7 @@ The `ETInput` type defines the typed arrays that can be used as inputs in the `f - Float32Array - Float64Array -### Errors +## Errors All functions provided by the `useExecutorchModule` hook are asynchronous and may throw an error. The `ETError` enum includes errors [defined by the ExecuTorch team](https://github.com/pytorch/executorch/blob/main/runtime/core/error.h) and additional errors specified by our library. @@ -60,7 +60,7 @@ To run model with ExecuTorch Bindings it's essential to specify the shape of the This example demonstrates the integration and usage of the ExecuTorch bindings with a [style transfer model](../computer-vision/useStyleTransfer.mdx). Specifically, we'll be using the `STYLE_TRANSFER_CANDY` model, which applies artistic style transfer to an input image. -### Importing the Module and loading the model +## Importing the Module and loading the model First, import the necessary functions from the `react-native-executorch` package and initialize the ExecuTorch module with the specified style transfer model. @@ -77,7 +77,7 @@ const executorchModule = useExecutorchModule({ ``` -### Setting up input parameters +## Setting up input parameters To prepare the input for the model, define the shape of the input tensor. This shape depends on the model's requirements. For the `STYLE_TRANSFER_CANDY` model, we need a tensor of shape `[1, 3, 640, 640]`, corresponding to a batch size of 1, 3 color channels (RGB), and dimensions of 640x640 pixels. @@ -88,7 +88,7 @@ const shape = [1, 3, 640, 640]; const input = new Float32Array(1 * 3 * 640 * 640); // fill this array with your image data ``` -### Performing inference +## Performing inference ```typescript try {