Skip to main content

Getting Started

What is ExecuTorch?

ExecuTorch is a novel AI framework developed by Meta, designed to streamline deploying PyTorch models on a variety of devices, including mobile phones and microcontrollers. This framework enables exporting models into standalone binaries, allowing them to run locally without requiring API calls. ExecuTorch achieves state-of-the-art performance through optimizations and delegates such as Core ML and XNNPACK. It provides a seamless export process with robust debugging options, making it easier to resolve issues if they arise.

React Native ExecuTorch

React Native ExecuTorch is our way of bringing ExecuTorch into the React Native world. Our API is built to be simple, declarative, and efficient. Plus, we’ll provide a set of pre-exported models for common use cases, so you won’t have to worry about handling exports yourself. With just a few lines of JavaScript, you’ll be able to run AI models (even LLMs 👀) right on your device—keeping user data private and saving on cloud costs.

Compatibility

React Native Executorch supports only the New React Native architecture.

If your app still runs on the old architecture, please consider upgrading to the New Architecture.

Installation

Installation is pretty straightforward, just use your favorite package manager. We use React Native Audio API as a peer dependency to make it possible to load audio for Speech To Text.

npm install react-native-executorch

If you're using bare React Native (instead of a managed Expo project), you also need to install Expo Modules because the underlying implementation relies on expo-file-system. Since expo-file-system is an Expo package, bare React Native projects need Expo Modules to properly integrate and use it. The link provided (https://docs.expo.dev/bare/installing-expo-modules/) offers guidance on setting up Expo Modules in a bare React Native environment.

If you plan on using your models via require() instead of fetching them from a url, you also need to add following lines to your metro.config.js:

// metro.config.js
...
defaultConfig.resolver.assetExts.push('pte')
defaultConfig.resolver.assetExts.push('bin')
...

This allows us to use binaries, such as exported models or tokenizers for LLMs.

caution

When using Expo, please note that you need to use a custom development build of your app, not the standard Expo Go app. This is because we rely on native modules, which Expo Go doesn’t support.

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.

Running the app with the library:

yarn run expo:<ios | android> -d

Good reads

If you want to dive deeper into ExecuTorch or our previous work with the framework, we highly encourage you to check out the following resources: