Skip to content

Commit

Permalink
support for layernorm in webgpu pre opset-17 (#21121)
Browse files Browse the repository at this point in the history
handled the same way cpu does
  • Loading branch information
guschmue authored Jun 27, 2024
1 parent 8f738d8 commit 9eb1c2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/web/docs/webgpu-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Do not modify directly.*
| HardSigmoid | ai.onnx(6+) | |
| If | ai.onnx(1-10,11-12,13-18,19+) | |
| InstanceNormalization | ai.onnx(6+); com.ms.internal.nhwc(6+) | |
| LayerNormalization | ai.onnx(17+) | |
| LayerNormalization | ai.onnx(1-16,17+) | |
| LeakyRelu | ai.onnx(6-15,16+) | |
| Less | ai.onnx(7-8,9-12,13+) | |
| LessOrEqual | ai.onnx(12-15,16+) | |
Expand Down
5 changes: 5 additions & 0 deletions onnxruntime/contrib_ops/js/js_contrib_kernels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, FastGe
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, FusedConv);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, Gelu);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, GroupQueryAttention);
// LayerNormalization used to be a contrib op that (incorrectly) used kOnnxDomain so we need to version it
class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 16, LayerNormalization);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, MatMulNBits);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, MultiHeadAttention);
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, QuickGelu);
Expand All @@ -23,6 +25,7 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, Simp
class ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, SkipSimplifiedLayerNormalization);

template <>

KernelCreateInfo BuildKernelCreateInfo<void>() {
KernelCreateInfo info;
return info;
Expand All @@ -37,6 +40,8 @@ Status RegisterJsContribKernels(KernelRegistry& kernel_registry) {
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, FusedConv)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, Gelu)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, GroupQueryAttention)>,
// LayerNormalization used to be a contrib op that (incorrectly) used kOnnxDomain so we need to version it
BuildKernelCreateInfo<ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kJsExecutionProvider, kOnnxDomain, 1, 16, LayerNormalization)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, MatMulNBits)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, MultiHeadAttention)>,
BuildKernelCreateInfo<ONNX_OPERATOR_KERNEL_CLASS_NAME(kJsExecutionProvider, kMSDomain, 1, QuickGelu)>,
Expand Down
13 changes: 13 additions & 0 deletions onnxruntime/contrib_ops/js/layer_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ namespace onnxruntime {
namespace contrib {
namespace js {

// LayerNormalization used to be a contrib op
// that (incorrectly) used kOnnxDomain so we need to version it
ONNX_OPERATOR_VERSIONED_KERNEL_EX(
LayerNormalization,
kOnnxDomain,
1,
16,
kJsExecutionProvider,
(*KernelDefBuilder::Create())
.TypeConstraint("T", onnxruntime::js::JsepSupportedFloatTypes())
.TypeConstraint("U", onnxruntime::js::JsepSupportedFloatTypes()),
onnxruntime::js::LayerNorm<false>);

ONNX_OPERATOR_KERNEL_EX(
SimplifiedLayerNormalization,
kOnnxDomain,
Expand Down

0 comments on commit 9eb1c2a

Please sign in to comment.