Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 1 addition & 4 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ const config = {
sidebarCollapsible: false,
editUrl:
'https://github.com/software-mansion/react-native-executorch/edit/main/docs',
lastVersion: 'current',
lastVersion: '0.10.0',
versions: {
current: {
label: '0.10.0',
},
// === LEGACY SUPPORT ===: versioned docs for the legacy API (remove when legacy API is dropped)
'0.10.0-legacy': {
label: '0.10.0-legacy',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---
title: Getting Started
slug: /fundamentals/getting-started
keywords:
[
react native,
react native ai,
react native llm,
on-device ai,
executorch,
pytorch mobile,
mobile ml,
vision,
speech,
]
description: 'Get started with React Native ExecuTorch — high-performance, privacy-first on-device AI inference for React Native.'
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Getting Started

React Native ExecuTorch is an on-device AI inference library for React Native,
powered by [ExecuTorch](https://executorch.ai) — Meta's on-device inference
runtime and a project under the PyTorch Foundation. It lets you run machine
learning models directly on the user's phone with zero network calls, full offline
capability, and guaranteed privacy. No data ever leaves the device.

The library ships with a curated set of pre-exported models covering
computer vision, language models, text-to-speech, transcription, and more — all available in our
[HuggingFace collection](https://huggingface.co/software-mansion/collections)
and ready to use out of the box. You can also bring your own models and
plug them into existing pipelines or build entirely custom ones from scratch.

## What is ExecuTorch?

[ExecuTorch](https://executorch.ai) is a PyTorch Core project — Meta's on-device
inference runtime for deploying PyTorch models on edge devices. It takes standard
PyTorch models and compiles them into an optimized `.pte` format that runs
natively on mobile phones, AR/VR headsets, embedded systems, and custom
accelerators.

The runtime supports hardware-accelerated backends for every major platform:
XNNPACK for CPU acceleration across all platforms, Core ML and MLX on Apple
devices, Vulkan for Android GPU, and more. It's a core part of the PyTorch ecosystem,
with full support for the standard PyTorch model export workflow.

ExecuTorch handles the hard parts: memory planning, operator dispatch, and
hardware delegate selection — so you don't have to. To learn more about the
underlying runtime, check out the
[ExecuTorch documentation](https://docs.pytorch.org/executorch/stable/index.html).

## Installation

Install [`react-native-executorch`](https://www.npmjs.com/package/react-native-executorch)
alongside its peer dependencies:

<Tabs groupId="package-manager">
<TabItem value="npm" label="npm">

```bash
npm install react-native-executorch react-native-worklets react-native-blob-util
```

</TabItem>
<TabItem value="yarn" label="yarn">

```bash
yarn add react-native-executorch react-native-worklets react-native-blob-util
```

</TabItem>
<TabItem value="pnpm" label="pnpm">

```bash
pnpm add react-native-executorch react-native-worklets react-native-blob-util
```

</TabItem>
</Tabs>

:::info Requirements
React Native ExecuTorch requires:

- **New Architecture** enabled
- **React Native 0.81+** or **Expo SDK 54+** with [Development Builds](https://docs.expo.dev/develop/development-builds/introduction/) (**Expo Go is not supported** due to custom C++ native libraries)
- **iOS 17.0+** / **Android 13+**

For supported React Native versions, see the [Compatibility
table](../05-other/01-compatibility.mdx).
:::

### Selecting native libraries

The native binaries — the ExecuTorch hardware backends (XNNPACK, Core ML, MLX,
Vulkan), and third-party binaries — are downloaded on demand at install time. By
default, **everything is downloaded and enabled**, so no configuration is
required to get started.

If you want a smaller app or faster installs, declare what you use in a
`react-native-executorch` block in your `package.json`, e.g.:

```json
{
"react-native-executorch": {
"features": ["classification", "styleTransfer"]
}
}
```

The available options are:

- **`features`** — high-level task names. Each one expands to the backends and
native libs it needs.
- **`backends`** — hardware backends directly, e.g. `xnnpack`, `coreml`,
`vulkan`.
- **`libs`** — extra native libraries, see
[options](../03-core-and-advanced/08-native-libraries.md#options).

The three lists are merged, so you can pair a `features` set with extra
`backends` / `libs` entries. Re-run your package manager's install after
editing. See [Native Libraries](../03-core-and-advanced/08-native-libraries.md)
for details.

## Choose Your Path

Most mobile ML libraries force you into one of two extremes: opaque native
black boxes that implement a fixed set of pipelines with no room for
customization, or raw low-level bindings that leave you to wire up everything
from preprocessing to memory management yourself.

What if you need a bit of both? Ready-to-use pipelines for common tasks, but
also the freedom to drop down and build something custom when the out-of-the-box
solution doesn't quite fit.
That's exactly how React Native ExecuTorch is designed. The library is built
around a clean **two-layer architecture** where the higher-level layer is
implemented entirely on top of the lower-level one — not as separate C++ code
hidden behind abstractions. This means:

- **Pipelines are transparent.** Every task pipeline (computer vision,
LLM chat, etc.) is written in a few hundred lines of TypeScript — often
less. You can read the full input/output contracts, preprocessing, and
postprocessing logic in one place — no native code required.

- **Custom models just work.** Plug your own `.pte` into any existing pipeline —
computer vision, LLM, whatever. The schema DSL declares exactly what each
pipeline expects (tensor shapes, data types, preprocessing), so there's no
guessing. Everything is in one place, readable in TypeScript.

- **You can always drop down.** When built-in pipelines don't fit your use
case, the lower-level API gives you direct access to ExecuTorch model
execution, native tensor operations, high-performance math/vision operators,
and worklet threading. You build custom orchestration pipelines entirely in
TypeScript — no C++ required — with complete control over preprocessing,
inference, postprocessing, and memory.

### High-Level Task Pipelines

Have a specific problem to solve — computer vision, LLM chat, speech
transcription? Each task has a ready-made pipeline you can drop into your app.
Hooks handle downloading, caching, and memory disposal automatically. Imperative
APIs give you manual control. Both work with pre-exported models from our
[HuggingFace collection](https://huggingface.co/software-mansion/collections) or
your own `.pte` files — as long as they match the pipeline's schema.

[Explore High-Level Pipelines →](../category/extensions)

### Lower-Level Runtime & Custom Pipelines

Working with a custom model or chaining multiple models together into a custom
workflow? The lower-level API gives you direct access to ExecuTorch model
execution, native tensor operations, native operators for vision, math, NLP, and
audio, plus worklet-based multi-threading. You write the entire pipeline in
TypeScript using the exact same building blocks and primitives we use to build
the library's built-in extensions — no native C++ required.

[Explore Lower-Level API →](../category/core--advanced)
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
---
title: Downloading Models
slug: /fundamentals/downloading-models
description: 'How model files reach the device — the pre-exported model registry, automatic download and caching in hooks, and the imperative download API with progress and cancellation.'
keywords:
[
react native executorch,
download model,
model cache,
useResourceDownload,
download,
on-device ai,
pte,
]
---

# Downloading Models

A model config is one or more files — the `.pte` program, and often a tokenizer,
phonemizer, or label map alongside it — that have to be present on the device
before inference can run. React Native ExecuTorch downloads those files for you
and caches them persistently, so in most apps you never touch the filesystem
directly: you point a pipeline at a model config and the library fetches whatever isn't
already cached.

## Where models come from

A model source is either remote or local:

- **Pre-exported models** live in our
[HuggingFace collection](https://huggingface.co/software-mansion/collections) and
are addressed through the
[`models`](../06-api-reference/variables/models.md) registry. Each entry bundles
every file a pipeline needs behind one object. This registry is the single source
of truth for the tuned, ready-to-run models.
- **Your own models** are plain URLs or local paths — a file bundled with the app,
a `file://` path, or a URL on your own host (see
[Exporting Custom Models](../03-core-and-advanced/07-exporting-custom-models.md)).

Local paths are always passed through untouched; only `http(s)` URLs are ever
downloaded.

## Automatic downloading with hooks

The [`use<Task>`](../category/extensions) hooks and the
[`useResourceDownload`](../06-api-reference/functions/useResourceDownload.md) hook
download and cache a model's files automatically. Pass a config; the hook fetches
anything not already cached, reports progress, and hands back the same config with
every URL replaced by its local path.

```typescript
import { useResourceDownload, models } from 'react-native-executorch';

function Example() {
const { resource, downloadProgress, downloadError } = useResourceDownload(
models.classification.EFFICIENTNET_V2_S.XNNPACK_FP32
);

// resource is undefined until the download resolves, then mirrors the config
// with local file paths, ready to hand to a pipeline.
}
```

Both hooks accept
[`ResourceOptions`](../06-api-reference/type-aliases/ResourceOptions.md):

- [**`preventLoad`**](../06-api-reference/type-aliases/ResourceOptions.md#preventload) —
skip the download entirely (and reset state), for deferring a fetch until the
user opts in.
- [**`forceDownload`**](../06-api-reference/type-aliases/ResourceOptions.md#forcedownload) —
re-fetch even when cached, to replace a corrupted file or pick up a model that
changed behind a stable URL.

## Imperative downloading

When you're not in a component — a background task, a custom pipeline, a
preloading step — use the imperative
[`download`](../06-api-reference/functions/download.md) function. It takes a URL,
or any nested object/array of them (typically a whole model config), downloads
every remote leaf, and resolves with the same value with URLs replaced by local
paths — ready to pass straight to a `create<Task>` factory:

```typescript
import { download, models } from 'react-native-executorch';

const model = await download(models.classification.EFFICIENTNET_V2_S.XNNPACK_FP32, {
onProgress: (p) => console.log(`${Math.round(p * 100)}%`),
});

// `model` now holds local paths; hand it to a pipeline factory
```

[`DownloadOptions`](../06-api-reference/interfaces/DownloadOptions.md) covers the
common needs:

- [**`onProgress(p)`**](../06-api-reference/interfaces/DownloadOptions.md#onprogress) —
overall progress in `[0, 1]`, weighted by each file's byte size so a large model
isn't reported the same as a small tokenizer.
- [**`signal`**](../06-api-reference/interfaces/DownloadOptions.md#signal) — an
`AbortSignal` to cancel. The bytes fetched so far are kept so a later download
of the same source resumes instead of restarting (except on Android without
the optional background downloader, where the system `DownloadManager` discards
a cancelled transfer).
- [**`forceDownload`**](../06-api-reference/interfaces/DownloadOptions.md#forcedownload) —
re-download even when cached.

## Caching behavior

Downloads go to a persistent cache keyed by URL, and this is what keeps repeat
launches fast:

- A file that is already cached resolves immediately — no network round trip.
- Concurrent downloads of the same URL are deduplicated into one transfer.
- Without extra dependencies, fetching falls back to what each platform supports
natively: the system `DownloadManager` on Android (which continues in the
background), and a streaming request on iOS (which pauses when the app is
suspended and resumes when reopened).
- To keep transfers running in the background across both iOS and Android and survive
the app being killed, install the optional peer dependency
[`@kesha-antonov/react-native-background-downloader`](https://github.com/kesha-antonov/react-native-background-downloader)
(`>=4.4.0`). The library detects and uses it automatically with zero extra configuration.

Use `forceDownload` to bypass the cache and replace a file. Otherwise, downloading
the same model again is effectively free.

## Anonymous Telemetry & Download Counter

When downloading pre-exported models from our Hugging Face repositories, the fetcher
pings Hugging Face's standard model download counter (via a lightweight `HEAD` request
to `config.json`). However, because Hugging Face's built-in metrics can be delayed or
inconsistent for direct file downloads, the library also sends a lightweight, anonymous
download event to Software Mansion. This exists solely to help us understand which
models community members rely on and prioritize maintenance and optimizations accordingly.
No user data, device IDs, IP addresses, or personally identifiable information are ever
stored or tracked.

Telemetry is enabled by default. To opt out, call
[`setTelemetryEnabled(false)`](../06-api-reference/functions/setTelemetryEnabled.md)
once at application startup:

```typescript
import { setTelemetryEnabled } from 'react-native-executorch';

// Opt out of anonymous download analytics
setTelemetryEnabled(false);
```

## Where to go next

- [Getting Started](./01-getting-started.md) — install the library and run your first model.
- [Exporting Custom Models](../03-core-and-advanced/07-exporting-custom-models.md) — bring your own `.pte` and match a pipeline.
- [Models & Tensors](../03-core-and-advanced/02-models-and-tensors.md) — load a downloaded `.pte` directly with the lower-level API.

### API reference

- [`download()`](../06-api-reference/functions/download.md) · [`DownloadOptions`](../06-api-reference/interfaces/DownloadOptions.md)
- [`useResourceDownload()`](../06-api-reference/functions/useResourceDownload.md) · [`ResourceOptions`](../06-api-reference/type-aliases/ResourceOptions.md)
- [`setTelemetryEnabled()`](../06-api-reference/functions/setTelemetryEnabled.md) · [`models`](../06-api-reference/variables/models.md)
Loading