2021-04-16 08:33:10 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
2023-06-12 19:05:11 +00:00
|
|
|
import {InferenceSession} from './inference-session.js';
|
|
|
|
|
import {OnnxValue} from './onnx-value.js';
|
2023-09-30 02:05:10 +00:00
|
|
|
import {TrainingSession} from './training-session.js';
|
2021-04-16 08:33:10 +00:00
|
|
|
|
2021-09-21 00:54:46 +00:00
|
|
|
/**
|
2023-09-06 03:40:23 +00:00
|
|
|
* @ignore
|
2021-09-21 00:54:46 +00:00
|
|
|
*/
|
2021-04-16 08:33:10 +00:00
|
|
|
export declare namespace SessionHandler {
|
|
|
|
|
type FeedsType = {[name: string]: OnnxValue};
|
|
|
|
|
type FetchesType = {[name: string]: OnnxValue | null};
|
|
|
|
|
type ReturnType = {[name: string]: OnnxValue};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-09-30 02:05:10 +00:00
|
|
|
* Represents shared SessionHandler functionality
|
2021-09-21 00:54:46 +00:00
|
|
|
*
|
2023-09-06 03:40:23 +00:00
|
|
|
* @ignore
|
2021-04-16 08:33:10 +00:00
|
|
|
*/
|
2023-09-30 02:05:10 +00:00
|
|
|
interface SessionHandler {
|
2021-04-16 08:33:10 +00:00
|
|
|
dispose(): Promise<void>;
|
|
|
|
|
|
2021-04-27 07:04:25 +00:00
|
|
|
readonly inputNames: readonly string[];
|
|
|
|
|
readonly outputNames: readonly string[];
|
2023-09-30 02:05:10 +00:00
|
|
|
}
|
2021-04-27 07:04:25 +00:00
|
|
|
|
2023-09-30 02:05:10 +00:00
|
|
|
/**
|
|
|
|
|
* Represent a handler instance of an inference session.
|
|
|
|
|
*
|
|
|
|
|
* @ignore
|
|
|
|
|
*/
|
|
|
|
|
export interface InferenceSessionHandler extends SessionHandler {
|
2021-04-27 07:04:25 +00:00
|
|
|
startProfiling(): void;
|
|
|
|
|
endProfiling(): void;
|
2021-04-16 08:33:10 +00:00
|
|
|
|
|
|
|
|
run(feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType,
|
|
|
|
|
options: InferenceSession.RunOptions): Promise<SessionHandler.ReturnType>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-30 02:05:10 +00:00
|
|
|
/**
|
|
|
|
|
* Represent a handler instance of a training inference session.
|
|
|
|
|
*
|
|
|
|
|
* @ignore
|
|
|
|
|
*/
|
|
|
|
|
export interface TrainingSessionHandler extends SessionHandler {
|
2023-12-04 21:37:14 +00:00
|
|
|
readonly evalInputNames: readonly string[];
|
|
|
|
|
readonly evalOutputNames: readonly string[];
|
|
|
|
|
|
2023-12-12 01:36:54 +00:00
|
|
|
lazyResetGrad(): Promise<void>;
|
2023-09-30 02:05:10 +00:00
|
|
|
runTrainStep(
|
|
|
|
|
feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType,
|
|
|
|
|
options: InferenceSession.RunOptions): Promise<SessionHandler.ReturnType>;
|
2023-12-04 21:37:14 +00:00
|
|
|
runOptimizerStep(options: InferenceSession.RunOptions): Promise<void>;
|
|
|
|
|
runEvalStep(
|
|
|
|
|
feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType,
|
|
|
|
|
options: InferenceSession.RunOptions): Promise<SessionHandler.ReturnType>;
|
2023-09-30 02:05:10 +00:00
|
|
|
|
2023-11-27 18:30:13 +00:00
|
|
|
getParametersSize(trainableOnly: boolean): Promise<number>;
|
[js/common] fix typedoc warnings (#19933)
### Description
Fix a few warnings in typedoc (for generating JS API):
```
[warning] The signature TrainingSession.loadParametersBuffer has an @param with name "buffer", which was not used.
[warning] NonTensorType, defined in ./lib/onnx-value.ts, is referenced by OnnxValue but not included in the documentation.
[warning] TensorFactory, defined in ./lib/tensor-factory.ts, is referenced by Tensor but not included in the documentation.
[warning] ExternalDataFileType, defined in ./lib/onnx-model.ts, is referenced by InferenceSession.SessionOptions.externalData but not included in the documentation.
[warning] TensorToDataUrlOptions, defined in ./lib/tensor-conversion.ts, is referenced by Tensor.toDataURL.toDataURL.options but not included in the documentation.
[warning] TensorToImageDataOptions, defined in ./lib/tensor-conversion.ts, is referenced by Tensor.toImageData.toImageData.options but not included in the documentation.
[warning] Failed to resolve link to "GpuBufferType" in comment for Env.WebGpuFlags.adapter.
[warning] Failed to resolve link to "GpuBufferType" in comment for Env.WebGpuFlags.device.
```
Changes highlighted:
- Merge `CoreMlExecutionProviderOption` and
`CoreMLExecutionProviderOption`. They expose 2 set of different options
for React-native and ORT nodejs binding. This should be fixed in future.
- Fix a few inconsistency of names between JSDoc and parameters
- Fix broken type links
- Exclude trace functions
2024-03-16 02:01:50 +00:00
|
|
|
loadParametersBuffer(buffer: Uint8Array, trainableOnly: boolean): Promise<void>;
|
2023-11-27 18:30:13 +00:00
|
|
|
getContiguousParameters(trainableOnly: boolean): Promise<OnnxValue>;
|
2023-09-30 02:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-16 08:33:10 +00:00
|
|
|
/**
|
|
|
|
|
* Represent a backend that provides implementation of model inferencing.
|
2021-09-21 00:54:46 +00:00
|
|
|
*
|
2023-09-06 03:40:23 +00:00
|
|
|
* @ignore
|
2021-04-16 08:33:10 +00:00
|
|
|
*/
|
|
|
|
|
export interface Backend {
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the backend asynchronously. Should throw when failed.
|
|
|
|
|
*/
|
[js/web] revise backend registration (#18715)
### Description
This PR revises the backend registration.
The following describes the expected behavior after this change:
(**bolded are changed behavior**)
- (ort.min.js - built without webgpu support)
- loading: do not register 'webgpu' backend
- creating session without EP list: use default EP list ['webnn', 'cpu',
'wasm']
- creating session with ['webgpu'] as EP list: should fail with backend
not available
- (ort.webgpu.min.js - built with webgpu support)
- loading: **always register 'webgpu' backend**
( previous behavior: only register 'webgpu' backend when `navigator.gpu`
is available)
- creating session without EP list: use default EP list ['webgpu',
'webnn', 'cpu', 'wasm']
- when WebGPU is available (win): use WebGPU backend
- when WebGPU is unavailable (android): **should fail backend init,**
and try to use next backend in the list, 'webnn'
(previous behavior: does not fail backend init, but fail in JSEP init,
which was too late to switch to next backend)
- creating session with ['webgpu'] as EP list
- when WebGPU is available (win): use WebGPU backend
- when WebGPU is unavailable (android): **should fail backend init, and
because no more EP listed, fail.
related PRs: #18190 #18144
2023-12-20 22:45:55 +00:00
|
|
|
init(backendName: string): Promise<void>;
|
2021-04-16 08:33:10 +00:00
|
|
|
|
2023-09-30 02:05:10 +00:00
|
|
|
createInferenceSessionHandler(uriOrBuffer: string|Uint8Array, options?: InferenceSession.SessionOptions):
|
|
|
|
|
Promise<InferenceSessionHandler>;
|
|
|
|
|
|
|
|
|
|
createTrainingSessionHandler?
|
[js/common] fix typedoc warnings (#19933)
### Description
Fix a few warnings in typedoc (for generating JS API):
```
[warning] The signature TrainingSession.loadParametersBuffer has an @param with name "buffer", which was not used.
[warning] NonTensorType, defined in ./lib/onnx-value.ts, is referenced by OnnxValue but not included in the documentation.
[warning] TensorFactory, defined in ./lib/tensor-factory.ts, is referenced by Tensor but not included in the documentation.
[warning] ExternalDataFileType, defined in ./lib/onnx-model.ts, is referenced by InferenceSession.SessionOptions.externalData but not included in the documentation.
[warning] TensorToDataUrlOptions, defined in ./lib/tensor-conversion.ts, is referenced by Tensor.toDataURL.toDataURL.options but not included in the documentation.
[warning] TensorToImageDataOptions, defined in ./lib/tensor-conversion.ts, is referenced by Tensor.toImageData.toImageData.options but not included in the documentation.
[warning] Failed to resolve link to "GpuBufferType" in comment for Env.WebGpuFlags.adapter.
[warning] Failed to resolve link to "GpuBufferType" in comment for Env.WebGpuFlags.device.
```
Changes highlighted:
- Merge `CoreMlExecutionProviderOption` and
`CoreMLExecutionProviderOption`. They expose 2 set of different options
for React-native and ORT nodejs binding. This should be fixed in future.
- Fix a few inconsistency of names between JSDoc and parameters
- Fix broken type links
- Exclude trace functions
2024-03-16 02:01:50 +00:00
|
|
|
(checkpointStateUriOrBuffer: TrainingSession.UriOrBuffer, trainModelUriOrBuffer: TrainingSession.UriOrBuffer,
|
|
|
|
|
evalModelUriOrBuffer: TrainingSession.UriOrBuffer, optimizerModelUriOrBuffer: TrainingSession.UriOrBuffer,
|
2023-09-30 02:05:10 +00:00
|
|
|
options: InferenceSession.SessionOptions): Promise<TrainingSessionHandler>;
|
2021-04-16 08:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-12 19:05:11 +00:00
|
|
|
export {registerBackend} from './backend-impl.js';
|