feat(core,llm): support ArrayBuffer, custom ModelDataLoader, and external .ptd weights in loadModel
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 1/100
- Type d'issue
- Fonctionnalité
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- pytorch, react-native, typescript
Piste de recherche
The issue identifies src/core/model.ts and the LLM runner, task, hook, and model loading APIs as the main entry points. Start by reviewing the linked PR #1630 and its tests to see the implementation scope and expected behavior. Done means the proposed model sources and external weight loading work through the core and LLM APIs, with the cited tests and documentation updates.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Problem description
loadModel(modelPath, options) and the LLM task APIs (createLLMRunner, createLLMChatSession, createLLMTranslator, useLLMChatSession) currently require a plain local .pte file path on disk and do not expose ExecuTorch's data_map_loader for separated .ptd weight archives.
This blocks three common production use cases:
- In-memory models (
ArrayBuffer): loading small.pteprograms directly from memory without writing a temporary file to disk. - Separated
.ptdexternal weight archives: ExecuTorch supports exporting a small.pteprogram alongside an external.ptdnamed-data archive (Module(data_loader, ..., data_map_loader)), where backend delegates such as XNNPACK unpack named weight segments during method initialization and immediately free the source buffers. - Chunked / on-demand loading (
DataLoader): apps that store models in custom containers or encrypted chunks cannot materialize a 200 MB–2 GB model into a temporary plaintext file or a single full-fileArrayBufferwithout doubling peak/steady-state resident memory. They need a random-access loader (size()+load(offset, size)) so ExecuTorch only requests the byte ranges it needs and frees eachFreeableBuffersegment as soon as the backend unpacks it.
Proposed solution
Extend the core loadModel primitive and thread it through the LLM runner/task layer while staying 100% backward-compatible with existing path-based callers:
- Add
ModelDataLoaderandModelSourceinsrc/core/model.ts:export type ModelDataLoader = { size(): number; load(offset: number, size: number): ArrayBuffer; }; export type ModelSource = string | ArrayBuffer | ModelDataLoader; - Extend
LoadModelOptionsandloadModel:export type LoadModelOptions = { readonly eagerLoadMethods?: boolean; readonly dataMapPath?: ModelSource; }; export function loadModel(modelSource: ModelSource, options?: LoadModelOptions): Model;stringcontinues to useMmapDataLoader(NoMlock).ArrayBufferuses a 64-byte-aligned owningBufferDataLoader(model.path === '<buffer>').ModelDataLoaderuses a JSI-backedDataLoader(model.path === '<loader>') that returns 64-byte-alignedFreeableBuffers with a deallocation callback so ExecuTorch frees each segment once unpacked, and detaches its JS function/runtime handles beforeloadModel()returns so nojsi::Runtime*or JS closure outlives the load call.
- Thread
ModelSourceanddataMapPaththrough LLM APIs & hooks:createLLMRunner(modelPath: ModelSource, tokenizerPath: string, modalities?, runtime?, options?: LoadModelOptions)LLMModel<TSource extends ModelSource = string>(defaulting tostringsomodels.llm.*registry entries remain typed asstringURLs, whilecreateLLMChatSession,createLLMTranslator, anduseLLMChatSessionacceptModelSourceanddataMapPath).- Preserve
ArrayBufferandModelDataLoaderreference identity inuseModelanduseResourceDownloadconfig memoization, and skipModelDataLoaderobjects indownload()traversal.
Alternative solutions
- Writing temporary
.pte/.ptdfiles to disk before callingloadModel(path): undesirable for encrypted/protected model assets (writes plaintext weights to flash storage) and adds unnecessary disk I/O and storage pressure. - Passing only whole
ArrayBuffers: works for small.pteprograms, but for large models it keeps a full copy of the raw weights in memory alongside the backend's packed weights (~170+ MB extra RSS on a 180 MB model). Supporting bothArrayBufferandModelDataLoaderplus.ptdexternal weights lets XNNPACK free each weight segment right after packing.
Benefits to React Native ExecuTorch
- Unlocks separated
.ptdweight archives (data_map_loader) acrossloadModeland LLM tasks. - Enables zero-temp-file in-memory loading (
ArrayBuffer) and low-memory streaming/chunked loading (ModelDataLoader) for custom asset containers or encrypted models. - Lives cleanly in
core/modelwith no breaking changes to existing APIs ormodelsregistry types.
Additional context
I have opened PR #1630 implementing this with host C++ GoogleTest (ModelTest), Jest API tests, and documentation updates.
- Langage dominant
- TypeScript
- Étoiles
- 1.8k
- Forks
- 101
- Merge moyen
- 1 j 10 h
- PR mergées (30 j)
- 51
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de software-mansion/react-native-executorch
-
Require react-native-blob-util >=1.0.0 (Xcode 27 iOS build failure)Peut-être pris @msluszniak l’a pris il y a 5 jours. Ouvertedependencies platform: ios
Difficulté 1/5 1-3 heures Accessibilité débutants 78/100
software-mansion/react-native-executorch#1617 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Peer react-native >=0.83Peut-être pris @msluszniak l’a pris il y a 5 jours. Ouvertedependencies dev exp
Difficulté 1/5 Moins d'une heure Accessibilité débutants 25/100
software-mansion/react-native-executorch#1623 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Docs: iOS < 17 fails pod install on the bare templatePeut-être pris @msluszniak l’a pris il y a 5 jours. Ouvertedocumentation platform: ios
Difficulté 1/5 Moins d'une heure Accessibilité débutants 20/100
software-mansion/react-native-executorch#1622 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Docs: dynamic frameworks are supportedPeut-être pris @msluszniak l’a pris il y a 5 jours. Ouvertedocumentation platform: ios
Difficulté 1/5 1-3 heures Accessibilité débutants 35/100
software-mansion/react-native-executorch#1621 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Docs: drop the Expo babel.config.js stepPeut-être pris @msluszniak l’a pris il y a 5 jours. Ouvertedocumentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 25/100
software-mansion/react-native-executorch#1620 · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de software-mansion/react-native-executorch
Issues similaires
-
area:tooling good first issue
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
interledger/publisher-tools#1007 ·
Les mainteneurs répondent en général sous 1 jour
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
databrickslabs/ontos#1420 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
vercel-labs/just-bash#756 ·
Les mainteneurs répondent en général sous 1 jour
-
area: ci good first issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
interledger/web-monetization-extension#1555 ·
Les mainteneurs répondent en général sous 1 jour
-
[t-dialog] 弹窗组件和抽屉组件的文档说明不够详细清楚Ouverte🐞 bug 🧐 unconfirmed
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Tencent/tdesign-vue-next#7056 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour