diff --git a/.cspell-wordlist.txt b/.cspell-wordlist.txt index 77427e9034..63fe8945eb 100644 --- a/.cspell-wordlist.txt +++ b/.cspell-wordlist.txt @@ -353,3 +353,19 @@ backgrounding LibriSpeech recompiles xzmf +memcpy +autoregressive +dispatchable +embedder +embedders +Embedder +Pretraining +Unigram +Unigrams +subword +wordpiece +anonymization +gapless +Feedforward +subpath +subpaths diff --git a/.github/workflows/docs-build-check.yml b/.github/workflows/docs-build-check.yml index eec9d3a4a3..5223b63711 100644 --- a/.github/workflows/docs-build-check.yml +++ b/.github/workflows/docs-build-check.yml @@ -4,15 +4,20 @@ on: push: branches: - main + - rne-rewrite paths: - 'docs/**' - '.github/workflows/docs-build-check.yml' pull_request: branches: - main + - rne-rewrite paths: - 'docs/**' - '.github/workflows/docs-build-check.yml' + merge_group: + types: + - checks_requested workflow_dispatch: jobs: check: diff --git a/README.md b/README.md index 818abb048d..6dc7851576 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@
- RNE Logo + + + React Native ExecuTorch Logo +
- -
-

React Native ExecuTorch -

-
+
+
@@ -21,164 +21,107 @@
-

- README - README ES - README FR - README CN - README PT - README IN -

+
-**React Native ExecuTorch** provides a declarative way to run AI models on-device using React Native, powered by **ExecuTorch** :rocket:. It offers out-of-the-box support for a wide range of LLMs, computer vision models, and more. Visit our [HuggingFace](https://huggingface.co/software-mansion) page to explore these models. +**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. 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. -[**ExecuTorch**](https://executorch.ai), developed by Meta, is a novel framework allowing AI model execution on devices like mobile phones or microcontrollers. +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 [Hugging Face collection](https://huggingface.co/software-mansion/collections) and ready to use out of the box. You can also bring your own `.pte` models and plug them into existing pipelines or build entirely custom ones from scratch. -React Native ExecuTorch bridges the gap between React Native and native platform capabilities, enabling developers to efficiently run local AI models on mobile devices. This can be achieved without the need for extensive expertise in native programming or machine learning. +To explore all on-device capabilities in an interactive showcase app, check out the [React Native ExecuTorch Gallery](https://github.com/software-mansion-labs/react-native-executorch-gallery). [![npm version](https://img.shields.io/npm/v/react-native-executorch?color=00008B)](https://www.npmjs.com/package/react-native-executorch) [![npm nightly](https://img.shields.io/npm/v/react-native-executorch/executorch-nightly?label=nightly&color=00008B)](https://www.npmjs.com/package/react-native-executorch) [![CI](https://github.com/software-mansion/react-native-executorch/actions/workflows/ci.yml/badge.svg)](https://github.com/software-mansion/react-native-executorch/actions/workflows/ci.yml) -
-Table of Contents - -- [Supported Versions](#supported-versions) -- [Real-world Example](#real-world-example) -- [Quickstart - Running LFM2.5](#quickstart---running-lfm25) - - [:one: Installation](#one-installation) - - [:two: Setup \& Initialization](#two-setup--initialization) - - [:three: Run the Model!](#three-run-the-model) -- [Demo Apps](#demo-apps) -- [Ready-made Models](#ready-made-models) -- [Documentation](#documentation) -- [License](#license) -- [What's Next?](#whats-next) -- [React Native ExecuTorch is created by Software Mansion](#react-native-executorch-is-created-by-software-mansion) - -
- -## Supported Versions - -The minimal supported version are: -* iOS 17.0 -* Android 13 -* React Native - see [compatibility table](https://docs.swmansion.com/react-native-executorch/docs/next/other/compatibility) - -> [!IMPORTANT] -> React Native ExecuTorch supports only the [New React Native architecture](https://reactnative.dev/architecture/landing-page). - -## Real-world Example +## Table of Contents -React Native ExecuTorch is powering [Private Mind](https://privatemind.swmansion.com/), a privacy-first mobile AI app available on [App Store](https://apps.apple.com/gb/app/private-mind/id6746713439) and [Google Play](https://play.google.com/store/apps/details?id=com.swmansion.privatemind). +- [Key Features](#key-features) +- [Quickstart](#quickstart) + - [1. Installation](#1-installation) + - [2. Run the Model](#2-run-the-model) +- [Interactive Gallery App](#interactive-gallery-app) +- [Documentation](#documentation) +- [Powered by React Native ExecuTorch](#powered-by-react-native-executorch) +- [Created by Software Mansion](#created-by-software-mansion) -Private Mind promo +## Key Features -## Quickstart - Running LFM2.5 +- **Native Hardware Acceleration**: Optimized execution delegates across backends: **XNNPACK** (CPU), **Core ML** & **MLX** (Apple Silicon), and **Vulkan** (Android GPU). +- **100% Offline & Private**: Zero cloud inference costs and zero network dependency after model download. No user data ever leaves the device. +- **Two-Layer Architecture**: + - **Ready-to-use Task Hooks (`use`)**: Out-of-the-box support for LLMs, computer vision, speech, and embeddings with automatic caching and lifecycle management. + - **Lower-level Runtime & Custom Orchestration**: Build custom pipelines entirely in TypeScript using low-level tensor operations, fast native operators, schema validation, and worklet threading. +- **Pre-Exported Model Catalog**: Access verified models directly via the `models` registry and the [Software Mansion Hugging Face Collections](https://huggingface.co/software-mansion/collections). -**Get started with AI-powered text generation in 3 easy steps!** +## Quickstart -The steps below assume an Expo project. For bare React Native, follow the [Getting Started guide](https://docs.swmansion.com/react-native-executorch/docs/fundamentals/getting-started) in the documentation. +### 1. Installation -### :one: Installation +Install `react-native-executorch` alongside its required peer dependencies: ```bash -# Install the package -yarn add react-native-executorch - -# Add these packages for resource fetching: -yarn add react-native-executorch-expo-resource-fetcher -yarn add expo-file-system expo-asset - -# Depending on the platform, choose either iOS or Android -yarn +npm install react-native-executorch react-native-worklets react-native-blob-util +# or +yarn add react-native-executorch react-native-worklets react-native-blob-util +# or +pnpm add react-native-executorch react-native-worklets react-native-blob-util ``` -> npm and pnpm work too — use `npm install` or `pnpm add` for the packages, and `npm run ` / `pnpm ` for the run step. - -### :two: Setup & Initialization +> [!IMPORTANT] +> React Native ExecuTorch requires the **New React Native Architecture**, **React Native 0.81+** or **Expo SDK 54+** (using development builds), **iOS 17.0+**, and **Android 13+**. -Add this to your component file: +### 2. Run the Model ```tsx -import { - useLLM, - models, - Message, - initExecutorch, -} from 'react-native-executorch'; -import { ExpoResourceFetcher } from 'react-native-executorch-expo-resource-fetcher'; - -initExecutorch({ - resourceFetcher: ExpoResourceFetcher, -}); - -function MyComponent() { - // Initialize the model 🚀 - const llm = useLLM({ model: models.llm.lfm2_5_1_2b_instruct() }); - // ... rest of your component +import { Button, View } from 'react-native'; +import { models, useLLMChatSession } from 'react-native-executorch'; + +export function App() { + const session = useLLMChatSession(models.llm.LFM2_5_1_2B.DEFAULT); + + const handleGenerate = async () => { + if (!session.isReady || !session.sendMessage) return; + + const turn = await session.sendMessage( + 'Explain on-device AI in one sentence.', + (token) => console.log(token) + ); + + console.log('Result messages:', turn.messages); + }; + + return ( + +