Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const parseConvTransposeAttributes = (attributes: Record<string, unknown>
typeof attributes.autoPad == 'undefined' ? 0 : (attributes.autoPad as number)
];
const dilations = attributes.dilations as [number, number];
const group = attributes.group as number;
const group = (attributes.group as number) ?? 1; // default to 1 per ONNX spec
const kernelShape = attributes.kernelShape as [number, number];
const pads = attributes.pads as [number, number, number, number];
const strides = attributes.strides as [number, number];
Expand Down Expand Up @@ -178,11 +178,17 @@ const validateInputs = (inputs: readonly TensorView[], attributes: ConvTranspose
throw new Error('FILTER_IN_CHANNEL should be equal to DATA_CHANNEL');
}

const featureMaps = inputs[1].dims[1] * attributes.group;

// if bias is provided it should be 1D and the number of elements should be equal to the number of feature maps
if (inputs.length === 3 && (inputs[2].dims.length !== 1 || inputs[2].dims[0] !== featureMaps)) {
throw new Error('invalid bias');
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})`,
);
}
}

const spatialRank = inputs[0].dims.length - 2;
Expand Down
11 changes: 11 additions & 0 deletions onnxruntime/core/providers/webgpu/nn/conv_transpose.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ Status ConvTranspose<is_channels_last>::ComputeInternal(ComputeContext& context)

bool has_bias = context.InputCount() > 2;
const auto* bias = has_bias ? context.Input<Tensor>(2) : nullptr;
// 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, ")");
}
}
if (input_shape.NumDimensions() == 3 && filter_shape.NumDimensions() == 3) {
// ConvTranspose1D
TensorShapeVector input_shape_vector = input_shape.AsShapeVector();
Expand Down
Loading