From 2db6b734f5e669593f2868a703c5d212df1bef03 Mon Sep 17 00:00:00 2001 From: Yang Gu Date: Tue, 17 Sep 2024 14:17:10 +0800 Subject: [PATCH] [js/webgpu] Fix issue to run model demucs (#22074) This is to fix issue #22031 to run model demucs. For conv-transpose, outputPadding.length could be 1, while spatialRank is 2. The fix is to append enough 0s to outputPadding. For conv, the issue is similar. kernelShape.length sometimes could be 1, while inputs[1].dims.length is 4. The fix is also to append enough 0s to kernelShape. --- js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts | 6 ++---- js/web/lib/wasm/jsep/webgpu/ops/conv.ts | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts b/js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts index ece2e1b7c7..236f1b09a6 100644 --- a/js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts +++ b/js/web/lib/wasm/jsep/webgpu/ops/conv-transpose.ts @@ -44,10 +44,8 @@ const calculateOutputShapeAndPads = ( ) => { const spatialRank = inputShape.length - 2; const updateOutputShape = outputShape.length === 0; - if (outputPadding.length === 0) { - for (let i = 0; i < spatialRank; ++i) { - outputPadding.push(0); - } + if (outputPadding.length < spatialRank) { + outputPadding.push(...Array(spatialRank - outputPadding.length).fill(0)); } const batchSize = inputShape[0]; const outChannels = kernelShape[isChannelLast ? 3 : 1] * group; diff --git a/js/web/lib/wasm/jsep/webgpu/ops/conv.ts b/js/web/lib/wasm/jsep/webgpu/ops/conv.ts index fe37163a0c..de9f7bc888 100644 --- a/js/web/lib/wasm/jsep/webgpu/ops/conv.ts +++ b/js/web/lib/wasm/jsep/webgpu/ops/conv.ts @@ -103,7 +103,10 @@ const validateInputs = (inputs: readonly TensorView[], attributes: ConvAttribute const getAdjustedConvAttributes = (attributes: T, inputs: readonly TensorView[]): T => { const kernelShape = attributes.kernelShape.slice(); - // if kernelShape is not specified in the attributes of this op, infer it from the weight tensor dims + // if kernelShape is not well specified in the attributes, infer it from the weight tensor dims + if (kernelShape.length < inputs[1].dims.length - 2) { + kernelShape.push(...Array(inputs[1].dims.length - 2 - kernelShape.length).fill(0)); + } for (let i = 2; i < inputs[1].dims.length; ++i) { if (kernelShape[i - 2] === 0) { kernelShape[i - 2] = inputs[1].dims[i];