feat(core,llm): support ArrayBuffer, custom ModelDataLoader, and external .ptd weights in loadModel
维护者通常 1 天内回复
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 1/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- pytorch, react-native, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 1.8k
- 派生
- 101
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 51
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
software-mansion/react-native-executorch 的其他 Issue
-
Require react-native-blob-util >=1.0.0 (Xcode 27 iOS build failure)可能已有人在做 @msluszniak 于 5 天前认领。 未关闭dependencies platform: ios
难度 1/5 1-3 小时 新手友好度 78/100
software-mansion/react-native-executorch#1617 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Peer react-native >=0.83可能已有人在做 @msluszniak 于 5 天前认领。 未关闭dependencies dev exp
难度 1/5 1 小时以内 新手友好度 25/100
software-mansion/react-native-executorch#1623 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Docs: iOS < 17 fails pod install on the bare template可能已有人在做 @msluszniak 于 5 天前认领。 未关闭documentation platform: ios
难度 1/5 1 小时以内 新手友好度 20/100
software-mansion/react-native-executorch#1622 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Docs: dynamic frameworks are supported可能已有人在做 @msluszniak 于 5 天前认领。 未关闭documentation platform: ios
难度 1/5 1-3 小时 新手友好度 35/100
software-mansion/react-native-executorch#1621 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Docs: drop the Expo babel.config.js step可能已有人在做 @msluszniak 于 5 天前认领。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 25/100
software-mansion/react-native-executorch#1620 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 software-mansion/react-native-executorch 的全部 Issue
相似的 Issue
-
area:tooling good first issue
难度 2/5 1-3 小时 新手友好度 68/100
interledger/publisher-tools#1007 ·
维护者通常 1 天内回复
-
priority/medium roadmap/v1.1.1 stakeholder/rapr type/bug
难度 2/5 1-3 小时 新手友好度 83/100
databrickslabs/ontos#1420 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
vercel-labs/just-bash#756 ·
维护者通常 1 天内回复
-
area: ci good first issue
难度 1/5 1 小时以内 新手友好度 85/100
interledger/web-monetization-extension#1555 ·
维护者通常 1 天内回复
-
🐞 bug 🧐 unconfirmed
难度 2/5 1-3 小时 新手友好度 72/100
Tencent/tdesign-vue-next#7056 · 1 条评论 ·
维护者通常 1 天内回复