Skip to content

[WebGPU] Correct MatMul bias input indexing in MatMul::ComputeInternal#28475

Merged
guschmue merged 2 commits into
mainfrom
copilot/fix-bias-setting-matmul-webgpu
May 12, 2026
Merged

[WebGPU] Correct MatMul bias input indexing in MatMul::ComputeInternal#28475
guschmue merged 2 commits into
mainfrom
copilot/fix-bias-setting-matmul-webgpu

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Description

WebGPU MatMul was wiring bias into the wrong slot in the inputs vector when bias is present. The vector is pre-sized to 3 and downstream code reads bias from inputs[2], but the previous logic appended bias, placing it at index 3.

  • Root cause
    • inputs was initialized with size 3 for bias cases, then bias was added via push_back, creating a 4th element.
  • Change
    • Replaced append logic with direct assignment to the expected index.
  • Effect
    • Bias is now consistently passed at inputs[2], matching ComputeMatMul() and Intel-path expectations.
std::vector<const Tensor*> inputs(has_bias ? 3 : 2);
inputs[0] = a;
inputs[1] = b;
if (has_bias) {
  const auto* bias = context.Input(2);
  inputs[2] = bias;  // was: inputs.push_back(bias);
}

Motivation and Context

This addresses incorrect bias propagation in WebGPU MatMul (onnxruntime/core/providers/webgpu/math/matmul.cc) caused by index mismatch between producer and consumer logic. The fix is intentionally surgical: one behavioral line change in the affected code path.

Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/b21f1aac-0a81-4b5d-a3bf-38752aeab99a

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect logic of setting the bias for matmul in WebGPU [WebGPU] Correct MatMul bias input indexing in MatMul::ComputeInternal May 12, 2026
Copilot AI requested a review from guschmue May 12, 2026 17:04
@guschmue guschmue marked this pull request as ready for review May 12, 2026 17:08
@guschmue guschmue enabled auto-merge (squash) May 12, 2026 17:08
@guschmue guschmue added the ep:WebGPU ort-web webgpu provider label May 12, 2026
@guschmue guschmue merged commit 72bce1d into main May 12, 2026
88 checks passed
@guschmue guschmue deleted the copilot/fix-bias-setting-matmul-webgpu branch May 12, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ep:WebGPU ort-web webgpu provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Web] Incorrect logic of setting the bias for matmul in WebGPU

3 participants