Proposal: API to Separate Graph Building from Weight Loading to Reduce Peak Memory Usage
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 6/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript
- Lĩnh vực
- ai, api, performance
Hướng nghiên cứu
This is a design proposal, not a bug to fix. Start with the proposed builder.constant(), builder.build(), graph.setConstantData() and context.dispatch() semantics, and check whether the backends can support weightless graph creation. The thread has been quiet for about 300 days with no linked pull request, so ask the maintainers whether the direction is still wanted before writing anything. Done means an agreed spec change, not a patch.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem Statement
While analyzing the memory-consumption of the Stable Diffusion demo on a dGPU system, I observed that the CPU memory used during graph building is more than 3x the actual model size. Similar high-memory-usage behavior (requiring multiple times the model size) is also observed on iGPU systems, although the exact multiplier may differ.
While this might be irrelevant for smaller models, it presents a significant overhead for larger ones. For example:
- A 4GB model can consume over 12GB of CPU memory during its load phase on a dGPU.
- This is already critical on systems with 16GB of total memory.
This issue is even more pronounced on UVM (Unified Memory) systems where the CPU and GPU/NPU share memory. This high peak usage during loading unnecessarily consumes memory that could otherwise be allocated for the model weights and intermediate buffers on the device.
Proposal
I'd like to propose introducing an API that splits graph creation from weight passing (i.e., loading the constant data).
The primary goal is to enable streaming weights directly into the graph during initialization. This would avoid creating copies of the weights in JavaScript or in the backend's staging memory before the graph is fully built. Ideally, the weight data would only be copied once, from its source buffer directly to its final (e.g., device) location when the data is provided to the graph after it has been built.
This raises a key question for discussion:
- Would all current WebNN backends be able to support a (mostly) "weightless" graph creation, where all tensor shapes and data types are known, but the actual weight data is not provided until a later step?
Potential Implementation Idea
One potential solution could look like this:
- Allow
builder.constant()to be called with just anMLOperandDescriptor(defining the shape and data type), without requiring theArrayBufferViewdata source. - This call would return an
MLOperandobject that acts as a handle for this "hollow constant" (a tensor without its data). - Allow
builder.build()to succeed usingMLOperands that represent these hollow constants, creating the executableMLGraph. - Introduce a new method on the
MLGraphinterface, such as:
graph.setConstantData(constantOperand, dataBuffer) - After the
MLGraphis built (step 3), the user must call this newsetConstantData()method for every hollow constant they created. At this stage, the backend can perform any required conversions and transfer thedataBufferdirectly to device memory. context.dispatch()would require all constants to be set. Attempting to calldispatch()before all hollow constants have been supplied with data (viasetConstantData) would result in an error.
Expected Benefits
This change would significantly reduce peak memory pressure during initialization:
- dGPU Systems: In an ideal scenario, this could limit the peak CPU memory overhead to 1x-2x the size of the largest single tensor (for temporary buffering during upload), rather than 3x the entire model.
- iGPU/UVM Systems: The hope is that no temporary CPU-side storage would be needed for the "upload" (as it's shared memory). This would reduce the total peak CPU memory consumption down to roughly
Model Size + Max Single Tensor Size.
- Ngôn ngữ chính
- Bikeshed
- Star
- 566
- Fork
- 72
- Merge trung bình
- 6 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của webmachinelearning/webnn
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
webmachinelearning/webnn#967 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
webmachinelearning/webnn#966 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
webmachinelearning/webnn#965 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
webmachinelearning/webnn#964 · 1 bình luận · 1 reaction ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
webmachinelearning/webnn#963 · 3 bình luận · 2 reaction ·
Tất cả issue của webmachinelearning/webnn
Issue tương tự
-
bug needs-acceptance wg/agentic-context
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vllm-project/semantic-router#5418 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug: Assistant replies lose the space before numbers ("Oct7", "as of10-22-2026") with OpenAI modelsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
we-promise/sure#4441 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
integration:coding-agents
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vectorize-io/hindsight#5982 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`facts relink` model tier fails on strict structured-output backends (`invalid_json_schema`)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 10 ngày