Skip to content

Commit

Permalink
[js/webgpu] Manage model download with a specific unittest option (mi…
Browse files Browse the repository at this point in the history
…crosoft#22214)

Currently in debug mode, unit test will always download models to local
file system, which is a bit annoying. This PR fixes this by adding a
specific option to enable model download.
  • Loading branch information
Yang Gu authored and Ishwar Raut committed Nov 19, 2024
1 parent a13fc1d commit c01d54a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions js/web/script/test-runner-cli-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Options:
node
bs (for BrowserStack tests)
-p, --profile Enable profiler.
-m, --download-model Enable model download.
Profiler will generate extra logs which include the information of events time consumption
-t, --trace Enable trace.
-P[=<...>], --perf[=<...>] Generate performance number. Cannot be used with flag --debug.
Expand Down Expand Up @@ -171,6 +172,11 @@ export interface TestRunnerCliArgs {
*/
profile: boolean;

/**
* whether to enable model download
*/
downloadModel: boolean;

/**
* Whether to enable file cache
*/
Expand Down Expand Up @@ -431,6 +437,9 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs
logLevel = 'verbose';
}

// Option: -m, --download-model
const downloadModel = args['download-model'] || args.m ? true : false;

// Option: -t, --trace
const trace = parseBooleanArg(args.trace || args.t, false);

Expand Down Expand Up @@ -517,6 +526,7 @@ export function parseTestRunnerCliArgs(cmdlineArgs: string[]): TestRunnerCliArgs
env: env as TestRunnerCliArgs['env'],
logConfig,
profile,
downloadModel,
times: perf ? times : undefined,
ioBindingMode: ioBindingMode as TestRunnerCliArgs['ioBindingMode'],
optimizedModelFilePath,
Expand Down
1 change: 1 addition & 0 deletions js/web/script/test-runner-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ async function main() {
op: opTestGroups,
log: args.logConfig,
profile: args.profile,
downloadModel: args.downloadModel,
options: {
sessionOptions: {
graphOptimizationLevel: args.graphOptimizationLevel,
Expand Down
6 changes: 5 additions & 1 deletion js/web/test/test-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ for (const group of ORT_WEB_TEST_CONFIG.op) {

before('Initialize Context', async () => {
context = useProtoOpTest
? new ProtoOpTestContext(test, ORT_WEB_TEST_CONFIG.options.sessionOptions)
? new ProtoOpTestContext(
test,
ORT_WEB_TEST_CONFIG.downloadModel,
ORT_WEB_TEST_CONFIG.options.sessionOptions,
)
: new OpTestContext(test);
await context.init();
if (ORT_WEB_TEST_CONFIG.profile) {
Expand Down
4 changes: 2 additions & 2 deletions js/web/test/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ export class ProtoOpTestContext {
readonly ioBindingMode: Test.IOBindingMode;
constructor(
test: Test.OperatorTest,
private readonly downloadModel: boolean,
private readonly sessionOptions: ort.InferenceSession.SessionOptions = {},
) {
const opsetImport = onnx.OperatorSetIdProto.create(test.opset);
Expand Down Expand Up @@ -1074,8 +1075,7 @@ export class ProtoOpTestContext {
this.ioBindingMode = test.ioBinding;
this.loadedData = onnx.ModelProto.encode(model).finish().slice();

// in debug mode, open a new tab in browser for the generated onnx model.
if (ort.env.debug) {
if (this.downloadModel) {
const modelFile = new File([this.loadedData], `op_test_generated_model_${test.name}.onnx`, {
type: 'application/octet-stream',
});
Expand Down
1 change: 1 addition & 0 deletions js/web/test/test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export declare namespace Test {

log: ReadonlyArray<{ category: string; config: Logger.Config }>;
profile: boolean;
downloadModel: boolean;
options: Options;
}
}

0 comments on commit c01d54a

Please sign in to comment.