Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cuda by default and bump onnxruntime-node version #945

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@huggingface/jinja": "^0.2.2"
},
"optionalDependencies": {
"onnxruntime-node": "1.14.0"
"onnxruntime-node": "~1.19.0"
},
"devDependencies": {
"@types/jest": "^29.5.1",
Expand Down
5 changes: 3 additions & 2 deletions src/backends/onnx.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ export let ONNX;

export const executionProviders = [
// 'webgpu',
'wasm'
];

if (typeof process !== 'undefined' && process?.release?.name === 'node') {
// Running in a node-like environment.
ONNX = ONNX_NODE.default ?? ONNX_NODE;

// Add `cpu` execution provider, with higher precedence that `wasm`.
executionProviders.unshift('cpu');
executionProviders.push('cuda', 'cpu');

} else {
// Running in a browser-environment
ONNX = ONNX_WEB.default ?? ONNX_WEB;

executionProviders.push('wasm');

// SIMD for WebAssembly does not operate correctly in some recent versions of iOS (16.4.x).
// As a temporary fix, we disable it for now.
// For more information, see: https://github.com/microsoft/onnxruntime/issues/15644
Expand Down
17 changes: 13 additions & 4 deletions src/utils/tensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,25 @@ export class Tensor {
*/
constructor(...args) {
if (args[0] instanceof ONNXTensor) {
const tensor = args[0];

// Create shallow copy
Object.assign(this, args[0]);
Object.assign(this, tensor);

// Object.assign() doesn't catch the data prop for some reason
this.data = tensor.data;
} else {
// Create new tensor
Object.assign(this, new ONNXTensor(
const tensor = new ONNXTensor(
/** @type {DataType} */(args[0]),
/** @type {Exclude<import('./maths.js').AnyTypedArray, Uint8ClampedArray>} */(args[1]),
args[2]
));
);

// Create new tensor
Object.assign(this, tensor);

// Object.assign() doesn't catch the data prop for some reason
this.data = tensor.data;
}

return new Proxy(this, {
Expand Down