-
Notifications
You must be signed in to change notification settings - Fork 96
[RNE Rewrite] docs: rewrite documentation #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rne-rewrite
Are you sure you want to change the base?
Changes from all commits
12ee8f8
2672dc3
7116bd3
e0e94a3
ee28c00
3c8137d
a698246
a7de483
0dbc21b
612c184
e9028af
dbd1e9b
2823653
20b746d
2d9c4a5
6250979
6f51a42
cbee144
35b96c2
0c01f26
785b6fd
4ed5008
06a35a9
8a7e18b
0dc5653
345afd7
dc245f5
3626481
5c47c7c
9fe96b7
05e8232
d13d663
c996a90
e91643b
a811df6
08162a5
8811681
ba98692
6f363b6
e85d538
08950b6
c875d7d
7a98fbf
838a3a2
c7bc5e5
e5c7739
9b1e138
76d53c9
519c59c
d2ce8cb
9650d88
e315b3b
ed801a5
c1a3f5d
7e28a84
d5a5f9e
8efba4c
6cbfe81
4449b04
fef4d85
63ec438
6da98c4
c07bd85
c269df0
bb6b56a
f511c4e
bfcbd1f
f219284
c13bf4f
b93bc55
4f5fe18
96a1940
1de87be
825c70e
dc5ab31
57f7c92
67b986f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| *.pbxproj -text | ||
| # specific for windows script files | ||
| *.bat text eol=crlf | ||
| *.bat text eol=crlf | ||
|
|
||
| # Linguist vendoring for accurate language statistics and cloc | ||
| third-party/** linguist-vendored | ||
| **/third-party/** linguist-vendored | ||
| packages/react-native-executorch/third-party/** linguist-vendored | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| --- | ||
| title: Downloading Models | ||
| slug: /fundamentals/downloading-models | ||
| description: 'How model files reach the device — the pre-exported model registry, automatic download and caching in hooks, and the imperative download API with progress and cancellation.' | ||
| keywords: | ||
| [ | ||
| react native executorch, | ||
| download model, | ||
| model cache, | ||
| useResourceDownload, | ||
| download, | ||
| on-device ai, | ||
| pte, | ||
| ] | ||
| --- | ||
|
|
||
| # Downloading Models | ||
|
|
||
| A model is one or more files — the `.pte` program, and often a tokenizer, | ||
| phonemizer, or label map alongside it — that have to be present on the device | ||
| before inference can run. React Native ExecuTorch downloads those files for you | ||
| and caches them persistently, so in most apps you never touch the filesystem | ||
| directly: you point a pipeline at a model and the library fetches whatever isn't | ||
| already cached. | ||
|
|
||
| ## Where models come from | ||
|
|
||
| A model source is either remote or local: | ||
|
|
||
| - **Pre-exported models** live in our | ||
| [HuggingFace collection](https://huggingface.co/software-mansion/collections) and | ||
| are addressed through the | ||
| [`models`](../06-api-reference/variables/models.md) registry. Each entry bundles | ||
| every file a pipeline needs behind one object — for example | ||
| `models.classification.EFFICIENTNET_V2_S.XNNPACK_FP32` resolves to the model and | ||
| its label assets. This registry is the single source of truth for the tuned, | ||
| ready-to-run models. | ||
| - **Your own models** are plain URLs or local paths — a file bundled with the app, | ||
| a `file://` path, or a URL on your own host — as long as the model's schema | ||
| matches the pipeline (see | ||
| [Exporting Custom Models](../03-core-and-advanced/07-exporting-custom-models.md)). | ||
|
|
||
| Local paths are always passed through untouched; only `http(s)` URLs are ever | ||
| downloaded. | ||
|
|
||
| ## Automatic downloading with hooks | ||
|
|
||
| The `use<Task>` hooks and the | ||
| [`useResourceDownload`](../06-api-reference/functions/useResourceDownload.md) hook | ||
| download and cache a model's files automatically. Pass a config; the hook fetches | ||
| anything not already cached, reports progress, and hands back the same config with | ||
| every URL replaced by its local path. | ||
|
|
||
| ```typescript | ||
| import { useResourceDownload, models } from 'react-native-executorch'; | ||
|
|
||
| function Example() { | ||
| const { resource, downloadProgress, downloadError } = useResourceDownload( | ||
| models.classification.EFFICIENTNET_V2_S.XNNPACK_FP32 | ||
| ); | ||
|
|
||
| // resource is undefined until the download resolves, then mirrors the config | ||
| // with local file paths, ready to hand to a pipeline. | ||
| } | ||
| ``` | ||
|
|
||
| Both hooks accept | ||
| [`ResourceOptions`](../06-api-reference/type-aliases/ResourceOptions.md): | ||
|
|
||
| - **`preventLoad`** — skip the download entirely (and reset state), for deferring a | ||
| fetch until the user opts in. | ||
| - **`forceDownload`** — re-fetch even when cached, to replace a corrupted file or | ||
| pick up a model that changed behind a stable URL. | ||
|
|
||
| ## Imperative downloading | ||
|
|
||
| When you're not in a component — a background task, a custom pipeline, a | ||
| preloading step — use the imperative | ||
| [`download`](../06-api-reference/functions/download.md) function. It takes a URL, | ||
| or any nested object/array of them (typically a whole model config), downloads | ||
| every remote leaf, and resolves with the same value with URLs replaced by local | ||
| paths — ready to pass straight to a `create<Task>` factory: | ||
|
|
||
| ```typescript | ||
| import { download, models } from 'react-native-executorch'; | ||
|
|
||
| const model = await download(models.classification.EFFICIENTNET_V2_S.XNNPACK_FP32, { | ||
| onProgress: (p) => console.log(`${Math.round(p * 100)}%`), | ||
| }); | ||
|
|
||
| // `model` now holds local paths; hand it to a pipeline factory | ||
| ``` | ||
|
|
||
| [`DownloadOptions`](../06-api-reference/interfaces/DownloadOptions.md) covers the | ||
| common needs: | ||
|
|
||
| - **`onProgress(p)`** — overall progress in `[0, 1]`, weighted by each file's byte | ||
| size so a large model isn't reported the same as a small tokenizer. | ||
| - **`signal`** — an `AbortSignal` to cancel. On iOS the bytes fetched so far are | ||
| kept, so a later download of the same source resumes rather than restarts. | ||
| - **`forceDownload`** — re-download even when cached. | ||
|
|
||
| ## Caching behavior | ||
|
|
||
| Downloads go to a persistent cache keyed by URL, and this is what keeps repeat | ||
| launches fast: | ||
|
|
||
| - A file that is already cached resolves immediately — no network round trip. | ||
| - Concurrent downloads of the same URL are deduplicated into one transfer. | ||
| - On Android, fetching goes through the system DownloadManager, which handles | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS background continuation needs the optional |
||
| multi-gigabyte files and continues in the background; on iOS it streams and | ||
| resumes an interrupted download from where it stopped. | ||
|
|
||
| Use `forceDownload` to bypass the cache and replace a file. Otherwise, downloading | ||
| the same model again is effectively free. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| ## Where to go next | ||
|
|
||
| - [Getting Started](./01-getting-started.md) — install the library and run your first model. | ||
| - [Exporting Custom Models](../03-core-and-advanced/07-exporting-custom-models.md) — bring your own `.pte` and match a pipeline. | ||
| - [Models & Tensors](../03-core-and-advanced/02-models-and-tensors.md) — load a downloaded `.pte` directly with the lower-level API. | ||
|
|
||
| ### API reference | ||
|
|
||
| - [`download()`](../06-api-reference/functions/download.md) · [`DownloadOptions`](../06-api-reference/interfaces/DownloadOptions.md) | ||
| - [`useResourceDownload()`](../06-api-reference/functions/useResourceDownload.md) · [`ResourceOptions`](../06-api-reference/type-aliases/ResourceOptions.md) | ||
| - [`models`](../06-api-reference/variables/models.md) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**/third-party/**already covers both other rules. Also still no trailing newline, and this is unrelated to a docs PR.