Repository navigation
perf: optimize H3 inference and segmented weight prefetch - #2240
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Backend buffer-cache lifecycle ggml, src/core/ggml_extend_backend.h, src/core/ggml_extend_backend.cpp, src/core/ggml_runner.cpp, examples/server/model_catalog.cpp, src/core/compute_workspace.cpp |
The backend API adds functions to enable or clear buffer caching. The runner calls them on its primary and extra backends at startup and shutdown. The ggml subproject reference changes. Two local declarations are reformatted. |
Graph-cut output binding and planning src/core/ggml_graph_cut.cpp, src/core/runner_cache.h, src/core/runner_cache.cpp, src/core/ggml_runner.h, src/core/ggml_runner.cpp, src/model_manager.cpp |
The runner carries source graph use counts into segment graphs, binds eligible cut outputs to cache storage, and includes those outputs in segment measurement. It updates capacity checks and selects segmented execution based on workspace fit and planning headroom. |
Staged prefetch submission src/device_residency_manager.h, src/model_manager.h, src/model_manager_prefetch.cpp, src/core/segment_weight_pipeline.h, src/core/segment_weight_pipeline.cpp, src/core/ggml_runner.cpp |
Prefetch preparation and transfer submission are separate operations. The segment pipeline submits queued work through a callback before graph computation. The device-memory margin increases to 1 GiB for CUDA on Windows. |
MiniMax H3 model graph
| Layer / File(s) | Summary |
|---|---|
MLP, attention, and segment processing src/model/diffusion/minimax_h3.hpp |
The MLP uses ggml_swiglu and weight-dependent scales. Attention operations are separated into projection, attention, and output projection. Transformer segments are processed separately around shared attention. |
Packed audio and video inputs src/model/diffusion/minimax_h3.hpp |
The runner validates packed input dimensions and creates video and audio views instead of copying values into separate cached tensors. |
Priority:
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant GGMLRunner
participant SegmentWeightPipeline
participant DeviceResidencyManager
participant ModelManager
SegmentWeightPipeline->>DeviceResidencyManager: prepare_prefetch_params
DeviceResidencyManager->>ModelManager: prepare prefetched parameters
GGMLRunner->>SegmentWeightPipeline: submit_next before compute
SegmentWeightPipeline->>DeviceResidencyManager: submit_prefetched_params
DeviceResidencyManager->>ModelManager: submit transfers and record event
Possibly related issues
- [Bug] MiniMax-H3 DiT: MLP fc1 output exceeds Vulkan's 4 GiB buffer limit above 37,449 tokens; the MLP of every layer falls back to CPU #2242: The PR changes the
MLP::forwardprojection and activation path involved in the reported failure. It does not add the issue’s proposed token-axis chunking.
Possibly related PRs
- leejet/stable-diffusion.cpp#2235: Both PRs change
GGMLRunner::measureand the segment execution path. - leejet/stable-diffusion.cpp#2224: Both PRs change graph-cut planning and segmented execution.
Merge Risk: 
Minimal · up to 301aa
-
No concrete runtime, integrity, availability, or security regression was established.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "perf: optimize H3 inference and segmented weight prefetch" matches the main changes. The raw summary shows H3 restructuring (projections, modulation, partial RoPE, tensor views for audio/video latents) and prefetch separation of allocation from transfer submission (prepare_prefetch_params / submit_prefetched_params). It omits the ggml update, graph-cut output binding, and runner buffer-cache control, but it does not describe anything absent from the changeset. The title is concise, specific, and uses a conventional prefix.
Full details: Description check
-
Explanation
The description follows the template. It has a Summary with five bullets that describe the changes, a Related Issue / Discussion section (marked N/A), an Additional Information section with hardware, DiT file, benchmark tables, and configuration details, and a Checklist with the contribution guidelines item checked. The summary bullets cover the H3 restructuring, prefetch separation, graph-cut output binding, buffer cache control, Windows CUDA headroom, and the ggml update. The benchmark data supports the performance claims.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 36 functions across 16 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Resolves the overlap between upstream leejet#2240 (H3 inference and segmented prefetch) and the branch's multi-device streaming: - cut outputs bind to the cache on the segment's device, reusing an entry with the same layout instead of reallocating it - prefetch is prepared at enqueue and submitted when the segment's device starts computing; cross-step prefetch keeps working - segmentation is decided from the weights-only lower bound before the cached full measurement - MiniMax-H3 takes upstream's per-span attention block, fused rope and INT8 MLP scaling while keeping feed-forward token chunking Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
Related Issue / Discussion
N/A
Additional Information
Hardware: NVIDIA GeForce RTX 4090 24 GB, NVIDIA driver 596.36.
DiT files:
minimax_h3_fl2va_pruned_int8_convrot.safetensorsSampling throughput in s/it; lower is better:
Configuration:
a lovely cat holding a sign says 'stable-diffusion.cpp'cdf272f351, PyTorch2.13.0+cu130, comfy-kitchen0.2.40, PyTorch attention.77b72a2efed78f55de26892c7e909cee001e8b83.Checklist
Summary by CodeRabbit
Performance
Reliability