The Principal Dev – Masterclass for Tech Leads

The Principal Dev – Masterclass for Tech LeadsJuly 17-18

Join

React Native ExecuTorch Join our Discord community

Software Mansion banner

React Native ExecuTorch is a declarative way to run AI models in React Native on device, powered by ExecuTorch :rocket:. It offers out-of-the-box support for many LLMs, computer vision models, and many many more. Feel free to check them out on our HuggingFace page.

ExecuTorch is a novel framework created by Meta that enables running AI models on devices such as mobile phones or microcontrollers.

React Native ExecuTorch bridges the gap between React Native and native platform capabilities, allowing developers to run AI models locally on mobile devices with state-of-the-art performance, without requiring deep knowledge of native code or machine learning internals.

npm version CI

Table of contents:

:yin_yang: Supported versions

The minimal supported version are:

[!IMPORTANT]
React Native Executorch supports only the New React Native architecture.

:robot: Ready-made models

To run any AI model in ExecuTorch, you need to export it to a .pte format. If you're interested in experimenting with your own models, we highly encourage you to check out the Python API. If you prefer focusing on developing your React Native app, we will cover several common use cases. For more details, please refer to the documentation.

:books: Documentation

Take a look at how our library can help build you your React Native AI features in our docs:
https://docs.swmansion.com/react-native-executorch

:llama: Quickstart - Running Llama

Get started with AI-powered text generation in 3 easy steps!

:one: Installation

# Install the package
yarn add react-native-executorch
# Depending on the platform, choose either iOS or Android
yarn expo run:< ios | android >

:two: Setup & Initialization

Add this to your component file:

import {
  useLLM,
  LLAMA3_2_1B,
  LLAMA3_2_TOKENIZER,
  LLAMA3_2_TOKENIZER_CONFIG,
} from 'react-native-executorch';

function MyComponent() {
  // Initialize the model 🚀
  const llm = useLLM({
    modelSource: LLAMA3_2_1B,
    tokenizerSource: LLAMA3_2_TOKENIZER,
    tokenizerConfigSource: LLAMA3_2_TOKENIZER_CONFIG,
  });
  // ... rest of your component
}

:three: Run the model!

const handleGenerate = async () => {
  const chat = [
    { role: 'system', content: 'You are a helpful assistant' },
    { role: 'user', content: 'What is the meaning of life?' }
  ];

  // Chat completion
  await llm.generate(chat);
  console.log('Llama says:', llm.response);
};

:calling: Examples

We currently host a few example apps demonstrating use cases of our library:

If you would like to run demo app, navigate to its project directory and install dependencies with:

yarn

Then, depending on the platform, choose either iOS or Android:

yarn expo run:< ios | android >

[!WARNING]
Running LLMs requires a significant amount of RAM. If you are encountering unexpected app crashes, try to increase the amount of RAM allocated to the emulator.

:balance_scale: License

This library is licensed under The MIT License.

:soon: What's next?

To learn about our upcoming plans and developments, please visit our milestones.

React Native ExecuTorch is created by Software Mansion

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.

swm

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.