Skip to content

Commit d79ae01

Browse files
authored
@jakmro/standardize naming (#62)
## Description Standardize naming and fix urls ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [x] Android ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent 1499364 commit d79ae01

File tree

16 files changed

+59
-53
lines changed

16 files changed

+59
-53
lines changed

android/src/main/java/com/swmansion/rnexecutorch/Classification.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Classification(reactContext: ReactApplicationContext) :
3232
classificationModel.loadModel(modelSource)
3333
promise.resolve(0)
3434
} catch (e: Exception) {
35-
promise.reject(e.message!!, ETError.InvalidModelPath.toString())
35+
promise.reject(e.message!!, ETError.InvalidModelSource.toString())
3636
}
3737
}
3838

android/src/main/java/com/swmansion/rnexecutorch/ETModule.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class ETModule(reactContext: ReactApplicationContext) : NativeETModuleSpec(react
1717
return NAME
1818
}
1919

20-
override fun loadModule(modelPath: String, promise: Promise) {
20+
override fun loadModule(modelSource: String, promise: Promise) {
2121
Fetcher.downloadModel(
2222
reactApplicationContext,
23-
modelPath,
23+
modelSource,
2424
) { path, error ->
2525
if (error != null) {
26-
promise.reject(error.message!!, ETError.InvalidModelPath.toString())
26+
promise.reject(error.message!!, ETError.InvalidModelSource.toString())
2727
return@downloadModel
2828
}
2929

android/src/main/java/com/swmansion/rnexecutorch/StyleTransfer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class StyleTransfer(reactContext: ReactApplicationContext) :
3131
styleTransferModel.loadModel(modelSource)
3232
promise.resolve(0)
3333
} catch (e: Exception) {
34-
promise.reject(e.message!!, ETError.InvalidModelPath.toString())
34+
promise.reject(e.message!!, ETError.InvalidModelSource.toString())
3535
}
3636
}
3737

android/src/main/java/com/swmansion/rnexecutorch/utils/ETError.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ enum class ETError(val code: Int) {
44
UndefinedError(0x65),
55
ModuleNotLoaded(0x66),
66
FileWriteFailed(0x67),
7-
InvalidModelPath(0xff),
7+
InvalidModelSource(0xff),
88

99
// System errors
1010
Ok(0x00),

docs/docs/guides/running-llms.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ React Native ExecuTorch supports Llama 3.2 models, including quantized versions.
1414
In order to load a model into the app, you need to run the following code:
1515

1616
```typescript
17-
import { useLLM, LLAMA3_2_1B_URL } from 'react-native-executorch';
17+
import { useLLM, LLAMA3_2_1B } from 'react-native-executorch';
1818

1919
const llama = useLLM({
20-
modelSource: LLAMA3_2_1B_URL,
20+
modelSource: LLAMA3_2_1B,
2121
tokenizer: require('../assets/tokenizer.bin'),
2222
contextWindowLength: 3,
2323
});
@@ -91,7 +91,7 @@ In order to send a message to the model, one can use the following code:
9191

9292
```typescript
9393
const llama = useLLM(
94-
modelSource: LLAMA3_2_1B_URL,
94+
modelSource: LLAMA3_2_1B,
9595
tokenizer: require('../assets/tokenizer.bin'),
9696
);
9797

examples/computer-vision/screens/ClassificationScreen.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const ClassificationScreen = ({
1717
);
1818

1919
const model = useClassification({
20-
modulePath: EFFICIENTNET_V2_S,
20+
modelSource: EFFICIENTNET_V2_S,
2121
});
2222

2323
const handleCameraPress = async (isCamera: boolean) => {

examples/computer-vision/screens/ObjectDetectionScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getImage } from '../utils';
55
import {
66
Detection,
77
useObjectDetection,
8-
SSDLITE_320_MOBILENET_V3_LARGE_URL,
8+
SSDLITE_320_MOBILENET_V3_LARGE,
99
} from 'react-native-executorch';
1010
import { View, StyleSheet, Image } from 'react-native';
1111
import ImageWithBboxes from '../components/ImageWithBboxes';
@@ -24,7 +24,7 @@ export const ObjectDetectionScreen = ({
2424
}>();
2525

2626
const ssdLite = useObjectDetection({
27-
modelSource: SSDLITE_320_MOBILENET_V3_LARGE_URL,
27+
modelSource: SSDLITE_320_MOBILENET_V3_LARGE,
2828
});
2929

3030
const handleCameraPress = async (isCamera: boolean) => {

examples/computer-vision/screens/StyleTransferScreen.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const StyleTransferScreen = ({
1515
setImageUri: (imageUri: string) => void;
1616
}) => {
1717
const model = useStyleTransfer({
18-
modulePath: STYLE_TRANSFER_CANDY,
18+
modelSource: STYLE_TRANSFER_CANDY,
1919
});
2020

2121
const handleCameraPress = async (isCamera: boolean) => {

examples/llama/screens/ChatScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';
1414
import SWMIcon from '../assets/icons/swm_icon.svg';
1515
import SendIcon from '../assets/icons/send_icon.svg';
1616
import Spinner from 'react-native-loading-spinner-overlay';
17-
import { LLAMA3_2_1B_QLORA_URL, useLLM } from 'react-native-executorch';
17+
import { LLAMA3_2_1B_QLORA, useLLM } from 'react-native-executorch';
1818
import PauseIcon from '../assets/icons/pause_icon.svg';
1919
import ColorPalette from '../colors';
2020
import Messages from '../components/Messages';
@@ -25,7 +25,7 @@ export default function ChatScreen() {
2525
const [isTextInputFocused, setIsTextInputFocused] = useState(false);
2626
const [userInput, setUserInput] = useState('');
2727
const llama = useLLM({
28-
modelSource: LLAMA3_2_1B_QLORA_URL,
28+
modelSource: LLAMA3_2_1B_QLORA,
2929
tokenizerSource: require('../assets/tokenizer.bin'),
3030
contextWindowLength: 6,
3131
});

ios/RnExecutorch/models/BaseModel.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ - (void)loadModel:(NSURL *)modelURL completion:(void (^)(BOOL success, NSNumber*
1313
module = [[ETModel alloc] init];
1414
[Fetcher fetchResource:modelURL resourceType:ResourceType::MODEL completionHandler:^(NSString *filePath, NSError *error) {
1515
if (error) {
16-
completion(NO, @(InvalidModelPath));
16+
completion(NO, @(InvalidModelSource));
1717
return;
1818
}
1919
NSNumber *result = [self->module loadModel: filePath];

ios/RnExecutorch/utils/ETError.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ typedef NS_ENUM(NSUInteger, ETError) {
22
UndefinedError = 0x65,
33
ModuleNotLoaded = 0x66,
44
FileWriteFailed = 0x67,
5-
InvalidModelPath = 0xff,
5+
InvalidModelSource = 0xff,
66

77
Ok = 0x00,
88
Internal = 0x01,

src/ETModule.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ const getTypeIdentifier = (arr: ETInput): number => {
1515
};
1616

1717
interface Props {
18-
modulePath: string | number;
18+
modelSource: string | number;
1919
}
2020

2121
export const useExecutorchModule = ({
22-
modulePath,
22+
modelSource,
2323
}: Props): ExecutorchModule => {
2424
const [error, setError] = useState<string | null>(null);
2525
const [isModelLoading, setIsModelLoading] = useState(true);
2626
const [isModelGenerating, setIsModelGenerating] = useState(false);
2727

2828
useEffect(() => {
2929
const loadModel = async () => {
30-
let path = modulePath;
31-
if (typeof modulePath === 'number') {
32-
path = Image.resolveAssetSource(modulePath).uri;
30+
let path = modelSource;
31+
if (typeof modelSource === 'number') {
32+
path = Image.resolveAssetSource(modelSource).uri;
3333
}
3434

3535
try {
@@ -42,7 +42,7 @@ export const useExecutorchModule = ({
4242
}
4343
};
4444
loadModel();
45-
}, [modulePath]);
45+
}, [modelSource]);
4646

4747
const forward = async (input: ETInput, shape: number[]) => {
4848
if (isModelLoading) {

src/Error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export enum ETError {
44
ModuleNotLoaded = 0x66,
55
FileWriteFailed = 0x67,
66
ModelGenerating = 0x68,
7-
InvalidModelPath = 0xff,
7+
InvalidModelSource = 0xff,
88

99
// ExecuTorch mapped errors
1010
// Based on: https://github.com/pytorch/executorch/blob/main/runtime/core/error.h

src/StyleTransfer.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { StyleTransfer } from './native/RnExecutorchModules';
44
import { ETError, getError } from './Error';
55

66
interface Props {
7-
modulePath: string | number;
7+
modelSource: string | number;
88
}
99

1010
interface StyleTransferModule {
@@ -15,18 +15,18 @@ interface StyleTransferModule {
1515
}
1616

1717
export const useStyleTransfer = ({
18-
modulePath,
18+
modelSource,
1919
}: Props): StyleTransferModule => {
2020
const [error, setError] = useState<null | string>(null);
2121
const [isModelReady, setIsModelReady] = useState(false);
2222
const [isModelGenerating, setIsModelGenerating] = useState(false);
2323

2424
useEffect(() => {
2525
const loadModel = async () => {
26-
let path = modulePath;
26+
let path = modelSource;
2727

28-
if (typeof modulePath === 'number') {
29-
path = Image.resolveAssetSource(modulePath).uri;
28+
if (typeof modelSource === 'number') {
29+
path = Image.resolveAssetSource(modelSource).uri;
3030
}
3131

3232
try {
@@ -39,7 +39,7 @@ export const useStyleTransfer = ({
3939
};
4040

4141
loadModel();
42-
}, [modulePath]);
42+
}, [modelSource]);
4343

4444
const forward = async (input: string) => {
4545
if (!isModelReady) {

src/constants/modelUrls.ts

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { Platform } from 'react-native';
22

33
// LLM's
4-
export const LLAMA3_2_3B_URL =
4+
export const LLAMA3_2_3B =
55
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-3B/original/llama3_2_3B_bf16.pte';
6-
export const LLAMA3_2_3B_QLORA_URL =
6+
export const LLAMA3_2_3B_QLORA =
77
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-3B/QLoRA/llama3_2-3B_qat_lora.pte';
8-
export const LLAMA3_2_3B_SPINQUANT_URL =
8+
export const LLAMA3_2_3B_SPINQUANT =
99
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-3B/spinquant/llama3_2_3B_spinquant.pte';
10-
export const LLAMA3_2_1B_URL =
10+
export const LLAMA3_2_1B =
1111
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-1B/original/llama3_2_bf16.pte';
12-
export const LLAMA3_2_1B_QLORA_URL =
12+
export const LLAMA3_2_1B_QLORA =
1313
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-1B/QLoRA/llama3_2_qat_lora.pte';
14-
export const LLAMA3_2_1B_SPINQUANT_URL =
14+
export const LLAMA3_2_1B_SPINQUANT =
1515
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-1B/spinquant/llama3_2_spinquant.pte';
1616
export const LLAMA3_2_1B_TOKENIZER =
1717
'https://huggingface.co/software-mansion/react-native-executorch-llama-3.2/resolve/v0.1.0/llama-3.2-1B/original/tokenizer.bin';
@@ -24,26 +24,32 @@ export const EFFICIENTNET_V2_S =
2424
? 'https://huggingface.co/software-mansion/react-native-executorch-efficientnet-v2-s/resolve/v0.2.0/coreml/efficientnet_v2_s_coreml_all.pte'
2525
: 'https://huggingface.co/software-mansion/react-native-executorch-efficientnet-v2-s/resolve/v0.2.0/xnnpack/efficientnet_v2_s_xnnpack.pte';
2626

27+
// Object detection
28+
export const SSDLITE_320_MOBILENET_V3_LARGE =
29+
'https://huggingface.co/software-mansion/react-native-executorch-ssdlite320-mobilenet-v3-large/resolve/v0.2.0/ssdlite320-mobilenetv3-large.pte';
30+
2731
// Style transfer
2832
export const STYLE_TRANSFER_CANDY =
2933
Platform.OS === 'ios'
3034
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-candy/resolve/v0.2.0/coreml/style_transfer_candy_coreml.pte'
3135
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-candy/resolve/v0.2.0/xnnpack/style_transfer_candy_xnnpack.pte';
32-
3336
export const STYLE_TRANSFER_MOSAIC =
3437
Platform.OS === 'ios'
35-
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/main/coreml/style_transfer_mosaic_coreml.pte'
36-
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/main/xnnpack/style_transfer_mosaic_xnnpack.pte';
37-
38+
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/v0.2.0/coreml/style_transfer_mosaic_coreml.pte'
39+
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-mosaic/resolve/v0.2.0/xnnpack/style_transfer_mosaic_xnnpack.pte';
3840
export const STYLE_TRANSFER_RAIN_PRINCESS =
3941
Platform.OS === 'ios'
40-
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/main/coreml/style_transfer_rain_princess_coreml.pte'
41-
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/main/xnnpack/style_transfer_rain_princess_xnnpack.pte';
42+
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/v0.2.0/coreml/style_transfer_rain_princess_coreml.pte'
43+
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-rain-princess/resolve/v0.2.0/xnnpack/style_transfer_rain_princess_xnnpack.pte';
4244
export const STYLE_TRANSFER_UDNIE =
4345
Platform.OS === 'ios'
44-
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/main/coreml/style_transfer_udnie_coreml.pte'
45-
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/main/xnnpack/style_transfer_udnie_xnnpack.pte';
46+
? 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/v0.2.0/coreml/style_transfer_udnie_coreml.pte'
47+
: 'https://huggingface.co/software-mansion/react-native-executorch-style-transfer-udnie/resolve/v0.2.0/xnnpack/style_transfer_udnie_xnnpack.pte';
4648

47-
// Object detection
48-
export const SSDLITE_320_MOBILENET_V3_LARGE_URL =
49-
'https://huggingface.co/software-mansion/react-native-executorch-ssdlite320-mobilenet-v3-large/resolve/main/ssdlite320-mobilenetv3-large.pte';
49+
// Backward compatibility
50+
export const LLAMA3_2_3B_URL = LLAMA3_2_3B;
51+
export const LLAMA3_2_3B_QLORA_URL = LLAMA3_2_3B_QLORA;
52+
export const LLAMA3_2_3B_SPINQUANT_URL = LLAMA3_2_3B_SPINQUANT;
53+
export const LLAMA3_2_1B_URL = LLAMA3_2_1B;
54+
export const LLAMA3_2_1B_QLORA_URL = LLAMA3_2_1B_QLORA;
55+
export const LLAMA3_2_1B_SPINQUANT_URL = LLAMA3_2_1B_SPINQUANT;

src/models/Classification.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Classification } from '../native/RnExecutorchModules';
44
import { ETError, getError } from '../Error';
55

66
interface Props {
7-
modulePath: string | number;
7+
modelSource: string | number;
88
}
99

1010
interface ClassificationModule {
@@ -15,18 +15,18 @@ interface ClassificationModule {
1515
}
1616

1717
export const useClassification = ({
18-
modulePath,
18+
modelSource,
1919
}: Props): ClassificationModule => {
2020
const [error, setError] = useState<null | string>(null);
2121
const [isModelReady, setIsModelReady] = useState(false);
2222
const [isModelGenerating, setIsModelGenerating] = useState(false);
2323

2424
useEffect(() => {
2525
const loadModel = async () => {
26-
let path = modulePath;
26+
let path = modelSource;
2727

28-
if (typeof modulePath === 'number') {
29-
path = Image.resolveAssetSource(modulePath).uri;
28+
if (typeof modelSource === 'number') {
29+
path = Image.resolveAssetSource(modelSource).uri;
3030
}
3131

3232
try {
@@ -40,7 +40,7 @@ export const useClassification = ({
4040
};
4141

4242
loadModel();
43-
}, [modulePath]);
43+
}, [modelSource]);
4444

4545
const forward = async (input: string) => {
4646
if (!isModelReady) {

0 commit comments

Comments
 (0)