From 240faf45c1e48125e43e8b34510cb83de5dbbb8a Mon Sep 17 00:00:00 2001 From: Arthur Islamov Date: Tue, 12 Sep 2023 17:42:29 +0400 Subject: [PATCH] BiasAdd/BiasSplitGelu fp16 support, reverted test runner changes --- js/web/lib/wasm/jsep/webgpu/ops/bias-add.ts | 5 ----- js/web/lib/wasm/jsep/webgpu/ops/bias-split-gelu.ts | 5 ----- js/web/script/test-runner-cli-args.ts | 4 ++-- js/web/script/test-runner-cli.ts | 2 +- js/web/test/test-main.ts | 3 +-- js/web/test/test-runner.ts | 2 +- onnxruntime/contrib_ops/js/bias_add.cc | 4 +++- onnxruntime/contrib_ops/js/bias_split_gelu.cc | 4 +++- 8 files changed, 11 insertions(+), 18 deletions(-) diff --git a/js/web/lib/wasm/jsep/webgpu/ops/bias-add.ts b/js/web/lib/wasm/jsep/webgpu/ops/bias-add.ts index b73aa45001c98..9421d7433a14f 100644 --- a/js/web/lib/wasm/jsep/webgpu/ops/bias-add.ts +++ b/js/web/lib/wasm/jsep/webgpu/ops/bias-add.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import {DataType} from '../../../wasm-common'; import {TensorView} from '../../tensor'; import {ShapeUtil} from '../../util'; import {ComputeContext, GpuDataType, ProgramInfo, ProgramMetadata} from '../types'; @@ -9,10 +8,6 @@ import {ComputeContext, GpuDataType, ProgramInfo, ProgramMetadata} from '../type import {inputVariable, outputVariable, ShaderHelper} from './common'; const validateInputs = (inputs: readonly TensorView[]): void => { - if (inputs[0].dataType !== DataType.float) { - throw new Error('inputs should be float type'); - } - if (inputs[0].dims.length !== 3) { throw new Error('input should have 3 dimensions'); } diff --git a/js/web/lib/wasm/jsep/webgpu/ops/bias-split-gelu.ts b/js/web/lib/wasm/jsep/webgpu/ops/bias-split-gelu.ts index 848ce37aaed6c..e6be08d10201c 100644 --- a/js/web/lib/wasm/jsep/webgpu/ops/bias-split-gelu.ts +++ b/js/web/lib/wasm/jsep/webgpu/ops/bias-split-gelu.ts @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import {DataType} from '../../../wasm-common'; import {TensorView} from '../../tensor'; import {ShapeUtil} from '../../util'; import {ComputeContext, GpuDataType, ProgramInfo, ProgramMetadata} from '../types'; @@ -10,10 +9,6 @@ import {inputVariable, outputVariable, ShaderHelper} from './common'; import {erfImpl} from './unary-op'; const validateInputs = (inputs: readonly TensorView[]): void => { - if (inputs[0].dataType !== DataType.float) { - throw new Error('inputs should be float type'); - } - if (inputs[0].dims.length !== 3) { throw new Error('input should have 3 dimensions'); } diff --git a/js/web/script/test-runner-cli-args.ts b/js/web/script/test-runner-cli-args.ts index aadfeae6cd150..e34529fa1037d 100644 --- a/js/web/script/test-runner-cli-args.ts +++ b/js/web/script/test-runner-cli-args.ts @@ -105,7 +105,7 @@ Examples: export declare namespace TestRunnerCliArgs { type Mode = 'suite0'|'suite1'|'model'|'unittest'|'op'; - type Backend = 'cpu'|'webgl'|'webgpu'|'wasm'|'onnxruntime'|'xnnpack'|'webnn'|'cuda'|'dml'|'tensorrt'; + type Backend = 'cpu'|'webgl'|'webgpu'|'wasm'|'onnxruntime'|'xnnpack'|'webnn'; type Environment = 'chrome'|'edge'|'firefox'|'electron'|'safari'|'node'|'bs'; type BundleMode = 'prod'|'dev'|'perf'; } @@ -367,7 +367,7 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs // and ChromeCanary is not in CI. const defaultBrowserBackends = ['webgl', 'webgpu', 'wasm', 'xnnpack' /*, 'webnn'*/]; - const nodejsBackends = ['cpu', 'wasm', 'dml', 'cuda', 'tensorrt']; + const nodejsBackends = ['cpu', 'wasm']; const backendArgs = args.backend || args.b; const backend = (typeof backendArgs !== 'string') ? (env === 'node' ? nodejsBackends : defaultBrowserBackends) : backendArgs.split(','); diff --git a/js/web/script/test-runner-cli.ts b/js/web/script/test-runner-cli.ts index 3de509ca52da1..fa4312ee0aaf3 100644 --- a/js/web/script/test-runner-cli.ts +++ b/js/web/script/test-runner-cli.ts @@ -53,7 +53,7 @@ async function main() { // The default backends and opset version lists. Those will be used in suite tests. const DEFAULT_BACKENDS: readonly TestRunnerCliArgs.Backend[] = - args.env === 'node' ? ['dml', 'cuda', 'tensorrt', 'cpu', 'wasm'] : ['wasm', 'webgl', 'webgpu', 'webnn']; + args.env === 'node' ? ['cpu', 'wasm'] : ['wasm', 'webgl', 'webgpu', 'webnn']; const DEFAULT_OPSET_VERSIONS = fs.readdirSync(TEST_DATA_MODEL_NODE_ROOT, {withFileTypes: true}) .filter(dir => dir.isDirectory() && dir.name.startsWith('opset')) .map(dir => dir.name.slice(5)); diff --git a/js/web/test/test-main.ts b/js/web/test/test-main.ts index 072ec96976bb3..e614cc8e67e71 100644 --- a/js/web/test/test-main.ts +++ b/js/web/test/test-main.ts @@ -12,8 +12,7 @@ import {Logger} from '../lib/onnxjs/instrument'; import {Test} from './test-types'; -if (ORT_WEB_TEST_CONFIG.model.some( - testGroup => testGroup.tests.some(test => ['cpu', 'dml', 'cuda', 'tensorrt'].includes(test.backend!)))) { +if (ORT_WEB_TEST_CONFIG.model.some(testGroup => testGroup.tests.some(test => test.backend === 'cpu'))) { // require onnxruntime-node require('../../node'); } diff --git a/js/web/test/test-runner.ts b/js/web/test/test-runner.ts index f5168c193dd1f..9802f00f7a866 100644 --- a/js/web/test/test-runner.ts +++ b/js/web/test/test-runner.ts @@ -282,7 +282,7 @@ export class TensorResultValidator { private static isHalfFloat: boolean|undefined; constructor(backend: string) { - if (backend === 'cpu' || backend === 'dml' || backend === 'cuda' || backend === 'tensorrt') { + if (backend === 'cpu') { this.absoluteThreshold = CPU_THRESHOLD_ABSOLUTE_ERROR; this.relativeThreshold = CPU_THRESHOLD_RELATIVE_ERROR; } else if (backend === 'webgl') { diff --git a/onnxruntime/contrib_ops/js/bias_add.cc b/onnxruntime/contrib_ops/js/bias_add.cc index 51a1073f5ce56..9e70dead6a5da 100644 --- a/onnxruntime/contrib_ops/js/bias_add.cc +++ b/onnxruntime/contrib_ops/js/bias_add.cc @@ -7,13 +7,15 @@ namespace onnxruntime { namespace contrib { namespace js { +using onnxruntime::js::JsepSupportedFloatTypes; + ONNX_OPERATOR_KERNEL_EX( BiasAdd, kMSDomain, 1, kJsExecutionProvider, (*KernelDefBuilder::Create()) - .TypeConstraint("T", DataTypeImpl::GetTensorType()), + .TypeConstraint("T", JsepSupportedFloatTypes()), BiasAdd); } // namespace js diff --git a/onnxruntime/contrib_ops/js/bias_split_gelu.cc b/onnxruntime/contrib_ops/js/bias_split_gelu.cc index efc52af2330ba..e16aa4367d1c7 100644 --- a/onnxruntime/contrib_ops/js/bias_split_gelu.cc +++ b/onnxruntime/contrib_ops/js/bias_split_gelu.cc @@ -7,13 +7,15 @@ namespace onnxruntime { namespace contrib { namespace js { +using onnxruntime::js::JsepSupportedFloatTypes; + ONNX_OPERATOR_KERNEL_EX( BiasSplitGelu, kMSDomain, 1, kJsExecutionProvider, (*KernelDefBuilder::Create()) - .TypeConstraint("T", DataTypeImpl::GetTensorType()), + .TypeConstraint("T", JsepSupportedFloatTypes()), BiasSplitGelu); } // namespace js