Skip to content

Commit afc2472

Browse files
Feat/Add a React Native LLaMA demo app for iOS
Differential Revision: D66644092 Pull Request resolved: #7134
1 parent ac8bf78 commit afc2472

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+18459
-0
lines changed

.lintrunner.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ exclude_patterns = [
7474
# NB: Objective-C is not supported
7575
'examples/apple/**',
7676
'examples/demo-apps/apple_ios/**',
77+
'examples/demo-apps/react-native/rnllama/ios/**',
7778
# File contains @generated
7879
'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
7980
'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
2+
3+
# dependencies
4+
node_modules/
5+
6+
# Expo
7+
.expo/
8+
dist/
9+
web-build/
10+
expo-env.d.ts
11+
12+
# Native
13+
*.orig.*
14+
*.jks
15+
*.p8
16+
*.p12
17+
*.key
18+
*.mobileprovision
19+
20+
# Metro
21+
.metro-health-check*
22+
23+
# debug
24+
npm-debug.*
25+
yarn-debug.*
26+
yarn-error.*
27+
28+
# macOS
29+
.DS_Store
30+
*.pem
31+
32+
# local env files
33+
.env*.local
34+
35+
# typescript
36+
*.tsbuildinfo
37+
38+
app-example
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# React Native Llama
2+
3+
<p align="center">
4+
<img src="./assets/images/rnllama.png" width="200" alt="rnllama Logo">
5+
</p>
6+
7+
A React Native mobile application for running LLaMA language models using ExecuTorch. This example is for iOS only for now.
8+
9+
## Features
10+
11+
- Run LLaMA models directly on device, build the UI using React Native
12+
- Tested using Llama 3.2 SpinQuant 1B on iPhone 12 Pro
13+
- The setup is heavily inspired by the [LLaMA iOS app example](https://github.com/pytorch/executorch/tree/main/examples/demo-apps/apple_ios/LLaMA)
14+
15+
16+
## Prerequisites
17+
18+
- Node.js & npm
19+
- Xcode
20+
21+
## Installation
22+
23+
1. Clone the repository: `git clone [email protected]:pytorch/executorch.git`
24+
25+
2. Navigate to the root of the repository: `cd executorch`
26+
27+
3. Pull submodules: `git submodule sync && git submodule update --init`
28+
29+
4. Install dependencies: `./install_requirements.sh --pybind xnnpack && ./examples/models/llama/install_requirements.sh`
30+
31+
5. Follow the instructions in the [README](https://github.com/pytorch/executorch/blob/main/examples/models/llama/README.md#option-a-download-and-export-llama32-1b3b-model) to export a model as `.pte`
32+
33+
6. Navigate to the example: `cd examples/demo-apps/react-native/rnllama`
34+
35+
7. Install dependencies: `npm install && cd ios && pod install && cd ..`
36+
37+
8. Run the app: `npx expo run:ios --device --configuration Release` and select a USB connected iOS device
38+
39+
9. Find the device in finder, and place the exported `.pte` model and the downloaded tokenizer under the app
40+
41+
10. Select the model and tokenizer in the app to start chatting:
42+
43+
[![rnllama]](https://github.com/user-attachments/assets/b339f1ec-8b80-41f0-b3f6-ded6698ac926)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"expo": {
3+
"name": "rnllama",
4+
"slug": "rnllama",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/images/rnllama.png",
8+
"scheme": "myapp",
9+
"userInterfaceStyle": "automatic",
10+
"splash": {
11+
"image": "./assets/images/rnllama.png",
12+
"resizeMode": "contain",
13+
"backgroundColor": "#ffffff"
14+
},
15+
"ios": {
16+
"supportsTablet": true,
17+
"bundleIdentifier": "com.hietalajulius.rnllama"
18+
},
19+
"android": {
20+
"adaptiveIcon": {
21+
"foregroundImage": "./assets/images/rnllama.png",
22+
"backgroundColor": "#ffffff"
23+
}
24+
},
25+
"web": {
26+
"bundler": "metro",
27+
"output": "static",
28+
"favicon": "./assets/images/rnllama.png"
29+
},
30+
"plugins": [
31+
"expo-router",
32+
[
33+
"expo-document-picker",
34+
{
35+
"iCloudContainerEnvironment": "Production"
36+
}
37+
]
38+
],
39+
"experiments": {
40+
"typedRoutes": true
41+
}
42+
}
43+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Stack } from "expo-router";
2+
3+
export default function RootLayout() {
4+
return <Stack screenOptions={{ headerShown: false }} />;
5+
}

0 commit comments

Comments
 (0)