Skip to content

Commit 45ff957

Browse files
fs-eireqjia7axingingsatyajandhyalaYang Gu
authoredMar 29, 2024··
1.17.3 cherry-picks for ORT Web changes (#19926)
### Description This PR is a preview of cherry-picks for ort-web to `rel-1.17.3` based on `rel-1.17.2`. <details> <summary>Changes of ort-web to cherry-pick</summary> The following commits are from main branch. `o` stands for pick, and `x` stands for skip. ``` o 2e0a388 [js/webgpu] Add HardSigmoid support (#19215) o d226e40 [js/webgpu] set query type in onRunStart (#19202) o 61610ff [js/webgpu] Add FusedConv clip test case (#18900) o a33b5bd [JS/WebGPU] Added Uniforms to SkipLayerNorm. (#18788) o 591f90c [js/webgpu] Fix issue of timestamp query (#19258) o 7252c6e [WebNN EP] Support WebNN async API with Asyncify (#19145) o 5b06505 [js/webgpu] Fix Tanh explosion (#19201) o 656ca66 [js/webgpu] Support uniforms for conv, conv transpose, conv grouped (#18753) o a3f0e24 [js/webgpu] Support f16 uniform (#19098) o 9e69606 fix f16 for attention, enable slice and flatten for more types (#19262) o 624b4e2 [js/webgpu] Remove enableShapesUniforms (#19279) o 90883a3 [js/webgpu] Add hardSigmoid activation for fusedConv (#19233) o 85cef0a [js/webgpu] Support capture and replay for jsep (#18989) o d73131c [js/webgpu] Use DataType as uniform cpu type (#19281) o dd1f6cc [js/webgpu] resolve codescan alert (#19343) o 3a2ab19 [js/webgpu] Refactor createTensorShapeVariables (#18883) o efc17e7 [js/webgpu] Fix the undefined push error (#19366) x 50806a7 [js/web] support external data in npm test (#19377) o ccbe264 [js/webgpu] Add LeakyRelu activation for fusedConv (#19369) o 5ff27ef [js/webgpu] support customop FastGelu (#19392) x 03be65e [js/web] fix types exports in package.json (#19458) o 06269a3 [js/webgpu] allow uint8 tensors for webgpu (#19545) o dfeda90 [JS/WebGPU] Add MatMulNBits (#19446) o 1b48054 [js/webgpu] Create Split indices helpers by rank, not by shape (#19554) o 3fe2c13 [js] small fix to workaround formatter (#19400) x 70567a4 [js/web] use ApiTensor insteadof onnxjs Tensor in TensorResultValidator (#19358) o 6e04e36 [js/common] upgrade tsc in common from 4.9.5 to 5.2.2 (#19317) o 58f4921 [js] changes to allow Float16Array if any polyfill is available (#19305) o 57d6819 [js/web] Fix fused-conv is not included in npm test (#19581) o ebd220b Misspelling in README.md (#19433) o 38c3432 Bump ip from 1.1.8 to 1.1.9 in /js/react_native (#19582) o fe82fcc [js/webgpu] Fix Conv2DTransposeMatMul f16 compilation failure (#19596) o 76a2a48 Bump ip from 1.1.8 to 1.1.9 in /js/react_native/e2e (#19583) o 29b1106 [node] Switch to setImmediate to avoid starving the Node.js event loop (#19610) o ae3d73c [JS/WebGPU] Fix Split and Where to handle corner cases. (#19613) o aec2389 [js/webgpu] allows a ProgramInfo's RunData to use zero sized output (#19614) o bb43a0f [js/webgpu] minor fixes to make tinyllama work (#19564) o 0edb035 [js/web] fix suite test list for zero sized tensor (#19638) o 3cb81cd [js/common] move 'env.wasm.trace' to 'env.trace' (#19617) o e30618d [js/webgpu] use Headless for webgpu test by default (#19702) o f06164e [js/web] transfer input buffer back to caller thread (#19677) x a788514 [js/web] dump debug logs for karma for diagnose purpose (#19785) o 24b72d2 [JS/WebGPU] Preserve zero size input tensor dims. (#19737) o 4538d31 [js/webgpu] expose a few properties in WebGPU API (#19857) o 53de2d8 [js/webgpu] Enable GroupedConvVectorize path (#19791) o ed250b8 [JS/WebGPU] Optimize MatMulNBits (#19852) x e771a76 [js/test] align web test runner flags with ort.env (#19790) o 79e50ae [js/web] rewrite backend resolve to allow multiple EPs (#19735) o acb0df2 Fix #19931 broken Get Started link of "ONNX Runtime JavaScript API" page (#19932) o b29849a [js/common] fix typedoc warnings (#19933) o afdab62 Bump follow-redirects from 1.15.4 to 1.15.6 in /js/web (#19949) o 28ad6c3 Bump follow-redirects from 1.15.4 to 1.15.6 in /js/node (#19951) o 7e0d424 accumulate in fp32 for Reduce* (#19868) o 4c6a6a3 [js/webgpu] Fix NAN caused by un-initialized buffer in instance-norm (#19387) o 01c7aaf [js/webgpu] allow setting env.webgpu.adapter (#19940) o c45cff6 [js/webgpu] fix maxpool / fp16 (#19981) ``` </details> <details> <summary>Cherry-pick commandlines</summary> ```sh git cherry-pick 2e0a388 git cherry-pick d226e40 git cherry-pick 61610ff git cherry-pick a33b5bd git cherry-pick 591f90c git cherry-pick 7252c6e git cherry-pick 5b06505 git cherry-pick 656ca66 git cherry-pick a3f0e24 git cherry-pick 9e69606 git cherry-pick 624b4e2 git cherry-pick 90883a3 git cherry-pick 85cef0a #<<<<< Note: conflicts git cherry-pick d73131c git cherry-pick dd1f6cc git cherry-pick 3a2ab19 git cherry-pick efc17e7 git cherry-pick ccbe264 git cherry-pick 5ff27ef git cherry-pick 06269a3 git cherry-pick dfeda90 git cherry-pick 1b48054 git cherry-pick 3fe2c13 git cherry-pick 6e04e36 git cherry-pick 58f4921 git cherry-pick 57d6819 git cherry-pick ebd220b git cherry-pick 38c3432 git cherry-pick fe82fcc git cherry-pick 76a2a48 git cherry-pick 29b1106 git cherry-pick ae3d73c git cherry-pick aec2389 git cherry-pick bb43a0f git cherry-pick 0edb035 git cherry-pick 3cb81cd git cherry-pick e30618d git cherry-pick f06164e git cherry-pick 24b72d2 git cherry-pick 4538d31 git cherry-pick 53de2d8 git cherry-pick ed250b8 git cherry-pick 79e50ae git cherry-pick acb0df2 git cherry-pick b29849a git cherry-pick afdab62 git cherry-pick 28ad6c3 git cherry-pick 7e0d424 git cherry-pick 4c6a6a3 git cherry-pick 01c7aaf git cherry-pick c45cff6 ``` </details> <details> <summary>Cherry-pick conflicts</summary> - 85cef0a #18989 this change is for enabling graph capture feature for JSEP, and it is done after ROCM EP enabled graph capture feature. However, the ROCM EP graph capture feature is not cherry-picked in rel-1.17.2. </details> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Jiajia Qin <[email protected]> Co-authored-by: Xu Xing <[email protected]> Co-authored-by: satyajandhyala <[email protected]> Co-authored-by: Yang Gu <[email protected]> Co-authored-by: Wanming Lin <[email protected]> Co-authored-by: Jiajie Hu <[email protected]> Co-authored-by: Guenther Schmuelling <[email protected]> Co-authored-by: Matttttt <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Segev Finer <[email protected]> Co-authored-by: Belem Zhang <[email protected]>
1 parent 046d06f commit 45ff957

File tree

114 files changed

+5493
-1350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5493
-1350
lines changed
 

‎js/common/lib/backend-impl.ts

+90-31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
import {Backend} from './backend.js';
5+
import {InferenceSession} from './inference-session.js';
56

67
interface BackendInfo {
78
backend: Backend;
@@ -10,6 +11,7 @@ interface BackendInfo {
1011
initPromise?: Promise<void>;
1112
initialized?: boolean;
1213
aborted?: boolean;
14+
error?: string;
1315
}
1416

1517
const backends: Map<string, BackendInfo> = new Map();
@@ -60,43 +62,100 @@ export const registerBackend = (name: string, backend: Backend, priority: number
6062
};
6163

6264
/**
63-
* Resolve backend by specified hints.
65+
* Try to resolve and initialize a backend.
6466
*
65-
* @param backendHints - a list of execution provider names to lookup. If omitted use registered backends as list.
66-
* @returns a promise that resolves to the backend.
67+
* @param backendName - the name of the backend.
68+
* @returns the backend instance if resolved and initialized successfully, or an error message if failed.
69+
*/
70+
const tryResolveAndInitializeBackend = async(backendName: string): Promise<Backend|string> => {
71+
const backendInfo = backends.get(backendName);
72+
if (!backendInfo) {
73+
return 'backend not found.';
74+
}
75+
76+
if (backendInfo.initialized) {
77+
return backendInfo.backend;
78+
} else if (backendInfo.aborted) {
79+
return backendInfo.error!;
80+
} else {
81+
const isInitializing = !!backendInfo.initPromise;
82+
try {
83+
if (!isInitializing) {
84+
backendInfo.initPromise = backendInfo.backend.init(backendName);
85+
}
86+
await backendInfo.initPromise;
87+
backendInfo.initialized = true;
88+
return backendInfo.backend;
89+
} catch (e) {
90+
if (!isInitializing) {
91+
backendInfo.error = `${e}`;
92+
backendInfo.aborted = true;
93+
}
94+
return backendInfo.error!;
95+
} finally {
96+
delete backendInfo.initPromise;
97+
}
98+
}
99+
};
100+
101+
/**
102+
* Resolve execution providers from the specific session options.
103+
*
104+
* @param options - the session options object.
105+
* @returns a promise that resolves to a tuple of an initialized backend instance and a session options object with
106+
* filtered EP list.
67107
*
68108
* @ignore
69109
*/
70-
export const resolveBackend = async(backendHints: readonly string[]): Promise<Backend> => {
71-
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
72-
const errors = [];
73-
for (const backendName of backendNames) {
74-
const backendInfo = backends.get(backendName);
75-
if (backendInfo) {
76-
if (backendInfo.initialized) {
77-
return backendInfo.backend;
78-
} else if (backendInfo.aborted) {
79-
continue; // current backend is unavailable; try next
80-
}
110+
export const resolveBackendAndExecutionProviders = async(options: InferenceSession.SessionOptions):
111+
Promise<[backend: Backend, options: InferenceSession.SessionOptions]> => {
112+
// extract backend hints from session options
113+
const eps = options.executionProviders || [];
114+
const backendHints = eps.map(i => typeof i === 'string' ? i : i.name);
115+
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
81116

82-
const isInitializing = !!backendInfo.initPromise;
83-
try {
84-
if (!isInitializing) {
85-
backendInfo.initPromise = backendInfo.backend.init(backendName);
117+
// try to resolve and initialize all requested backends
118+
let backend: Backend|undefined;
119+
const errors = [];
120+
const availableBackendNames = new Set<string>();
121+
for (const backendName of backendNames) {
122+
const resolveResult = await tryResolveAndInitializeBackend(backendName);
123+
if (typeof resolveResult === 'string') {
124+
errors.push({name: backendName, err: resolveResult});
125+
} else {
126+
if (!backend) {
127+
backend = resolveResult;
128+
}
129+
if (backend === resolveResult) {
130+
availableBackendNames.add(backendName);
131+
}
86132
}
87-
await backendInfo.initPromise;
88-
backendInfo.initialized = true;
89-
return backendInfo.backend;
90-
} catch (e) {
91-
if (!isInitializing) {
92-
errors.push({name: backendName, err: e});
133+
}
134+
135+
// if no backend is available, throw error.
136+
if (!backend) {
137+
throw new Error(`no available backend found. ERR: ${errors.map(e => `[${e.name}] ${e.err}`).join(', ')}`);
138+
}
139+
140+
// for each explicitly requested backend, if it's not available, output warning message.
141+
for (const {name, err} of errors) {
142+
if (backendHints.includes(name)) {
143+
// eslint-disable-next-line no-console
144+
console.warn(`removing requested execution provider "${
145+
name}" from session options because it is not available: ${err}`);
93146
}
94-
backendInfo.aborted = true;
95-
} finally {
96-
delete backendInfo.initPromise;
97147
}
98-
}
99-
}
100148

101-
throw new Error(`no available backend found. ERR: ${errors.map(e => `[${e.name}] ${e.err}`).join(', ')}`);
102-
};
149+
const filteredEps = eps.filter(i => availableBackendNames.has(typeof i === 'string' ? i : i.name));
150+
151+
return [
152+
backend, new Proxy(options, {
153+
get: (target, prop) => {
154+
if (prop === 'executionProviders') {
155+
return filteredEps;
156+
}
157+
return Reflect.get(target, prop);
158+
}
159+
})
160+
];
161+
};

‎js/common/lib/backend.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface TrainingSessionHandler extends SessionHandler {
5858
options: InferenceSession.RunOptions): Promise<SessionHandler.ReturnType>;
5959

6060
getParametersSize(trainableOnly: boolean): Promise<number>;
61-
loadParametersBuffer(array: Uint8Array, trainableOnly: boolean): Promise<void>;
61+
loadParametersBuffer(buffer: Uint8Array, trainableOnly: boolean): Promise<void>;
6262
getContiguousParameters(trainableOnly: boolean): Promise<OnnxValue>;
6363
}
6464

@@ -77,8 +77,8 @@ export interface Backend {
7777
Promise<InferenceSessionHandler>;
7878

7979
createTrainingSessionHandler?
80-
(checkpointStateUriOrBuffer: TrainingSession.URIorBuffer, trainModelUriOrBuffer: TrainingSession.URIorBuffer,
81-
evalModelUriOrBuffer: TrainingSession.URIorBuffer, optimizerModelUriOrBuffer: TrainingSession.URIorBuffer,
80+
(checkpointStateUriOrBuffer: TrainingSession.UriOrBuffer, trainModelUriOrBuffer: TrainingSession.UriOrBuffer,
81+
evalModelUriOrBuffer: TrainingSession.UriOrBuffer, optimizerModelUriOrBuffer: TrainingSession.UriOrBuffer,
8282
options: InferenceSession.SessionOptions): Promise<TrainingSessionHandler>;
8383
}
8484

0 commit comments

Comments
 (0)
Please sign in to comment.