feat(core,llm): support ArrayBuffer, custom ModelDataLoader, and external .ptd weights in loadModel
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 1/100
- Issue-Typ
- Feature
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- pytorch, react-native, typescript
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1.8k
- Forks
- 101
- Ø Merge
- 1 T. 10 Std.
- Gemergte PRs (30 T.)
- 51
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus software-mansion/react-native-executorch
-
Require react-native-blob-util >=1.0.0 (Xcode 27 iOS build failure)Evtl. vergeben @msluszniak hat das vor 5 Tagen übernommen. Offendependencies platform: ios
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
software-mansion/react-native-executorch#1617 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Peer react-native >=0.83Evtl. vergeben @msluszniak hat das vor 5 Tagen übernommen. Offendependencies dev exp
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 25/100
software-mansion/react-native-executorch#1623 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: iOS < 17 fails pod install on the bare templateEvtl. vergeben @msluszniak hat das vor 5 Tagen übernommen. Offendocumentation platform: ios
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 20/100
software-mansion/react-native-executorch#1622 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: dynamic frameworks are supportedEvtl. vergeben @msluszniak hat das vor 5 Tagen übernommen. Offendocumentation platform: ios
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 35/100
software-mansion/react-native-executorch#1621 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: drop the Expo babel.config.js stepEvtl. vergeben @msluszniak hat das vor 5 Tagen übernommen. Offendocumentation
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 25/100
software-mansion/react-native-executorch#1620 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in software-mansion/react-native-executorch
Ähnliche Issues
-
area:tooling good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
interledger/publisher-tools#1007 ·
Maintainer antworten meist innerhalb von 1 Tag
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
databrickslabs/ontos#1420 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
vercel-labs/just-bash#756 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: ci good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
interledger/web-monetization-extension#1555 ·
Maintainer antworten meist innerhalb von 1 Tag
-
🐞 bug 🧐 unconfirmed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Tencent/tdesign-vue-next#7056 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag