Skip to content

Commit 8978751

Browse files
authored
Merge branch 'main' into @ms/add-lfm2.5-instruct
2 parents 9a1a04e + bda1494 commit 8978751

338 files changed

Lines changed: 6765 additions & 1375 deletions

File tree

Some content is hidden

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

.cspell-wordlist.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ microcontrollers
2121
notimestamps
2222
seqs
2323
smollm
24+
llms
2425
qwen
2526
XNNPACK
2627
EFFICIENTNET
@@ -111,4 +112,7 @@ logprob
111112
RNFS
112113
pogodin
113114
kesha
114-
antonov
115+
antonov
116+
rfdetr
117+
basemodule
118+
IMAGENET
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Check if API reference is up-to-date
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docs/**'
9+
- 'packages/react-native-executorch/src/**'
10+
- '.github/workflows/api-reference-up-to-date-check.yml'
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- 'docs/**'
16+
- 'packages/react-native-executorch/src/**'
17+
- '.github/workflows/api-reference-up-to-date-check.yml'
18+
workflow_dispatch:
19+
jobs:
20+
check:
21+
if: github.repository == 'software-mansion/react-native-executorch'
22+
runs-on: ubuntu-latest
23+
concurrency:
24+
group: api-reference-up-to-date-${{ github.ref }}
25+
cancel-in-progress: true
26+
env:
27+
WORKING_DIRECTORY: docs
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v3
31+
with:
32+
ref: ${{ github.event.pull_request.head.sha }}
33+
- name: Use Node.js 20
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 20
37+
- name: Install root dependencies
38+
run: yarn install --immutable
39+
- name: Install node docs dependencies
40+
working-directory: ${{ env.WORKING_DIRECTORY }}
41+
run: yarn install --immutable
42+
- name: Check TypeDoc is up-to-date
43+
working-directory: ${{ env.WORKING_DIRECTORY }}
44+
run: |
45+
yarn docusaurus generate-typedoc
46+
yarn prettier-api-reference
47+
git status
48+
git diff
49+
if ! git diff --quiet; then
50+
echo "Differences found. Look at the 'git diff' output above."
51+
exit 1
52+
fi

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The release process of new minor version consists of the following steps:
1010
4. Create a new release branch `release/{MAJOR}.{MINOR}`and push it to the remote.
1111
5. Stability tests are performed on the release branch and all fixes to the new-found issues are pushed into the main branch and cherry-picked into the release branch. This allows for further development on the main branch without interfering with the release process.
1212
6. Once all tests are passed, tag the release branch with proper version tag `v{MAJOR}.{MINOR}.0` and run `npm publish`.
13-
7. Create versioned docs by running from repo root `(cd docs && yarn docusaurus docs:version {MAJOR}.{MINOR}.x)` (the 'x' part is intentional and is not to be substituted). Also, make sure that all the links in `api-reference` are not broken.
13+
7. Create versioned docs by running from repo root `(cd docs && yarn docs:version {MAJOR}.{MINOR}.x)` (the 'x' part is intentional and is not to be substituted). Also, make sure that all the links in `api-reference` are not broken.
1414
8. Create a PR with the updated docs.
1515
9. Create the release notes on GitHub.
1616
10. Update README.md with release video, if available.

apps/computer-vision/app/image_segmentation/index.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import Spinner from '../../components/Spinner';
22
import { BottomBar } from '../../components/BottomBar';
33
import { getImage } from '../../utils';
44
import {
5-
useImageSegmentation,
65
DEEPLAB_V3_RESNET50,
7-
DeeplabLabel,
6+
useImageSegmentation,
87
} from 'react-native-executorch';
98
import {
109
Canvas,
@@ -44,16 +43,20 @@ const numberToColor: number[][] = [
4443
];
4544

4645
export default function ImageSegmentationScreen() {
47-
const model = useImageSegmentation({ model: DEEPLAB_V3_RESNET50 });
4846
const { setGlobalGenerating } = useContext(GeneratingContext);
49-
useEffect(() => {
50-
setGlobalGenerating(model.isGenerating);
51-
}, [model.isGenerating, setGlobalGenerating]);
47+
const { isReady, isGenerating, downloadProgress, forward } =
48+
useImageSegmentation({
49+
model: DEEPLAB_V3_RESNET50,
50+
});
5251
const [imageUri, setImageUri] = useState('');
5352
const [imageSize, setImageSize] = useState({ width: 0, height: 0 });
5453
const [segImage, setSegImage] = useState<SkImage | null>(null);
5554
const [canvasSize, setCanvasSize] = useState({ width: 0, height: 0 });
5655

56+
useEffect(() => {
57+
setGlobalGenerating(isGenerating);
58+
}, [isGenerating, setGlobalGenerating]);
59+
5760
const handleCameraPress = async (isCamera: boolean) => {
5861
const image = await getImage(isCamera);
5962
if (!image?.uri) return;
@@ -69,12 +72,8 @@ export default function ImageSegmentationScreen() {
6972
if (!imageUri || imageSize.width === 0 || imageSize.height === 0) return;
7073
try {
7174
const { width, height } = imageSize;
72-
const output = await model.forward(imageUri, [DeeplabLabel.ARGMAX]);
73-
const argmax = output[DeeplabLabel.ARGMAX] || [];
74-
const uniqueValues = new Set<number>();
75-
for (let i = 0; i < argmax.length; i++) {
76-
uniqueValues.add(argmax[i]);
77-
}
75+
const output = await forward(imageUri, [], true);
76+
const argmax = output.ARGMAX || [];
7877
const pixels = new Uint8Array(width * height * 4);
7978

8079
for (let row = 0; row < height; row++) {
@@ -105,11 +104,11 @@ export default function ImageSegmentationScreen() {
105104
}
106105
};
107106

108-
if (!model.isReady) {
107+
if (!isReady) {
109108
return (
110109
<Spinner
111-
visible={!model.isReady}
112-
textContent={`Loading the model ${(model.downloadProgress * 100).toFixed(0)} %`}
110+
visible={!isReady}
111+
textContent={`Loading the model ${(downloadProgress * 100).toFixed(0)} %`}
113112
/>
114113
);
115114
}

docs/docs/03-hooks/01-natural-language-processing/useLLM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ To configure model (i.e. change system prompt, load initial conversation history
192192

193193
- [`initialMessageHistory`](../../06-api-reference/interfaces/ChatConfig.md#initialmessagehistory) - Object that represent the conversation history. This can be used to provide initial context to the model.
194194

195-
- [`contextWindowLength`](../../06-api-reference/interfaces/ChatConfig.md#contextwindowlength) - The number of messages from the current conversation that the model will use to generate a response. Keep in mind that using larger context windows will result in longer inference time and higher memory usage.
195+
- [`contextStrategy`](../../06-api-reference/interfaces/ChatConfig.md#contextstrategy) - Object implementing [`ContextStrategy`](../../06-api-reference/interfaces/ContextStrategy.md) interface used to manage conversation context, including trimming history if necessary. Custom strategies can be implemented or one of the built-in options can be used (e.g. [`NoopContextStrategy`](../../06-api-reference/classes/NoopContextStrategy.md), [`MessageCountContextStrategy`](../../06-api-reference/classes/MessageCountContextStrategy.md) or the default [`SlidingWindowContextStrategy`](../../06-api-reference/classes/SlidingWindowContextStrategy.md)).
196196

197197
- [`toolsConfig`](../../06-api-reference/interfaces/LLMConfig.md#toolsconfig) - Object configuring options for enabling and managing tool use. **It will only have effect if your model's chat template support it**. Contains following properties:
198198
- [`tools`](../../06-api-reference/interfaces/ToolsConfig.md#tools) - List of objects defining tools.

docs/docs/03-hooks/02-computer-vision/useImageSegmentation.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import {
2121
DEEPLAB_V3_RESNET50,
2222
} from 'react-native-executorch';
2323

24-
const model = useImageSegmentation({ model: DEEPLAB_V3_RESNET50 });
24+
const model = useImageSegmentation({
25+
model: DEEPLAB_V3_RESNET50,
26+
});
2527

2628
const imageUri = 'file::///Users/.../cute_cat.png';
2729

2830
try {
29-
const outputDict = await model.forward(imageUri);
31+
const result = await model.forward(imageUri);
32+
// result.ARGMAX is an Int32Array of per-pixel class indices
3033
} catch (error) {
3134
console.error(error);
3235
}
@@ -36,9 +39,13 @@ try {
3639

3740
`useImageSegmentation` takes [`ImageSegmentationProps`](../../06-api-reference/interfaces/ImageSegmentationProps.md) that consists of:
3841

39-
- `model` containing [`modelSource`](../../06-api-reference/interfaces/ImageSegmentationProps.md#modelsource).
42+
- `model` - An object containing:
43+
- `modelName` - The name of a built-in model. See [`ModelSources`](../../06-api-reference/type-aliases/ModelSources.md) for the list of supported models.
44+
- `modelSource` - The location of the model binary (a URL or a bundled resource).
4045
- An optional flag [`preventLoad`](../../06-api-reference/interfaces/ImageSegmentationProps.md#preventload) which prevents auto-loading of the model.
4146

47+
The hook is generic over the model config — TypeScript automatically infers the correct label type based on the `modelName` you provide. No explicit generic parameter is needed.
48+
4249
You need more details? Check the following resources:
4350

4451
- For detailed information about `useImageSegmentation` arguments check this section: [`useImageSegmentation` arguments](../../06-api-reference/functions/useImageSegmentation.md#parameters).
@@ -47,45 +54,70 @@ You need more details? Check the following resources:
4754

4855
### Returns
4956

50-
`useImageSegmentation` returns an object called `ImageSegmentationType` containing bunch of functions to interact with image segmentation models. To get more details please read: [`ImageSegmentationType` API Reference](../../06-api-reference/interfaces/ImageSegmentationType.md).
57+
`useImageSegmentation` returns an [`ImageSegmentationType`](../../06-api-reference/interfaces/ImageSegmentationType.md) object containing:
58+
59+
- `isReady` - Whether the model is loaded and ready to process images.
60+
- `isGenerating` - Whether the model is currently processing an image.
61+
- `error` - An error object if the model failed to load or encountered a runtime error.
62+
- `downloadProgress` - A value between 0 and 1 representing the download progress of the model binary.
63+
- `forward` - A function to run inference on an image.
5164

5265
## Running the model
5366

54-
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) method. It accepts three arguments: a required image - can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64), an optional list of classes, and an optional flag whether to resize the output to the original dimensions.
67+
To run the model, use the [`forward`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) method. It accepts three arguments:
5568

56-
- The image can be a remote URL, a local file URI, or a base64-encoded image.
57-
- The [`classesOfInterest`](../../06-api-reference/interfaces/ImageSegmentationType.md#classesofinterest) list contains classes for which to output the full results. By default the list is empty, and only the most probable classes are returned (essentially an arg max for each pixel). Look at [`DeeplabLabel`](../../06-api-reference/enumerations/DeeplabLabel.md) enum for possible classes.
58-
- The [`resizeToInput`](../../06-api-reference/interfaces/ImageSegmentationType.md#resizetoinput) flag specifies whether the output will be rescaled back to the size of the input image. The default is `true`. The model runs inference on a scaled (probably smaller) version of your image (224x224 for `DEEPLAB_V3_RESNET50`). If you choose to resize, the output will be `number[]` of size `width * height` of your original image.
69+
- [`imageSource`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) (required) - The image to segment. Can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64).
70+
- [`classesOfInterest`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) (optional) - An array of label keys indicating which per-class probability masks to include in the output. Defaults to `[]` (no class masks). The `ARGMAX` map is always returned regardless of this parameter.
71+
- [`resizeToInput`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) (optional) - Whether to resize the output masks to the original input image dimensions. Defaults to `true`. If `false`, returns the raw model output dimensions (e.g. 224x224 for `DEEPLAB_V3_RESNET50`).
5972

6073
:::warning
6174
Setting `resizeToInput` to `false` will make `forward` faster.
6275
:::
6376

64-
[`forward`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) returns a promise which can resolve either to an error or a dictionary containing number arrays with size depending on [`resizeToInput`](../../06-api-reference/interfaces/ImageSegmentationType.md#resizetoinput):
77+
`forward` returns a promise resolving to an object containing:
78+
79+
- `ARGMAX` - An `Int32Array` where each element is the class index with the highest probability for that pixel.
80+
- For each label included in `classesOfInterest`, a `Float32Array` of per-pixel probabilities for that class.
6581

66-
- For the key [`DeeplabLabel.ARGMAX`](../../06-api-reference/enumerations/DeeplabLabel.md#argmax) the array contains for each pixel an integer corresponding to the class with the highest probability.
67-
- For every other key from [`DeeplabLabel`](../../06-api-reference/enumerations/DeeplabLabel.md), if the label was included in [`classesOfInterest`](../../06-api-reference/interfaces/ImageSegmentationType.md#classesofinterest) the dictionary will contain an array of floats corresponding to the probability of this class for every pixel.
82+
The return type is fully typed — TypeScript narrows it based on the labels you pass in `classesOfInterest`.
6883

6984
## Example
7085

7186
```typescript
87+
import {
88+
useImageSegmentation,
89+
DEEPLAB_V3_RESNET50,
90+
DeeplabLabel,
91+
} from 'react-native-executorch';
92+
7293
function App() {
73-
const model = useImageSegmentation({ model: DEEPLAB_V3_RESNET50 });
94+
const model = useImageSegmentation({
95+
model: DEEPLAB_V3_RESNET50,
96+
});
7497

75-
// ...
76-
const imageUri = 'file::///Users/.../cute_cat.png';
98+
const handleSegment = async () => {
99+
if (!model.isReady) return;
100+
101+
const imageUri = 'file::///Users/.../cute_cat.png';
102+
103+
try {
104+
const result = await model.forward(imageUri, ['CAT', 'PERSON'], true);
105+
106+
// result.ARGMAX — Int32Array of per-pixel class indices
107+
// result.CAT — Float32Array of per-pixel probabilities for CAT
108+
// result.PERSON — Float32Array of per-pixel probabilities for PERSON
109+
} catch (error) {
110+
console.error(error);
111+
}
112+
};
77113

78-
try {
79-
const outputDict = await model.forward(imageUri, [DeeplabLabel.CAT], true);
80-
} catch (error) {
81-
console.error(error);
82-
}
83114
// ...
84115
}
85116
```
86117

87118
## Supported models
88119

89-
| Model | Number of classes | Class list |
90-
| ------------------------------------------------------------------------------------------------ | ----------------- | ------------------------------------------------------------------- |
91-
| [deeplabv3_resnet50](https://huggingface.co/software-mansion/react-native-executorch-deeplab-v3) | 21 | [DeeplabLabel](../../06-api-reference/enumerations/DeeplabLabel.md) |
120+
| Model | Number of classes | Class list |
121+
| ------------------------------------------------------------------------------------------------ | ----------------- | ----------------------------------------------------------------------------------------- |
122+
| [deeplabv3_resnet50](https://huggingface.co/software-mansion/react-native-executorch-deeplab-v3) | 21 | [DeeplabLabel](../../06-api-reference/enumerations/DeeplabLabel.md) |
123+
| selfie-segmentation | 2 | [SelfieSegmentationLabel](../../06-api-reference/enumerations/SelfieSegmentationLabel.md) |

docs/docs/04-typescript-api/01-natural-language-processing/LLMModule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ To configure model (i.e. change system prompt, load initial conversation history
9696

9797
- [`initialMessageHistory`](../../06-api-reference/interfaces/ChatConfig.md#initialmessagehistory) - Object that represent the conversation history. This can be used to provide initial context to the model.
9898

99-
- [`contextWindowLength`](../../06-api-reference/interfaces/ChatConfig.md#contextwindowlength) - The number of messages from the current conversation that the model will use to generate a response. Keep in mind that using larger context windows will result in longer inference time and higher memory usage.
99+
- [`contextStrategy`](../../06-api-reference/interfaces/ChatConfig.md#contextstrategy) - Object implementing [`ContextStrategy`](../../06-api-reference/interfaces/ContextStrategy.md) interface used to manage conversation context, including trimming history if necessary. Custom strategies can be implemented or one of the built-in options can be used (e.g. [`NoopContextStrategy`](../../06-api-reference/classes/NoopContextStrategy.md), [`MessageCountContextStrategy`](../../06-api-reference/classes/MessageCountContextStrategy.md) or the default [`SlidingWindowContextStrategy`](../../06-api-reference/classes/SlidingWindowContextStrategy.md)).
100100

101101
- [`toolsConfig`](../../06-api-reference/interfaces/ToolsConfig.md) - Object configuring options for enabling and managing tool use. **It will only have effect if your model's chat template support it**. Contains following properties:
102102
- [`tools`](../../06-api-reference/interfaces/ToolsConfig.md#tools) - List of objects defining tools.

0 commit comments

Comments
 (0)