You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WebGPU] Reuse MatMulNBits MLP/QKV for QLoRA adapters (alternative to #33901) - #33912
Alternative to #33901 for QLoRA QKV/MLP fusion. Extend the existing MatMulNBitsMlp and MatMulNBitsQkv operators with optional runtime adapter inputs, and route adapter-off calls through their existing base decode shaders. No new contrib-operator names are added. The portable Muffin model is unchanged.
The optimizer fuses QLoRA only when the WebGPU kernel advertises the TAdapter type constraint. An older plugin that exposes only the base kernels keeps the unfused graph.
Performance
RTX 5080, built-in D3D12 WebGPU, graph capture on, batch 1, prompt length 16, 128 generated tokens; median of four runs after two warmups, adapter off:
Model/path
Decode tokens/s
Decode ms/token
Portable Muffin, fusion disabled
227.1
4.404
Portable Muffin, fusion enabled
253.5
3.945
Pruned AION base-only graph
254.6
3.928
Fusion improves portable Muffin decode by about 11.6% and brings it within 0.5% of the pruned base-only graph in this run window. The separate-operator PR #33901 reported the same performance relationship.
Validation
Windows Release builds of onnxruntime, onnxruntime_test_all, and onnxruntime_provider_test passed.
37 focused fusion/switching tests and 3 WebGPU operator tests passed.
One Muffin session ran adapter off, on, then off again; the final off run returned to the original token result.
Tradeoff for review
This approach extends the version-1 schemas of existing contrib operators. Automatic fusion is guarded for older plugins, but a serialized optimized graph containing the new adapter inputs requires a plugin that understands them. #33901 uses distinct operator names to keep that contract explicit.
This PR extends the existing WebGPU MatMulNBitsMlp and MatMulNBitsQkv operators to support runtime QLoRA adapters, rather than adding separate operators as proposed in #33901.
Changes:
Adds optional adapter inputs and reuses base decode shaders when adapters are off.
Extends MLP/QKV fusion with a TAdapter capability check intended to protect older plugins.
Updates operator documentation and adds numerical, adapter-switching, schema, and malformed-weight tests.
The all-empty shortcut accepts a dynamically shaped adapter-up tensor such as [0, 1, 32] and returns the base result, whereas the standalone projection rejects it because the first dimension must be N. Validate each group's packed adapter ranks and dimensions before taking the shortcut, preferably using shared validation, and add a malformed-empty-adapter regression. The same issue affects onnxruntime/contrib_ops/webgpu/quantization/matmul_nbits_qkv.cc:409–411.
The new fused adapter numerical and switching tests cover only FP16 with M=1 and K=32, leaving integration with the FP32 and multi-row projection paths untested. Add unfused-versus-fused numerical cases for float and M>1, with active and mixed empty adapters, for both MLP and QKV. Choose dimensions and provider capabilities that exercise the alternative projection dispatches together with fused normalization and MLP activation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Alternative to #33901 for QLoRA QKV/MLP fusion. Extend the existing
MatMulNBitsMlpandMatMulNBitsQkvoperators with optional runtime adapter inputs, and route adapter-off calls through their existing base decode shaders. No new contrib-operator names are added. The portable Muffin model is unchanged.The optimizer fuses QLoRA only when the WebGPU kernel advertises the
TAdaptertype constraint. An older plugin that exposes only the base kernels keeps the unfused graph.Performance
RTX 5080, built-in D3D12 WebGPU, graph capture on, batch 1, prompt length 16, 128 generated tokens; median of four runs after two warmups, adapter off:
Fusion improves portable Muffin decode by about 11.6% and brings it within 0.5% of the pruned base-only graph in this run window. The separate-operator PR #33901 reported the same performance relationship.
Validation
onnxruntime,onnxruntime_test_all, andonnxruntime_provider_testpassed.Tradeoff for review
This approach extends the version-1 schemas of existing contrib operators. Automatic fusion is guarded for older plugins, but a serialized optimized graph containing the new adapter inputs requires a plugin that understands them. #33901 uses distinct operator names to keep that contract explicit.