feat(core,llm): support ArrayBuffer, custom ModelDataLoader, and external .ptd weights in loadModel
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 1/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- pytorch, react-native, typescript
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.8k
- Forks
- 101
- Merge medio
- 1 d 10 h
- PR fusionados (30 d)
- 51
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de software-mansion/react-native-executorch
-
Require react-native-blob-util >=1.0.0 (Xcode 27 iOS build failure)Posiblemente ocupada @msluszniak la tomó hace 5 días. Abiertodependencies platform: ios
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
software-mansion/react-native-executorch#1617 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Peer react-native >=0.83Posiblemente ocupada @msluszniak la tomó hace 5 días. Abiertodependencies dev exp
Dificultad 1/5 Menos de una hora Aptitud para principiantes 25/100
software-mansion/react-native-executorch#1623 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Docs: iOS < 17 fails pod install on the bare templatePosiblemente ocupada @msluszniak la tomó hace 5 días. Abiertodocumentation platform: ios
Dificultad 1/5 Menos de una hora Aptitud para principiantes 20/100
software-mansion/react-native-executorch#1622 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Docs: dynamic frameworks are supportedPosiblemente ocupada @msluszniak la tomó hace 5 días. Abiertodocumentation platform: ios
Dificultad 1/5 1-3 horas Aptitud para principiantes 35/100
software-mansion/react-native-executorch#1621 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Docs: drop the Expo babel.config.js stepPosiblemente ocupada @msluszniak la tomó hace 5 días. Abiertodocumentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 25/100
software-mansion/react-native-executorch#1620 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de software-mansion/react-native-executorch
Issues similares
-
area:tooling good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
interledger/publisher-tools#1007 ·
Los mantenedores suelen responder en 1 día
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
databrickslabs/ontos#1420 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
vercel-labs/just-bash#756 ·
Los mantenedores suelen responder en 1 día
-
area: ci good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
interledger/web-monetization-extension#1555 ·
Los mantenedores suelen responder en 1 día
-
[t-dialog] 弹窗组件和抽屉组件的文档说明不够详细清楚Abierto🐞 bug 🧐 unconfirmed
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Tencent/tdesign-vue-next#7056 · 1 comentario ·
Los mantenedores suelen responder en 1 día