[RNE Rewrite] feat!: add classification task and common utilities for manipulating tensors in CV tasks#1264
Merged
Merged
Conversation
…extension sources in build files
…age preprocessing
…e classification task
…ourceDownload, and register public exports
…amelCase in ESLint
Align native extensions with the add-native-extension guideline: - sigmoid: use the precomputed src->numel_ instead of recomputing the element count via std::accumulate; drop the now-unused <numeric>. - softmax/argmax: require axis (count == 3) instead of defaulting to -1 in C++; defaults belong in the TS wrapper layer. argmax now validates args[2].isNumber() (parity with softmax) and registers with arity 3. - normalize: drop misleading "default" init for the required alpha/beta coefficients. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Download to a .partial temp file and promote it to the final cache path only after the transfer succeeds. Previously an interrupted download left a truncated file that a later run treated as a valid cache hit, loading a corrupt .pte. Also treat HTTP >= 400 as a failure (RNFS.downloadFile resolves on 4xx/5xx) and unlink the partial file on any error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Surface the resize pad value through the preprocessor options so letterbox consumers can configure it instead of being stuck with black padding. Optional; the resize wrapper defaults it to 0. Switch the resize wrapper to per-key nullish defaults so an explicit `padValue: undefined` falls back to the default instead of clobbering it through object spread (the native op requires padValue unconditionally). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was
linked to
issues
Jun 18, 2026
msluszniak
reviewed
Jun 19, 2026
msluszniak
left a comment
Member
There was a problem hiding this comment.
Maybe we change example app icon to something meaningful for CV, I thought about it for our current apps, but haven't executed eventually.
msluszniak
reviewed
Jun 19, 2026
…anonymous namespaces
…::fill, and clean up loop/dimension types
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Each useResourceDownload instance now writes to a unique .partial file so concurrent downloads of the same source no longer clobber a shared temp file. The moveFile call is guarded so a download that loses the race to an identical file already at the destination (iOS moveFile throws when dest exists) is treated as success instead of surfacing a spurious error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Contributor
Author
|
Regarding example apps visual aspects, we can open an issue regarding the general overhaul of example apps, but I don't think it is a priority right now. |
Member
Agreed. Let me do another quick pass over the code ;) |
msluszniak
reviewed
Jun 19, 2026
msluszniak
reviewed
Jun 19, 2026
msluszniak
reviewed
Jun 19, 2026
msluszniak
reviewed
Jun 19, 2026
Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
msluszniak
approved these changes
Jun 19, 2026
This was referenced Jun 19, 2026
12 tasks
14 tasks
msluszniak
added a commit
that referenced
this pull request
Jun 23, 2026
## Description Adds the tokenizer pipeline (issue #1248) using the new worklet-based architecture, with functional parity to the current `TokenizerModule`. A new `nlp` extension exposes a `loadTokenizer` JSI primitive (top-level on `__rnexecutorch_jsi__`, like `loadModel`) returning a `Tokenizer` host object backed by `tokenizers::HFTokenizer`. On top of it sits a `createTokenizer(config, runtime?)` async factory (async + `*Worklet` variants + `dispose`) and a `useTokenizer` hook. Methods: `encode`, `decode`, `getVocabSize`, `idToToken`, `tokenToId` — same semantics as today (special tokens follow the `tokenizer.json` post_processor). The `*Worklet` variants let an upcoming text-embeddings task tokenize → build tensors → run forward within a single worklet. - C++: `cpp/extensions/nlp/{tokenizer,install}.{h,cpp}`, wired into `RnExecutorch.cpp`. - TS: `src/extensions/nlp/{ops,tasks}/tokenizer.ts`, `src/hooks/useTokenizer.ts`, exports in `index.ts`, example `models.tokenizer.ALL_MINILM_L6_V2`. - Build: tokenizer header-search paths added to `android/CMakeLists.txt` and the podspec — `pytorch/tokenizers/include` plus the bundled libs its public headers pull in (`nlohmann/json`, `re2`, and re2's `abseil` dep). Symbols link from the prebuilt `libexecutorch`. Documented in `third-party/README.md`. - Demo: a dedicated `apps/nlp` example app with a Tokenizer screen that drives the full pipeline on device. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [x] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [ ] Android ### Testing instructions CI is TypeScript-only here (native isn't compiled in CI); `yarn typecheck`, root `yarn lint`, and `yarn prepare` (bob build) all pass. To exercise the native tokenizer end-to-end via the demo app: 1. Provision the ExecuTorch `third-party` artifacts into `packages/react-native-executorch/third-party/` (see `third-party/README.md`). The existing PoC bundle already ships the llm/tokenizers extension (headers + symbols), so no rebuild is needed. 2. `yarn && cd apps/nlp && yarn ios` — the iOS simulator works since the tokenizer is pure CPU (no GPU/Metal). 3. Open the **Tokenizer** screen. It loads `all-MiniLM-L6-v2` and auto-runs `encode` / `decode` / `getVocabSize` / `idToToken` / `tokenToId`, asserting: `encode("Hello world")` = `[7592, 2088]`, `decode` round-trips to `"hello world"`, `getVocabSize()` = `30522`, and `tokenToId(idToToken(id))` is the identity. All three assertions should read **PASS** (also logged as `[TokenizerTest]`). The screen genuinely drives the new code — `useTokenizer` → `createTokenizer` → the `loadTokenizer` JSI primitive → the native `TokenizerHostObject` / `HFTokenizer` — so a green run validates the whole pipeline, not just the types. Verified locally on iOS (iPhone 16 Pro Max, Xcode 26.5): all assertions pass. The `apps/nlp` app is intentionally minimal and exists only to prove this pipeline; it can be dropped after approval if you'd prefer not to keep a demo app in-tree. ### Screenshots ### Related issues #1248, part of #1208 ### 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 ### Additional notes The C++ mirrors the current `TokenizerModule`, which is backed by `pytorch/tokenizers` (`tokenizers::HFTokenizer`) from the ExecuTorch llm/tokenizers extension. This PR consumes the same headers (the third-party bundle under `extension/llm/tokenizers`) and prebuilt symbols (from `libexecutorch`); it does not use the `tokenizers-cpp` submodule. Tokenizer download currently uses the temporary `react-native-fs`-based `useResourceDownload` introduced in #1264 (to be replaced by the ResourceFetcher in #1253).
barhanc
added a commit
that referenced
this pull request
Jun 24, 2026
## Description - Adds semantic segmentation task and required native operations for it. - Adds computer-vision example app screen for semantic segmentation. - Fixes the performance regression in the argmax introduced in #1264. The initial implementation from PoC was more efficient for the default `axis=-1` case as the internal loop was over contiguous elements. The linked PR changed it so that it was more efficient for `axis=0` case, however since the default is `axis=-1` this caused a performance regression in the semantic segmentation task. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [x] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [ ] Other (chores, tests, code style improvements etc.) ### Tested on - [x] iOS - [x] Android ### Testing instructions - [ ] Build the computer-vision example app. - [ ] Test the semantic segmentation screen. <!-- Provide step-by-step instructions on how to test your changes. Include setup details if necessary. --> ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues <!-- Link related issues here using #issue-number --> Closes #1242 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. --> --------- Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds:
useModelanduseResourceDownloadhook which are needed for all modelsIt also introduces some fixes:
Introduces a breaking change?
Type of change
Tested on
Testing instructions
Screenshots
N/A
Related issues
Closes #1237
Closes #1207
Checklist
Additional notes