Skip to content

Fix WebGPU ConvTranspose bias validation in TypeScript and C++ implementations#27213

Merged
guschmue merged 12 commits intomainfrom
copilot/fix-convtranspose-input-validation
Feb 6, 2026
Merged

Fix WebGPU ConvTranspose bias validation in TypeScript and C++ implementations#27213
guschmue merged 12 commits intomainfrom
copilot/fix-convtranspose-input-validation

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Description

WebGPU EP's ConvTranspose operator failed to properly validate bias tensor shape in both TypeScript and C++ implementations. Undefined group attribute caused NaN in validation checks, allowing invalid bias tensors to pass.

TypeScript Changes (js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts):

  • Parse time default: Set group to 1 when undefined (line 135 in parseConvTransposeAttributes)
  • Merged bias validation (lines 181-186 in validateInputs):
    • Validates bias is 1D and size matches output channels in single condition
    • Uses simple 'invalid bias' error message matching Conv operator pattern

C++ Changes (onnxruntime/core/providers/webgpu/nn/conv_transpose.cc):

  • Merged bias validation (lines 61-64 in ComputeInternal):
    • Validates bias is 1D and size matches output channels in single condition
    • Uses simple "invalid bias" error message matching Conv operator pattern

Code Formatting:

  • Applied prettier formatting to ensure TypeScript code adheres to project style guidelines
  • Applied lintrunner formatting fixes to remove trailing whitespace in C++ code

Motivation and Context

Addresses issue where tests with intentionally invalid bias shapes were incorrectly passing in the WebGPU EP. The fix ensures:

  • Invalid bias shapes are properly rejected in both TypeScript and C++ implementations
  • NaN bugs prevented across all code paths using group attribute in TypeScript
  • Validation conditions are merged into single checks with OR operators for cleaner code
  • Error messages use simple 'invalid bias' format matching Conv operator pattern
  • Consistent validation logic across both WebGPU backend implementations
  • Enables compatibility with tests in PR [CPU/CUDA] Add bias input validations for ConvTranspose #27209 for WebGPU EP
  • Code passes all linting and formatting checks (prettier and lintrunner)

Note: The C++ implementation already handles group attribute defaulting to 1 in the ConvAttributes base class, so only bias validation needed to be added.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Web] WebGPU EP's ConvTranspose input validation seems loose</issue_title>
<issue_description>### Describe the issue

As title.

The WebGPU EP's ConvTranspose operator neglects to check if the bias is of the expected shape. See tests added in #27209. The WebGPU EP "passes" those tests when a failure of some sort is expected (preferably along the lines of bias is not of the expected shape). Not sure if this is masking a bug of some sort.

To reproduce

Run tests in #27209 with the WebGPU EP

Urgency

Not urgent

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

Run tests in PR branch #27209

Execution Provider

'webgpu' (WebGPU)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 30, 2026 16:28
Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
…ndant check

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix input validation for ConvTranspose bias in WebGPU EP Fix WebGPU ConvTranspose bias validation Jan 30, 2026
Copilot AI requested a review from guschmue January 30, 2026 16:37
Copy link
Contributor

@guschmue guschmue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to make the change in onnxruntime/core/providers/webgpu/nn/conv_transpose.cc

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

you also need to make the change in onnxruntime/core/providers/webgpu/nn/conv_transpose.cc

Added bias validation to the C++ implementation in commit 0d53e11. The validation checks that bias is 1D and has size equal to output channels (group * filter_shape[1]), matching the logic in the TypeScript implementation.

Copilot AI changed the title Fix WebGPU ConvTranspose bias validation Fix WebGPU ConvTranspose bias validation in TypeScript and C++ implementations Jan 30, 2026
Copilot AI requested a review from guschmue January 30, 2026 16:46
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

guschmue and others added 3 commits January 30, 2026 08:51
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@guschmue guschmue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint is failing:
Error: Following source files are not formatted: (did you run "npm run format"?)
js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 30, 2026

lint is failing:
Error: Following source files are not formatted: (did you run "npm run format"?)
js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts

Fixed formatting by running prettier in commit 7c55b81. The file now passes linting checks.

Copilot AI requested a review from guschmue January 30, 2026 16:56
@guschmue
Copy link
Contributor

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

Copy link
Member

@hariharans29 hariharans29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the error check conditions be merged and the error message align with the error message in #27209 so that it is easier to enable the test in #27209 for the WebGPU EP ?

Copy link
Contributor

@guschmue guschmue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve pending review feedback

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

Can the error check conditions be merged and the error message align with the error message in #27209 so that it is easier to enable the test in https://gi...

Merged the validation conditions and simplified error messages in both TypeScript and C++ implementations in commit 4c850b7. The error message now matches the Conv operator pattern with 'invalid bias', which should enable the tests in PR #27209 for WebGPU EP.

Copilot AI requested a review from guschmue February 5, 2026 17:19
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@guschmue guschmue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run
lintrunner -a
to fix formatting

Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

run
lintrunner -a
to fix formatting

Ran lintrunner -a and applied the formatting fixes in commit 9c9ef07.

Copilot AI requested a review from guschmue February 5, 2026 20:01
@guschmue
Copy link
Contributor

guschmue commented Feb 5, 2026

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@guschmue guschmue merged commit b75bfe1 into main Feb 6, 2026
88 checks passed
@guschmue guschmue deleted the copilot/fix-convtranspose-input-validation branch February 6, 2026 01:27
tianleiwu pushed a commit that referenced this pull request Feb 12, 2026
…entations (#27213)

### Description

WebGPU EP's ConvTranspose operator failed to properly validate bias
tensor shape in both TypeScript and C++ implementations. Undefined
`group` attribute caused NaN in validation checks, allowing invalid bias
tensors to pass.

**TypeScript Changes**
(`js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts`):

- **Parse time default**: Set `group` to 1 when undefined (line 135 in
`parseConvTransposeAttributes`)
  ```typescript
  const group = (attributes.group as number) ?? 1; // per ONNX spec
  ```

- **Enhanced bias validation** (lines 182-192 in `validateInputs`):
  - Check bias is 1D before accessing dimensions
  - Validate bias size matches output channels: `weight.dims[1] * group`
  - Descriptive errors showing actual vs expected values
  ```typescript
  if (inputs.length === 3) {
    if (inputs[2].dims.length !== 1) {
      throw new Error('invalid bias: bias must be 1D tensor');
    }
    const featureMaps = inputs[1].dims[1] * attributes.group;
    if (inputs[2].dims[0] !== featureMaps) {
      throw new Error(
`invalid bias: bias size (${inputs[2].dims[0]}) must be equal to output
channels (${featureMaps})`,
      );
    }
  }
  ```

**C++ Changes**
(`onnxruntime/core/providers/webgpu/nn/conv_transpose.cc`):

- **Added bias validation** (lines 61-71 in `ComputeInternal`):
  - Validates bias is 1D tensor
- Validates bias size matches output channels (`num_output_channels =
group * filter_shape[1]`)
  - Uses consistent error messages with TypeScript implementation
  ```cpp
  // Validate bias shape if provided
  if (has_bias) {
    const auto& bias_shape = bias->Shape();
    if (bias_shape.NumDimensions() != 1) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "invalid bias:
bias must be 1D tensor");
    }
    if (bias_shape[0] != num_output_channels) {
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "invalid bias:
bias size (", bias_shape[0],
") must be equal to output channels (", num_output_channels, ")");
    }
  }
  ```

**Code Formatting**:
- Applied prettier formatting to ensure TypeScript code adheres to
project style guidelines (120 character line width, proper line breaks
for long error messages)

### Motivation and Context

Addresses issue where tests with intentionally invalid bias shapes were
incorrectly passing in the WebGPU EP. The fix ensures:
- Invalid bias shapes are properly rejected in both TypeScript and C++
implementations
- NaN bugs prevented across all code paths using `group` attribute in
TypeScript
- Clear error messages for debugging
- Consistent validation logic across both WebGPU backend implementations
- Code passes all linting and formatting checks

Note: The C++ implementation already handles `group` attribute
defaulting to 1 in the ConvAttributes base class, so only bias
validation needed to be added.

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[Web] WebGPU EP's ConvTranspose input validation seems
loose</issue_title>
> <issue_description>### Describe the issue
> 
> As title.
> 
> The WebGPU EP's ConvTranspose operator neglects to check if the bias
is of the expected shape. See tests added in
#27209. The WebGPU EP
"passes" those tests when a failure of some sort is expected (preferably
along the lines of bias is not of the expected shape). Not sure if this
is masking a bug of some sort.
> 
> ### To reproduce
> 
> Run tests in #27209 with
the WebGPU EP
> 
> ### Urgency
> 
> Not urgent
> 
> ### ONNX Runtime Installation
> 
> Built from Source
> 
> ### ONNX Runtime Version or Commit ID
> 
> Run tests in PR branch
#27209
> 
> ### Execution Provider
> 
> 'webgpu' (WebGPU)</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #27210

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Co-authored-by: Guenther Schmuelling <guschmue@microsoft.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
tianleiwu added a commit that referenced this pull request Feb 13, 2026
This cherry-picks the following commits for the 1.24.2 release:
- #27096
- #27077
- #26677
- #27238
- #27213
- #27256
- #27278
- #27275
- #27276
- #27216
- #27271
- #27299
- #27294
- #27266
- #27176
- #27126
- #27252

---------

Co-authored-by: Xiaofei Han <xiaofeihan@microsoft.com>
Co-authored-by: Jiajia Qin <jiajiaqin@microsoft.com>
Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
Co-authored-by: qti-monumeen <monumeen@qti.qualcomm.com>
Co-authored-by: Ankit Maheshkar <ankit.maheshkar@intel.com>
Co-authored-by: Eric Crawford <eric.r.crawford@intel.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: guschmue <22941064+guschmue@users.noreply.github.com>
Co-authored-by: Guenther Schmuelling <guschmue@microsoft.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: angelser <32746004+angelser@users.noreply.github.com>
Co-authored-by: Angela Serrano Brummett <angelser@microsoft.com>
Co-authored-by: Misha Chornyi <99709299+mc-nv@users.noreply.github.com>
Co-authored-by: hariharans29 <9969784+hariharans29@users.noreply.github.com>
Co-authored-by: eserscor <erscor@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>
Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com>
Co-authored-by: Ti-Tai Wang <titaiwang@microsoft.com>
Co-authored-by: bmehta001 <bmehta001@users.noreply.github.com>
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] WebGPU EP's ConvTranspose input validation seems loose

5 participants