feat(core,llm): support ArrayBuffer, custom ModelDataLoader, and external .ptd weights in loadModel
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 1/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- pytorch, react-native, typescript
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 1.8k
- Fork
- 101
- Merge medio
- 1g 10h
- PR unite (30g)
- 51
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-native-executorch
-
Require react-native-blob-util >=1.0.0 (Xcode 27 iOS build failure)Forse già presa @msluszniak l’ha presa 5 giorni fa. Apertadependencies platform: ios
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
software-mansion/react-native-executorch#1617 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Peer react-native >=0.83Forse già presa @msluszniak l’ha presa 5 giorni fa. Apertadependencies dev exp
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 25/100
software-mansion/react-native-executorch#1623 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Docs: iOS < 17 fails pod install on the bare templateForse già presa @msluszniak l’ha presa 5 giorni fa. Apertadocumentation platform: ios
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 20/100
software-mansion/react-native-executorch#1622 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Docs: dynamic frameworks are supportedForse già presa @msluszniak l’ha presa 5 giorni fa. Apertadocumentation platform: ios
Difficoltà 1/5 1-3 ore Idoneità per principianti 35/100
software-mansion/react-native-executorch#1621 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Docs: drop the Expo babel.config.js stepForse già presa @msluszniak l’ha presa 5 giorni fa. Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 25/100
software-mansion/react-native-executorch#1620 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di software-mansion/react-native-executorch
Issue simili
-
area:tooling good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
interledger/publisher-tools#1007 ·
I maintainer di solito rispondono entro 1 giorno
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
databrickslabs/ontos#1420 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
vercel-labs/just-bash#756 ·
I maintainer di solito rispondono entro 1 giorno
-
area: ci good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
interledger/web-monetization-extension#1555 ·
I maintainer di solito rispondono entro 1 giorno
-
🐞 bug 🧐 unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Tencent/tdesign-vue-next#7056 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno