Skip to content

Commit

Permalink
[Node.js binding] Fix 1.17.3 - reversion.1 (#20397)
Browse files Browse the repository at this point in the history
### Description

This reversion bumped version of onnxruntime-node to `1.17.3-rev.1` and
fixed the following issues:

- Fixed the release file name `onnxruntime-linux-x64-cuda12-1.17.3.tgz`
=> `onnxruntime-linux-x64-gpu-cuda12-1.17.3.tgz`
- Fixed tarball extraction failure (may cause incorrect file size) due
to Node.js script early exit. Fixed by moving callbacks to `tar.t()` and
adding event listener on `finish` so the script will not exit early.
- Allow using env var `ONNXRUNTIME_NODE_INSTALL_CUDA` as an alternative
of commandline flag `--onnxruntime_node_install_cuda` to customize
behavior of CUDA EP installation.
  • Loading branch information
fs-eire authored Apr 22, 2024
1 parent b9999d2 commit 0453cd7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion js/node/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
// This file is generated by /js/scripts/update-version.ts
// Do not modify file content manually.

export const version = '1.17.3';
export const version = '1.17.3-rev.1';
4 changes: 2 additions & 2 deletions js/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
3
]
},
"version": "1.17.3",
"version": "1.17.3-rev.1",
"dependencies": {
"onnxruntime-common": "file:../common",
"tar": "^7.0.1"
Expand Down
32 changes: 20 additions & 12 deletions js/node/script/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const {Readable} = require('stream');
// --onnxruntime-node-install-cuda=v12 Force install the CUDA EP binaries for CUDA 12.
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
//
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL_CUDA"
//
// If the flag is not provided, the script will only install the CUDA EP binaries when:
// - The platform is Linux/x64.
// - The binaries are not already present in the package.
Expand All @@ -42,7 +44,7 @@ const IS_LINUX_X64 = os.platform() === 'linux' && os.arch() === 'x64';
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v3/linux/x64');
const BIN_FOLDER_EXISTS = fs.existsSync(BIN_FOLDER);
const CUDA_DLL_EXISTS = fs.existsSync(path.join(BIN_FOLDER, 'libonnxruntime_providers_cuda.so'));
const ORT_VERSION = require('../package.json').version;
const ORT_VERSION = '1.17.3';

const npm_config_local_prefix = process.env.npm_config_local_prefix;
const npm_package_json = process.env.npm_package_json;
Expand All @@ -58,7 +60,7 @@ if (NO_INSTALL || !shouldInstall) {
const artifactUrl = {
11: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-${
ORT_VERSION}.tgz`,
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-cuda12-${
12: `https://github.com/microsoft/onnxruntime/releases/download/v${ORT_VERSION}/onnxruntime-linux-x64-gpu-cuda12-${
ORT_VERSION}.tgz`
}[INSTALL_CUDA_FLAG || tryGetCudaVersion()];
console.log(`Downloading "${artifactUrl}"...`);
Expand All @@ -79,15 +81,19 @@ Use "--onnxruntime-node-install-cuda=skip" to skip the installation. You will st
]);

Readable.fromWeb(res.body)
.pipe(tar.t())
.on('entry',
(entry) => {
const filename = path.basename(entry.path);
if (entry.type === 'File' && FILES.has(filename)) {
console.log(`Extracting "${filename}" to "${BIN_FOLDER}"...`);
entry.pipe(fs.createWriteStream(path.join(BIN_FOLDER, filename)));
}
})
.pipe(tar.t({
strict: true,
onentry: (entry) => {
const filename = path.basename(entry.path);
if (entry.type === 'File' && FILES.has(filename)) {
console.log(`Extracting "${filename}" to "${BIN_FOLDER}"...`);
entry.pipe(fs.createWriteStream(path.join(BIN_FOLDER, filename)));
entry.on('finish', () => {
console.log(`Finished extracting "${filename}".`);
});
}
}
}))
.on('error', (err) => {
throw new Error(`Failed to extract the binaries: ${err.message}.
Expand All @@ -105,7 +111,7 @@ function tryGetCudaVersion() {
}

function parseInstallCudaFlag() {
let flag = process.env.npm_config_onnxruntime_node_install_cuda;
let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda;
if (!flag) {
for (let i = 0; i < process.argv.length; i++) {
if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) {
Expand All @@ -118,6 +124,8 @@ function parseInstallCudaFlag() {
}
switch (flag) {
case 'true':
case '1':
case 'ON':
return tryGetCudaVersion();
case 'v11':
return 11;
Expand Down

0 comments on commit 0453cd7

Please sign in to comment.