From 747a04de5c48b452206d635c85c2d28864853d86 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Fri, 25 Apr 2025 15:45:33 -0700 Subject: [PATCH 01/15] ONNX Runtime improvements (experimental native webgpu; fix iOS) (#1231) * customize the wasm paths * update implementation * allow using 'webgpu' in nodejs binding * update version of onnxruntime-node * Upgrade onnxruntime-web to same version as onnxruntime-node * Update list of supported devices --------- Co-authored-by: Joshua Lochner <26504141+xenova@users.noreply.github.com> --- package-lock.json | 211 ++++++++++++------------------------------- package.json | 4 +- src/backends/onnx.js | 26 ++++-- src/env.js | 33 ++++++- src/utils/devices.js | 1 + 5 files changed, 112 insertions(+), 163 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9dbad1e69..0071d2e2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.3.4", - "onnxruntime-node": "1.21.0", - "onnxruntime-web": "1.22.0-dev.20250409-89f8206ba4", + "onnxruntime-node": "1.22.0-dev.20250418-c19a49615b", + "onnxruntime-web": "1.22.0-dev.20250418-c19a49615b", "sharp": "^0.34.1" }, "devDependencies": { @@ -1009,6 +1009,7 @@ "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", @@ -1025,6 +1026,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -1036,6 +1038,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, "engines": { "node": ">=12" }, @@ -1046,12 +1049,14 @@ "node_modules/@isaacs/cliui/node_modules/emoji-regex": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", - "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==" + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true }, "node_modules/@isaacs/cliui/node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", @@ -1068,6 +1073,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -1082,6 +1088,7 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, "dependencies": { "ansi-styles": "^6.1.0", "string-width": "^5.0.1", @@ -1094,17 +1101,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/@isaacs/fs-minipass": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz", - "integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==", - "dependencies": { - "minipass": "^7.0.4" - }, - "engines": { - "node": ">=18.0.0" - } - }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -2693,6 +2689,7 @@ "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, "optional": true, "engines": { "node": ">=14" @@ -3392,6 +3389,15 @@ "node": ">=0.4.0" } }, + "node_modules/adm-zip": { + "version": "0.5.16", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz", + "integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ==", + "license": "MIT", + "engines": { + "node": ">=12.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -3491,6 +3497,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -3499,6 +3506,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -3640,7 +3648,8 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true }, "node_modules/batch": { "version": "0.6.1", @@ -3987,14 +3996,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/chownr": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-3.0.0.tgz", - "integrity": "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==", - "engines": { - "node": ">=18" - } - }, "node_modules/chrome-trace-event": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.3.tgz", @@ -4294,6 +4295,7 @@ "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -4518,7 +4520,8 @@ "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", - "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true }, "node_modules/ee-first": { "version": "1.1.1", @@ -4549,7 +4552,8 @@ "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true }, "node_modules/encodeurl": { "version": "2.0.0", @@ -5044,6 +5048,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "dev": true, "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" @@ -5059,6 +5064,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, "engines": { "node": ">=14" }, @@ -5642,6 +5648,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, "engines": { "node": ">=8" } @@ -5770,7 +5777,8 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true }, "node_modules/isobject": { "version": "3.0.1", @@ -5894,6 +5902,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.1.2.tgz", "integrity": "sha512-kWmLKn2tRtfYMF/BakihVVRzBKOxz4gJMiL2Rj91WnAB5TPZumSH99R/Yf1qE1u4uRimvCSJfm6hnxohXeEXjQ==", + "dev": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -8909,82 +8918,11 @@ "version": "7.1.2", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", + "dev": true, "engines": { "node": ">=16 || 14 >=14.17" } }, - "node_modules/minizlib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.0.1.tgz", - "integrity": "sha512-umcy022ILvb5/3Djuu8LWeqUa8D68JaBzlttKeMWen48SjabqS3iY5w/vzeMzMUNhLDifyhbOwKDSznB1vvrwg==", - "dependencies": { - "minipass": "^7.0.4", - "rimraf": "^5.0.5" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/minizlib/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/minizlib/node_modules/glob": { - "version": "10.4.1", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.1.tgz", - "integrity": "sha512-2jelhlq3E4ho74ZyVLN03oKdAZVUa6UDZzFLVH1H7dnoax+y9qyaq8zBkfDIggjniU19z0wU18y16jMB2eyVIw==", - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^3.1.2", - "minimatch": "^9.0.4", - "minipass": "^7.1.2", - "path-scurry": "^1.11.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.18" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/minizlib/node_modules/minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/minizlib/node_modules/rimraf": { - "version": "5.0.7", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.7.tgz", - "integrity": "sha512-nV6YcJo5wbLW77m+8KjH8aB/7/rxQy9SZ0HY5shnwULfS+9nmTtVXAJET5NdZmCzA4fPI/Hm1wo/Po/4mopOdg==", - "dependencies": { - "glob": "^10.3.7" - }, - "bin": { - "rimraf": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=14.18" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", @@ -9167,15 +9105,15 @@ } }, "node_modules/onnxruntime-common": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.21.0.tgz", - "integrity": "sha512-Q632iLLrtCAVOTO65dh2+mNbQir/QNTVBG3h/QdZBpns7mZ0RYbLRBgGABPbpU9351AgYy7SJf1WaeVwMrBFPQ==", + "version": "1.22.0-dev.20250409-89f8206ba4", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.22.0-dev.20250409-89f8206ba4.tgz", + "integrity": "sha512-vDJMkfCfb0b1A836rgHj+ORuZf4B4+cc2bASQtpeoJLueuFc5DuYwjIZUBrSvx/fO5IrLjLz+oTrB3pcGlhovQ==", "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.21.0.tgz", - "integrity": "sha512-NeaCX6WW2L8cRCSqy3bInlo5ojjQqu2fD3D+9W5qb5irwxhEyWKXeH2vZ8W9r6VxaMPUan+4/7NDwZMtouZxEw==", + "version": "1.22.0-dev.20250418-c19a49615b", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.22.0-dev.20250418-c19a49615b.tgz", + "integrity": "sha512-++oEW2PNFFGuaLsJJIgq+RMs+DN5An0OB4gxEap4ohDUGgnczqNdNCt1VQEtL8XCK1tnNu0ntyOu69L0e2MJTA==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9184,15 +9122,15 @@ "linux" ], "dependencies": { + "adm-zip": "^0.5.16", "global-agent": "^3.0.0", - "onnxruntime-common": "1.21.0", - "tar": "^7.0.1" + "onnxruntime-common": "1.22.0-dev.20250409-89f8206ba4" } }, "node_modules/onnxruntime-web": { - "version": "1.22.0-dev.20250409-89f8206ba4", - "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.22.0-dev.20250409-89f8206ba4.tgz", - "integrity": "sha512-0uS76OPgH0hWCPrFKlL8kYVV7ckM7t/36HfbgoFw6Nd0CZVVbQC4PkrR8mBX8LtNUFZO25IQBqV2Hx2ho3FlbQ==", + "version": "1.22.0-dev.20250418-c19a49615b", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.22.0-dev.20250418-c19a49615b.tgz", + "integrity": "sha512-N4TlDmpqa8aW7nyJ2mhjQ448HStWQjXPaCS3nmZb3ImkkEgLizj8wWqibO7mMne58w7wXnek0nVp7Z9hFl8iCQ==", "license": "MIT", "dependencies": { "flatbuffers": "^25.1.24", @@ -9203,12 +9141,6 @@ "protobufjs": "^7.2.4" } }, - "node_modules/onnxruntime-web/node_modules/onnxruntime-common": { - "version": "1.22.0-dev.20250409-89f8206ba4", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.22.0-dev.20250409-89f8206ba4.tgz", - "integrity": "sha512-vDJMkfCfb0b1A836rgHj+ORuZf4B4+cc2bASQtpeoJLueuFc5DuYwjIZUBrSvx/fO5IrLjLz+oTrB3pcGlhovQ==", - "license": "MIT" - }, "node_modules/open": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/open/-/open-10.1.0.tgz", @@ -9339,6 +9271,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, "engines": { "node": ">=8" } @@ -9353,6 +9286,7 @@ "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" @@ -9368,6 +9302,7 @@ "version": "10.2.2", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "dev": true, "engines": { "node": "14 || >=16.14" } @@ -10156,6 +10091,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -10167,6 +10103,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, "engines": { "node": ">=8" } @@ -10409,6 +10346,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -10423,6 +10361,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -10436,6 +10375,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -10448,6 +10388,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -10554,44 +10495,6 @@ "node": ">=6" } }, - "node_modules/tar": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.2.0.tgz", - "integrity": "sha512-hctwP0Nb4AB60bj8WQgRYaMOuJYRAPMGiQUAotms5igN8ppfQM+IvjQ5HcKu1MaZh2Wy2KWVTe563Yj8dfc14w==", - "dependencies": { - "@isaacs/fs-minipass": "^4.0.0", - "chownr": "^3.0.0", - "minipass": "^7.1.0", - "minizlib": "^3.0.1", - "mkdirp": "^3.0.1", - "yallist": "^5.0.0" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/tar/node_modules/mkdirp": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", - "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", - "bin": { - "mkdirp": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/tar/node_modules/yallist": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", - "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", - "engines": { - "node": ">=18" - } - }, "node_modules/terser": { "version": "5.31.6", "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.6.tgz", @@ -11328,6 +11231,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "dependencies": { "isexe": "^2.0.0" }, @@ -11384,6 +11288,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", diff --git a/package.json b/package.json index f5f881fa0..f835af7c3 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.3.4", - "onnxruntime-node": "1.21.0", - "onnxruntime-web": "1.22.0-dev.20250409-89f8206ba4", + "onnxruntime-node": "1.22.0-dev.20250418-c19a49615b", + "onnxruntime-web": "1.22.0-dev.20250418-c19a49615b", "sharp": "^0.34.1" }, "devDependencies": { diff --git a/src/backends/onnx.js b/src/backends/onnx.js index a64f9d160..58b8114bb 100644 --- a/src/backends/onnx.js +++ b/src/backends/onnx.js @@ -38,6 +38,7 @@ const DEVICE_TO_EXECUTION_PROVIDER_MAPPING = Object.freeze({ webgpu: 'webgpu', // WebGPU cuda: 'cuda', // CUDA dml: 'dml', // DirectML + coreml: 'coreml', // CoreML webnn: { name: 'webnn', deviceType: 'cpu' }, // WebNN (default) 'webnn-npu': { name: 'webnn', deviceType: 'npu' }, // WebNN NPU @@ -63,13 +64,15 @@ if (ORT_SYMBOL in globalThis) { } else if (apis.IS_NODE_ENV) { ONNX = ONNX_NODE.default ?? ONNX_NODE; - // Updated as of ONNX Runtime 1.20.1 + // Updated as of ONNX Runtime 1.22.0-dev.20250418-c19a49615b // The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries. - // | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 | - // | ------------- | ----------- | ------------- | ----------------- | ----------- | --------- | ----------- | - // | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | - // | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ | - // | CUDA | ❌ | ❌ | ✔️ (CUDA v11.8) | ❌ | ❌ | ❌ | + // | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 | + // | --------------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | + // | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | + // | WebGPU (experimental) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | + // | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ | + // | CUDA | ❌ | ❌ | ✔️ (CUDA v12) | ❌ | ❌ | ❌ | + // | CoreML | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | switch (process.platform) { case 'win32': // Windows x64 and Windows arm64 supportedDevices.push('dml'); @@ -80,9 +83,11 @@ if (ORT_SYMBOL in globalThis) { } break; case 'darwin': // MacOS x64 and MacOS arm64 + supportedDevices.push('coreml'); break; } + supportedDevices.push('webgpu'); supportedDevices.push('cpu'); defaultDevices = ['cpu']; } else { @@ -180,9 +185,16 @@ if (ONNX_ENV?.wasm) { if ( // @ts-ignore Cannot find name 'ServiceWorkerGlobalScope'.ts(2304) !(typeof ServiceWorkerGlobalScope !== 'undefined' && self instanceof ServiceWorkerGlobalScope) + && env.backends.onnx.versions?.web && !ONNX_ENV.wasm.wasmPaths ) { - ONNX_ENV.wasm.wasmPaths = `https://cdn.jsdelivr.net/npm/@huggingface/transformers@${env.version}/dist/`; + const wasmPathPrefix = `https://cdn.jsdelivr.net/npm/onnxruntime-web@${env.backends.onnx.versions.web}/dist/`; + + ONNX_ENV.wasm.wasmPaths = apis.IS_SAFARI ? { + "mjs": `${wasmPathPrefix}/ort-wasm-simd-threaded.mjs`, + "wasm": `${wasmPathPrefix}/ort-wasm-simd-threaded.wasm`, + } + : wasmPathPrefix; } // TODO: Add support for loading WASM files from cached buffer when we upgrade to onnxruntime-web@1.19.0 diff --git a/src/env.js b/src/env.js index d591a8ab6..51d1fa587 100644 --- a/src/env.js +++ b/src/env.js @@ -30,11 +30,39 @@ const VERSION = '3.5.0'; // Check if various APIs are available (depends on environment) const IS_BROWSER_ENV = typeof window !== "undefined" && typeof window.document !== "undefined"; -const IS_WEBWORKER_ENV = typeof self !== "undefined" && self.constructor?.name === 'DedicatedWorkerGlobalScope'; +const IS_WEBWORKER_ENV = typeof self !== "undefined" && self.constructor?.name === 'DedicatedWorkerGlobalScope'; const IS_WEB_CACHE_AVAILABLE = typeof self !== "undefined" && 'caches' in self; const IS_WEBGPU_AVAILABLE = typeof navigator !== 'undefined' && 'gpu' in navigator; const IS_WEBNN_AVAILABLE = typeof navigator !== 'undefined' && 'ml' in navigator; +/** + * Check if the current environment is Safari browser. + * Works in both browser and web worker contexts. + * @returns {boolean} Whether the current environment is Safari. + */ +const isSafari = () => { + // Check if we're in a browser environment + if (typeof navigator === 'undefined') { + return false; + } + + const userAgent = navigator.userAgent; + const vendor = navigator.vendor || ''; + + // Safari has "Apple" in vendor string + const isAppleVendor = vendor.indexOf('Apple') > -1; + + // Exclude Chrome on iOS (CriOS), Firefox on iOS (FxiOS), + // Edge on iOS (EdgiOS), and other browsers + const notOtherBrowser = + !userAgent.match(/CriOS|FxiOS|EdgiOS|OPiOS|mercury|brave/i) && + !userAgent.includes('Chrome') && + !userAgent.includes('Android'); + + return isAppleVendor && notOtherBrowser; +}; +const IS_SAFARI = isSafari(); + const IS_PROCESS_AVAILABLE = typeof process !== 'undefined'; const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node'; const IS_FS_AVAILABLE = !isEmpty(fs); @@ -59,6 +87,9 @@ export const apis = Object.freeze({ /** Whether the WebNN API is available */ IS_WEBNN_AVAILABLE, + /** Whether we are running in a Safari browser */ + IS_SAFARI, + /** Whether the Node.js process API is available */ IS_PROCESS_AVAILABLE, diff --git a/src/utils/devices.js b/src/utils/devices.js index 1086b33e4..edfd960f5 100644 --- a/src/utils/devices.js +++ b/src/utils/devices.js @@ -10,6 +10,7 @@ export const DEVICE_TYPES = Object.freeze({ webgpu: 'webgpu', // WebGPU cuda: 'cuda', // CUDA dml: 'dml', // DirectML + coreml: 'coreml', // CoreML webnn: 'webnn', // WebNN (default) 'webnn-npu': 'webnn-npu', // WebNN NPU From bdaead04a6235fe717af27e8991652e3dfae5bf6 Mon Sep 17 00:00:00 2001 From: Yulong Wang <7679871+fs-eire@users.noreply.github.com> Date: Fri, 25 Apr 2025 15:46:13 -0700 Subject: [PATCH 02/15] customize the wasm paths (#1250) * customize the wasm paths * update implementation From 573e5dc830de55e871d9b5f6b39c1f5a7d1209e9 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Wed, 7 May 2025 18:09:28 -0400 Subject: [PATCH 03/15] [internal] Add is_decoder option to session retrieval for preferred output location --- src/models.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/models.js b/src/models.js index d4e858b55..27fb6bf08 100644 --- a/src/models.js +++ b/src/models.js @@ -154,10 +154,11 @@ const MODEL_CLASS_TO_NAME_MAPPING = new Map(); * @param {string} pretrained_model_name_or_path The path to the directory containing the model file. * @param {string} fileName The name of the model file. * @param {import('./utils/hub.js').PretrainedModelOptions} options Additional options for loading the model. + * @param {boolean} [is_decoder=false] Whether the model is a decoder model. * @returns {Promise<{buffer_or_path: Uint8Array|string, session_options: Object, session_config: Object}>} A Promise that resolves to the data needed to create an InferenceSession object. * @private */ -async function getSession(pretrained_model_name_or_path, fileName, options) { +async function getSession(pretrained_model_name_or_path, fileName, options, is_decoder=false) { let custom_config = options.config?.['transformers.js_config'] ?? {}; let device = options.device ?? custom_config.device; @@ -316,7 +317,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options) { } } - if (selectedDevice === 'webgpu') { + if (is_decoder && selectedDevice === 'webgpu') { const shapes = getKeyValueShapes(options.config, { prefix: 'present', }); @@ -342,13 +343,14 @@ async function getSession(pretrained_model_name_or_path, fileName, options) { * @param {string} pretrained_model_name_or_path The path to the directory containing the model file. * @param {Record} names The names of the model files to load. * @param {import('./utils/hub.js').PretrainedModelOptions} options Additional options for loading the model. + * @param {string} [decoder_name] The name of the decoder model, if any. * @returns {Promise>} A Promise that resolves to a dictionary of InferenceSession objects. * @private */ -async function constructSessions(pretrained_model_name_or_path, names, options) { +async function constructSessions(pretrained_model_name_or_path, names, options, decoder_name=undefined) { return Object.fromEntries(await Promise.all( Object.keys(names).map(async (name) => { - const { buffer_or_path, session_options, session_config } = await getSession(pretrained_model_name_or_path, names[name], options); + const { buffer_or_path, session_options, session_config } = await getSession(pretrained_model_name_or_path, names[name], options, name === decoder_name); const session = await createInferenceSession(buffer_or_path, session_options, session_config); return [name, session]; }) @@ -1148,7 +1150,7 @@ export class PreTrainedModel extends Callable { info = await Promise.all([ constructSessions(pretrained_model_name_or_path, { model: options.model_file_name ?? 'model', - }, options), + }, options, 'model'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1159,7 +1161,7 @@ export class PreTrainedModel extends Callable { constructSessions(pretrained_model_name_or_path, { model: 'encoder_model', decoder_model_merged: 'decoder_model_merged', - }, options), + }, options, 'decoder_model_merged'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1178,7 +1180,7 @@ export class PreTrainedModel extends Callable { constructSessions(pretrained_model_name_or_path, { model: 'encoder_model', decoder_model_merged: 'decoder_model_merged', - }, options), + }, options, 'decoder_model_merged'), ]); } else if (modelType === MODEL_TYPES.ImageTextToText) { @@ -1191,7 +1193,7 @@ export class PreTrainedModel extends Callable { sessions['model'] = 'encoder_model'; } info = await Promise.all([ - constructSessions(pretrained_model_name_or_path, sessions, options), + constructSessions(pretrained_model_name_or_path, sessions, options, 'decoder_model_merged'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1204,7 +1206,7 @@ export class PreTrainedModel extends Callable { decoder_model_merged: 'decoder_model_merged', } info = await Promise.all([ - constructSessions(pretrained_model_name_or_path, sessions, options), + constructSessions(pretrained_model_name_or_path, sessions, options, 'decoder_model_merged'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1216,7 +1218,7 @@ export class PreTrainedModel extends Callable { model: 'text_encoder', decoder_model_merged: 'decoder_model_merged', encodec_decode: 'encodec_decode', - }, options), + }, options, 'decoder_model_merged'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1231,7 +1233,7 @@ export class PreTrainedModel extends Callable { gen_head: 'gen_head', gen_img_embeds: 'gen_img_embeds', image_decode: 'image_decode', - }, options), + }, options, 'model'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), @@ -1243,7 +1245,7 @@ export class PreTrainedModel extends Callable { prepare_inputs_embeds: 'prepare_inputs_embeds', model: 'model', vision_encoder: 'vision_encoder', - }, options), + }, options, 'model'), getOptionalConfigs(pretrained_model_name_or_path, { generation_config: 'generation_config.json', }, options), From 4d3a28d995dae6855301f0147e1ad28be5b693a7 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Thu, 8 May 2025 15:55:44 -0400 Subject: [PATCH 04/15] Update tests --- tests/models/florence2/test_modeling_florence2.js | 6 +++--- tests/models/grounding_dino/test_modeling_grounding_dino.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/models/florence2/test_modeling_florence2.js b/tests/models/florence2/test_modeling_florence2.js index 9d21cb4be..c3b74753a 100644 --- a/tests/models/florence2/test_modeling_florence2.js +++ b/tests/models/florence2/test_modeling_florence2.js @@ -46,7 +46,7 @@ export default () => { { const inputs = await processor(image, texts[0]); const generate_ids = await model.generate({ ...inputs, max_new_tokens: 10 }); - expect(generate_ids.tolist()).toEqual([[2n, 0n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 2n]]); + expect(generate_ids.tolist()).toEqual([[2n, 0n, 0n, 0n, 1n, 0n, 0n, 2n]]); } }, MAX_TEST_EXECUTION_TIME, @@ -68,8 +68,8 @@ export default () => { const generate_ids = await model.generate({ ...inputs, max_new_tokens: 10 }); expect(generate_ids.tolist()).toEqual([ - [2n, 0n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 2n], - [2n, 0n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 48n, 2n], + [2n, 0n, 0n, 0n, 1n, 0n, 0n, 2n], + [2n, 0n, 0n, 0n, 1n, 0n, 0n, 2n], ]); } }, diff --git a/tests/models/grounding_dino/test_modeling_grounding_dino.js b/tests/models/grounding_dino/test_modeling_grounding_dino.js index b1abb8826..177f62aff 100644 --- a/tests/models/grounding_dino/test_modeling_grounding_dino.js +++ b/tests/models/grounding_dino/test_modeling_grounding_dino.js @@ -32,7 +32,7 @@ export default () => { expect(pred_boxes.dims).toEqual([1, num_queries, 4]); expect(logits.max().item()).toBeCloseTo(56.237613677978516, 2); expect(logits.min().item()).toEqual(-Infinity); - expect(pred_boxes.mean().item()).toEqual(0.2500016987323761); + expect(pred_boxes.mean().item()).toBeCloseTo(0.2500016987323761, 4); }, MAX_TEST_EXECUTION_TIME, ); From 80f58ce77afc8f1c9a29a95a8b97c7dcd807484d Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Thu, 8 May 2025 15:55:55 -0400 Subject: [PATCH 05/15] Formatting --- tests/tokenizers.test.js | 79 ++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/tests/tokenizers.test.js b/tests/tokenizers.test.js index d815d2fc7..5f7a4a138 100644 --- a/tests/tokenizers.test.js +++ b/tests/tokenizers.test.js @@ -54,7 +54,6 @@ describe("Tokenizer padding/truncation", () => { }, MAX_TOKENIZER_LOAD_TIME); describe("return_tensor=false (jagged array)", () => { - test("jagged array output when return_tensor is false", () => { const output = tokenizer(inputs, { return_tensor: false, @@ -105,7 +104,6 @@ describe("Tokenizer padding/truncation", () => { compare(output, expected); }); - test("No padding, max_length=3 (implicit truncation strategy)", () => { const output = tokenizer(inputs_2, { padding: false, @@ -129,9 +127,18 @@ describe("Tokenizer padding/truncation", () => { return_tensor: false, }); const expected = { - input_ids: [[1037, 0, 0, 0, 0], [1038, 1039, 1040, 1041, 1042]], - token_type_ids: [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], - attention_mask: [[1, 0, 0, 0, 0], [1, 1, 1, 1, 1]], + input_ids: [ + [1037, 0, 0, 0, 0], + [1038, 1039, 1040, 1041, 1042], + ], + token_type_ids: [ + [0, 0, 0, 0, 0], + [0, 0, 0, 0, 0], + ], + attention_mask: [ + [1, 0, 0, 0, 0], + [1, 1, 1, 1, 1], + ], }; compare(output, expected); }); @@ -161,48 +168,75 @@ describe("Tokenizer padding/truncation", () => { return_tensor: false, }); const expected = { - input_ids: [[1037, 0, 0], [1038, 1039, 1040]], - token_type_ids: [[0, 0, 0], [0, 0, 0]], - attention_mask: [[1, 0, 0], [1, 1, 1]], + input_ids: [ + [1037, 0, 0], + [1038, 1039, 1040], + ], + token_type_ids: [ + [0, 0, 0], + [0, 0, 0], + ], + attention_mask: [ + [1, 0, 0], + [1, 1, 1], + ], }; compare(output, expected); }); test("Padding 'max_length' without truncation, max_length=3", () => { const output = tokenizer(inputs_2, { - padding: 'max_length', + padding: "max_length", truncation: false, max_length: 3, add_special_tokens: false, return_tensor: false, }); const expected = { - input_ids: [[1037, 0, 0], [1038, 1039, 1040, 1041, 1042]], - token_type_ids: [[0, 0, 0], [0, 0, 0, 0, 0]], - attention_mask: [[1, 0, 0], [1, 1, 1, 1, 1]], + input_ids: [ + [1037, 0, 0], + [1038, 1039, 1040, 1041, 1042], + ], + token_type_ids: [ + [0, 0, 0], + [0, 0, 0, 0, 0], + ], + attention_mask: [ + [1, 0, 0], + [1, 1, 1, 1, 1], + ], }; compare(output, expected); }); test("Padding 'max_length' with truncation, max_length=3", () => { const output = tokenizer(inputs_2, { - padding: 'max_length', + padding: "max_length", truncation: true, max_length: 3, add_special_tokens: false, return_tensor: false, }); const expected = { - input_ids: [[1037, 0, 0], [1038, 1039, 1040]], - token_type_ids: [[0, 0, 0], [0, 0, 0]], - attention_mask: [[1, 0, 0], [1, 1, 1]], + input_ids: [ + [1037, 0, 0], + [1038, 1039, 1040], + ], + token_type_ids: [ + [0, 0, 0], + [0, 0, 0], + ], + attention_mask: [ + [1, 0, 0], + [1, 1, 1], + ], }; compare(output, expected); }); test("Padding 'max_length' without truncation and max_length=null", () => { const output = tokenizer(inputs_2, { - padding: 'max_length', + padding: "max_length", truncation: false, max_length: null, add_special_tokens: false, @@ -211,15 +245,15 @@ describe("Tokenizer padding/truncation", () => { const expected = { input_ids: [ [1037, ...Array(511).fill(0)], - [1038, 1039, 1040, 1041, 1042, ...Array(507).fill(0)] + [1038, 1039, 1040, 1041, 1042, ...Array(507).fill(0)], ], token_type_ids: [ [0, ...Array(511).fill(0)], - [0, 0, 0, 0, 0, ...Array(507).fill(0)] + [0, 0, 0, 0, 0, ...Array(507).fill(0)], ], attention_mask: [ [1, ...Array(511).fill(0)], - [1, 1, 1, 1, 1, ...Array(507).fill(0)] + [1, 1, 1, 1, 1, ...Array(507).fill(0)], ], }; compare(output, expected); @@ -227,7 +261,6 @@ describe("Tokenizer padding/truncation", () => { }); describe("return_tensor=true", () => { - test("throws error when tensor output is requested for a jagged array", () => { expect(() => tokenizer(inputs)).toThrow("Unable to create tensor"); }); @@ -329,7 +362,7 @@ describe("Tokenizer padding/truncation", () => { test("padding:'max_length' pads to the specified max_length", () => { const { input_ids, attention_mask, token_type_ids } = tokenizer(inputs, { - padding: 'max_length', + padding: "max_length", truncation: true, add_special_tokens: false, max_length: 3, @@ -347,7 +380,7 @@ describe("Tokenizer padding/truncation", () => { [0n, 0n, 0n], ]); }); - }) + }); }); describe("Token type ids", () => { From 071d728a66a4d280e96e3f7dbffce6f1f136f6b6 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Tue, 13 May 2025 16:00:21 -0400 Subject: [PATCH 06/15] Bump ort versions --- package-lock.json | 26 +++++++++++++------------- package.json | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index c98e001a7..13193812d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.22.0-dev.20250418-c19a49615b", - "onnxruntime-web": "1.22.0-dev.20250418-c19a49615b", + "onnxruntime-node": "1.23.0-dev.20250509-3dc91e6c31", + "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", "sharp": "^0.34.1" }, "devDependencies": { @@ -9105,15 +9105,15 @@ } }, "node_modules/onnxruntime-common": { - "version": "1.22.0-dev.20250409-89f8206ba4", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.22.0-dev.20250409-89f8206ba4.tgz", - "integrity": "sha512-vDJMkfCfb0b1A836rgHj+ORuZf4B4+cc2bASQtpeoJLueuFc5DuYwjIZUBrSvx/fO5IrLjLz+oTrB3pcGlhovQ==", + "version": "1.22.0-dev.20250504-93f85fb7b2", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.22.0-dev.20250504-93f85fb7b2.tgz", + "integrity": "sha512-iPX9WYOvUzS0qsGZ9DPhW+vhG0K8Vh/K/Sh0YRrPVjonq2dcLGChy+ijJ8MRWMwRkFzn8hL95QGiSqZ9+WQ1Xg==", "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.22.0-dev.20250418-c19a49615b", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.22.0-dev.20250418-c19a49615b.tgz", - "integrity": "sha512-++oEW2PNFFGuaLsJJIgq+RMs+DN5An0OB4gxEap4ohDUGgnczqNdNCt1VQEtL8XCK1tnNu0ntyOu69L0e2MJTA==", + "version": "1.23.0-dev.20250509-3dc91e6c31", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250509-3dc91e6c31.tgz", + "integrity": "sha512-Fb79xA9CbipaE8UM1YiXrvKiyDifR7OBqSw2sYQckwwwCevEMCRXCUJBGleuY4pUqqx9MDn8x1t4ft+jIAiEtQ==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9124,19 +9124,19 @@ "dependencies": { "adm-zip": "^0.5.16", "global-agent": "^3.0.0", - "onnxruntime-common": "1.22.0-dev.20250409-89f8206ba4" + "onnxruntime-common": "1.22.0-dev.20250504-93f85fb7b2" } }, "node_modules/onnxruntime-web": { - "version": "1.22.0-dev.20250418-c19a49615b", - "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.22.0-dev.20250418-c19a49615b.tgz", - "integrity": "sha512-N4TlDmpqa8aW7nyJ2mhjQ448HStWQjXPaCS3nmZb3ImkkEgLizj8wWqibO7mMne58w7wXnek0nVp7Z9hFl8iCQ==", + "version": "1.23.0-dev.20250509-3dc91e6c31", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250509-3dc91e6c31.tgz", + "integrity": "sha512-WTVXfDXqb0Jd93eMqiXO08o2Gg/QcOJx/SmrECmU7un7Qdk5B4Swi8jJ5UHxWuNW60f0c7amhyZerRsDEHM1PA==", "license": "MIT", "dependencies": { "flatbuffers": "^25.1.24", "guid-typescript": "^1.0.9", "long": "^5.2.3", - "onnxruntime-common": "1.22.0-dev.20250409-89f8206ba4", + "onnxruntime-common": "1.22.0-dev.20250504-93f85fb7b2", "platform": "^1.3.6", "protobufjs": "^7.2.4" } diff --git a/package.json b/package.json index 8b010e8ac..7a9cc3cd5 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.22.0-dev.20250418-c19a49615b", - "onnxruntime-web": "1.22.0-dev.20250418-c19a49615b", + "onnxruntime-node": "1.23.0-dev.20250509-3dc91e6c31", + "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", "sharp": "^0.34.1" }, "devDependencies": { From cfb8ff3c1fa0ddf94c09f81c7763ca076ca20345 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Mon, 19 May 2025 19:56:27 -0700 Subject: [PATCH 07/15] Bump onnxruntime-node version --- package-lock.json | 16 +++++++++++----- package.json | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 13193812d..58b243d89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250509-3dc91e6c31", + "onnxruntime-node": "1.23.0-dev.20250515-00bd398d54", "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", "sharp": "^0.34.1" }, @@ -9111,9 +9111,9 @@ "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.23.0-dev.20250509-3dc91e6c31", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250509-3dc91e6c31.tgz", - "integrity": "sha512-Fb79xA9CbipaE8UM1YiXrvKiyDifR7OBqSw2sYQckwwwCevEMCRXCUJBGleuY4pUqqx9MDn8x1t4ft+jIAiEtQ==", + "version": "1.23.0-dev.20250515-00bd398d54", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250515-00bd398d54.tgz", + "integrity": "sha512-kKt8DXSedu8hw0dkMKcprsZt/EljgD31Kja+9oLZXRgVHuSm0INqjybXTAy1t1NwJ3nEq+OnlPTwzUhW9FX1Gw==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9124,9 +9124,15 @@ "dependencies": { "adm-zip": "^0.5.16", "global-agent": "^3.0.0", - "onnxruntime-common": "1.22.0-dev.20250504-93f85fb7b2" + "onnxruntime-common": "1.23.0-dev.20250515-00bd398d54" } }, + "node_modules/onnxruntime-node/node_modules/onnxruntime-common": { + "version": "1.23.0-dev.20250515-00bd398d54", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.23.0-dev.20250515-00bd398d54.tgz", + "integrity": "sha512-cxGTqeD7TG6kjbojVKhVrK5wO9WwvlBpITuuWmSym8EjjsrR2t2XdywLtAEQhin39JPfJJFatSvRCVRUUCjAqA==", + "license": "MIT" + }, "node_modules/onnxruntime-web": { "version": "1.23.0-dev.20250509-3dc91e6c31", "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250509-3dc91e6c31.tgz", diff --git a/package.json b/package.json index 7a9cc3cd5..544fe7c4f 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "typegen": "tsc --build", "dev": "webpack serve --no-client-overlay", "build": "webpack && npm run typegen", - "test": "node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose", + "test": "node --experimental-vm-modules --expose-gc node_modules/jest/bin/jest.js --verbose --logHeapUsage", "readme": "python ./docs/scripts/build_readme.py", "docs-api": "node ./docs/scripts/generate.js", "docs-preview": "doc-builder preview transformers.js ./docs/source/ --not_python_module", @@ -56,7 +56,7 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250509-3dc91e6c31", + "onnxruntime-node": "1.23.0-dev.20250515-00bd398d54", "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", "sharp": "^0.34.1" }, From 7ea7718de881891b9f6eedb5f6bd48fabf6a9865 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Mon, 26 May 2025 15:38:02 -0400 Subject: [PATCH 08/15] Bump versions --- package-lock.json | 171 +++++++++++++++++++++++++--------------------- package.json | 6 +- 2 files changed, 96 insertions(+), 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index 58b243d89..024e09d63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,9 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250515-00bd398d54", - "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", - "sharp": "^0.34.1" + "onnxruntime-node": "1.23.0-dev.20250522-ad7b0e368d", + "onnxruntime-web": "1.23.0-dev.20250522-ad7b0e368d", + "sharp": "^0.34.2" }, "devDependencies": { "@types/jest": "^29.5.14", @@ -610,9 +610,9 @@ } }, "node_modules/@emnapi/runtime": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.4.0.tgz", - "integrity": "sha512-64WYIf4UYcdLnbKn/umDlNjQDSS8AgZrI/R9+x5ilkUVFxXcA1Ebl+gQLc/6mERA4407Xof0R7wEyEuj091CVw==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.4.3.tgz", + "integrity": "sha512-pBPWdu6MLKROBX05wSNKcNb++m5Er+KQ9QkB+WVM+pW2Kx9hoSrVTnu3BdkI5eBLZoKu/J6mW/B6i6bJB2ytXQ==", "license": "MIT", "optional": true, "dependencies": { @@ -629,9 +629,9 @@ } }, "node_modules/@img/sharp-darwin-arm64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.1.tgz", - "integrity": "sha512-pn44xgBtgpEbZsu+lWf2KNb6OAf70X68k+yk69Ic2Xz11zHR/w24/U49XT7AeRwJ0Px+mhALhU5LPci1Aymk7A==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.2.tgz", + "integrity": "sha512-OfXHZPppddivUJnqyKoi5YVeHRkkNE2zUFT2gbpKxp/JZCFYEYubnMg+gOp6lWfasPrTS+KPosKqdI+ELYVDtg==", "cpu": [ "arm64" ], @@ -651,9 +651,9 @@ } }, "node_modules/@img/sharp-darwin-x64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.1.tgz", - "integrity": "sha512-VfuYgG2r8BpYiOUN+BfYeFo69nP/MIwAtSJ7/Zpxc5QF3KS22z8Pvg3FkrSFJBPNQ7mmcUcYQFBmEQp7eu1F8Q==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.2.tgz", + "integrity": "sha512-dYvWqmjU9VxqXmjEtjmvHnGqF8GrVjM2Epj9rJ6BUIXvk8slvNDJbhGFvIoXzkDhrJC2jUxNLz/GUjjvSzfw+g==", "cpu": [ "x64" ], @@ -817,9 +817,9 @@ } }, "node_modules/@img/sharp-linux-arm": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.1.tgz", - "integrity": "sha512-anKiszvACti2sGy9CirTlNyk7BjjZPiML1jt2ZkTdcvpLU1YH6CXwRAZCA2UmRXnhiIftXQ7+Oh62Ji25W72jA==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.2.tgz", + "integrity": "sha512-0DZzkvuEOqQUP9mo2kjjKNok5AmnOr1jB2XYjkaoNRwpAYMDzRmAqUIa1nRi58S2WswqSfPOWLNOr0FDT3H5RQ==", "cpu": [ "arm" ], @@ -839,9 +839,9 @@ } }, "node_modules/@img/sharp-linux-arm64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.1.tgz", - "integrity": "sha512-kX2c+vbvaXC6vly1RDf/IWNXxrlxLNpBVWkdpRq5Ka7OOKj6nr66etKy2IENf6FtOgklkg9ZdGpEu9kwdlcwOQ==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.2.tgz", + "integrity": "sha512-D8n8wgWmPDakc83LORcfJepdOSN6MvWNzzz2ux0MnIbOqdieRZwVYY32zxVx+IFUT8er5KPcyU3XXsn+GzG/0Q==", "cpu": [ "arm64" ], @@ -861,9 +861,9 @@ } }, "node_modules/@img/sharp-linux-s390x": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.34.1.tgz", - "integrity": "sha512-7s0KX2tI9mZI2buRipKIw2X1ufdTeaRgwmRabt5bi9chYfhur+/C1OXg3TKg/eag1W+6CCWLVmSauV1owmRPxA==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.34.2.tgz", + "integrity": "sha512-EGZ1xwhBI7dNISwxjChqBGELCWMGDvmxZXKjQRuqMrakhO8QoMgqCrdjnAqJq/CScxfRn+Bb7suXBElKQpPDiw==", "cpu": [ "s390x" ], @@ -883,9 +883,9 @@ } }, "node_modules/@img/sharp-linux-x64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.1.tgz", - "integrity": "sha512-wExv7SH9nmoBW3Wr2gvQopX1k8q2g5V5Iag8Zk6AVENsjwd+3adjwxtp3Dcu2QhOXr8W9NusBU6XcQUohBZ5MA==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.2.tgz", + "integrity": "sha512-sD7J+h5nFLMMmOXYH4DD9UtSNBD05tWSSdWAcEyzqW8Cn5UxXvsHAxmxSesYUsTOBmUnjtxghKDl15EvfqLFbQ==", "cpu": [ "x64" ], @@ -905,9 +905,9 @@ } }, "node_modules/@img/sharp-linuxmusl-arm64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.1.tgz", - "integrity": "sha512-DfvyxzHxw4WGdPiTF0SOHnm11Xv4aQexvqhRDAoD00MzHekAj9a/jADXeXYCDFH/DzYruwHbXU7uz+H+nWmSOQ==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.2.tgz", + "integrity": "sha512-NEE2vQ6wcxYav1/A22OOxoSOGiKnNmDzCYFOZ949xFmrWZOVII1Bp3NqVVpvj+3UeHMFyN5eP/V5hzViQ5CZNA==", "cpu": [ "arm64" ], @@ -927,9 +927,9 @@ } }, "node_modules/@img/sharp-linuxmusl-x64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.1.tgz", - "integrity": "sha512-pax/kTR407vNb9qaSIiWVnQplPcGU8LRIJpDT5o8PdAx5aAA7AS3X9PS8Isw1/WfqgQorPotjrZL3Pqh6C5EBg==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.2.tgz", + "integrity": "sha512-DOYMrDm5E6/8bm/yQLCWyuDJwUnlevR8xtF8bs+gjZ7cyUNYXiSf/E8Kp0Ss5xasIaXSHzb888V1BE4i1hFhAA==", "cpu": [ "x64" ], @@ -949,17 +949,36 @@ } }, "node_modules/@img/sharp-wasm32": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.34.1.tgz", - "integrity": "sha512-YDybQnYrLQfEpzGOQe7OKcyLUCML4YOXl428gOOzBgN6Gw0rv8dpsJ7PqTHxBnXnwXr8S1mYFSLSa727tpz0xg==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.34.2.tgz", + "integrity": "sha512-/VI4mdlJ9zkaq53MbIG6rZY+QRN3MLbR6usYlgITEzi4Rpx5S6LFKsycOQjkOGmqTNmkIdLjEvooFKwww6OpdQ==", "cpu": [ "wasm32" ], "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT", "optional": true, "dependencies": { - "@emnapi/runtime": "^1.4.0" + "@emnapi/runtime": "^1.4.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-arm64": { + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.2.tgz", + "integrity": "sha512-cfP/r9FdS63VA5k0xiqaNaEoGxBg9k7uE+RQGzuK9fHt7jib4zAVVseR9LsE4gJcNWgT6APKMNnCcnyOtmSEUQ==", + "cpu": [ + "arm64" + ], + "license": "Apache-2.0 AND LGPL-3.0-or-later", + "optional": true, + "os": [ + "win32" + ], "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" }, @@ -968,9 +987,9 @@ } }, "node_modules/@img/sharp-win32-ia32": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.34.1.tgz", - "integrity": "sha512-WKf/NAZITnonBf3U1LfdjoMgNO5JYRSlhovhRhMxXVdvWYveM4kM3L8m35onYIdh75cOMCo1BexgVQcCDzyoWw==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.34.2.tgz", + "integrity": "sha512-QLjGGvAbj0X/FXl8n1WbtQ6iVBpWU7JO94u/P2M4a8CFYsvQi4GW2mRy/JqkRx0qpBzaOdKJKw8uc930EX2AHw==", "cpu": [ "ia32" ], @@ -987,9 +1006,9 @@ } }, "node_modules/@img/sharp-win32-x64": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.1.tgz", - "integrity": "sha512-hw1iIAHpNE8q3uMIRCgGOeDoz9KtFNarFLQclLxr/LK1VBkj8nby18RjFvr6aP7USRYAjTZW6yisnBWMX571Tw==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.2.tgz", + "integrity": "sha512-aUdT6zEYtDKCaxkofmmJDJYGCf0+pJg3eU9/oBuqvEeoB9dKI6ZLc/1iLJCTuJQDO4ptntAlkUmHgGjyuobZbw==", "cpu": [ "x64" ], @@ -4446,9 +4465,10 @@ } }, "node_modules/detect-libc": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", - "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.4.tgz", + "integrity": "sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==", + "license": "Apache-2.0", "engines": { "node": ">=8" } @@ -9105,15 +9125,15 @@ } }, "node_modules/onnxruntime-common": { - "version": "1.22.0-dev.20250504-93f85fb7b2", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.22.0-dev.20250504-93f85fb7b2.tgz", - "integrity": "sha512-iPX9WYOvUzS0qsGZ9DPhW+vhG0K8Vh/K/Sh0YRrPVjonq2dcLGChy+ijJ8MRWMwRkFzn8hL95QGiSqZ9+WQ1Xg==", + "version": "1.23.0-dev.20250515-00bd398d54", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.23.0-dev.20250515-00bd398d54.tgz", + "integrity": "sha512-cxGTqeD7TG6kjbojVKhVrK5wO9WwvlBpITuuWmSym8EjjsrR2t2XdywLtAEQhin39JPfJJFatSvRCVRUUCjAqA==", "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.23.0-dev.20250515-00bd398d54", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250515-00bd398d54.tgz", - "integrity": "sha512-kKt8DXSedu8hw0dkMKcprsZt/EljgD31Kja+9oLZXRgVHuSm0INqjybXTAy1t1NwJ3nEq+OnlPTwzUhW9FX1Gw==", + "version": "1.23.0-dev.20250522-ad7b0e368d", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250522-ad7b0e368d.tgz", + "integrity": "sha512-LEI0Nw558a9sKw7zWVCp9LsoRVmVbHEOZLYQvS5t5EZq2ZAEMpNoaU0QZdI+AXxBtzZLcJQx7XeZztcvuIRRgw==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9127,22 +9147,16 @@ "onnxruntime-common": "1.23.0-dev.20250515-00bd398d54" } }, - "node_modules/onnxruntime-node/node_modules/onnxruntime-common": { - "version": "1.23.0-dev.20250515-00bd398d54", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.23.0-dev.20250515-00bd398d54.tgz", - "integrity": "sha512-cxGTqeD7TG6kjbojVKhVrK5wO9WwvlBpITuuWmSym8EjjsrR2t2XdywLtAEQhin39JPfJJFatSvRCVRUUCjAqA==", - "license": "MIT" - }, "node_modules/onnxruntime-web": { - "version": "1.23.0-dev.20250509-3dc91e6c31", - "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250509-3dc91e6c31.tgz", - "integrity": "sha512-WTVXfDXqb0Jd93eMqiXO08o2Gg/QcOJx/SmrECmU7un7Qdk5B4Swi8jJ5UHxWuNW60f0c7amhyZerRsDEHM1PA==", + "version": "1.23.0-dev.20250522-ad7b0e368d", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250522-ad7b0e368d.tgz", + "integrity": "sha512-Wrh8OLznmeCcuwJAqg+yksh++6yF3phkN+Ndd6bh4fCF3gs7z0qYU0GekZzNWvwYxo4Skfjva7pRFV5oh06MOQ==", "license": "MIT", "dependencies": { "flatbuffers": "^25.1.24", "guid-typescript": "^1.0.9", "long": "^5.2.3", - "onnxruntime-common": "1.22.0-dev.20250504-93f85fb7b2", + "onnxruntime-common": "1.23.0-dev.20250515-00bd398d54", "platform": "^1.3.6", "protobufjs": "^7.2.4" } @@ -9848,9 +9862,9 @@ } }, "node_modules/semver": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", - "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -10054,15 +10068,15 @@ } }, "node_modules/sharp": { - "version": "0.34.1", - "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.34.1.tgz", - "integrity": "sha512-1j0w61+eVxu7DawFJtnfYcvSv6qPFvfTaqzTQ2BLknVhHTwGS8sc63ZBF4rzkWMBVKybo4S5OBtDdZahh2A1xg==", + "version": "0.34.2", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.34.2.tgz", + "integrity": "sha512-lszvBmB9QURERtyKT2bNmsgxXK0ShJrL/fvqlonCo7e6xBF8nT8xU6pW+PMIbLsz0RxQk3rgH9kd8UmvOzlMJg==", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "color": "^4.2.3", - "detect-libc": "^2.0.3", - "semver": "^7.7.1" + "detect-libc": "^2.0.4", + "semver": "^7.7.2" }, "engines": { "node": "^18.17.0 || ^20.3.0 || >=21.0.0" @@ -10071,8 +10085,8 @@ "url": "https://opencollective.com/libvips" }, "optionalDependencies": { - "@img/sharp-darwin-arm64": "0.34.1", - "@img/sharp-darwin-x64": "0.34.1", + "@img/sharp-darwin-arm64": "0.34.2", + "@img/sharp-darwin-x64": "0.34.2", "@img/sharp-libvips-darwin-arm64": "1.1.0", "@img/sharp-libvips-darwin-x64": "1.1.0", "@img/sharp-libvips-linux-arm": "1.1.0", @@ -10082,15 +10096,16 @@ "@img/sharp-libvips-linux-x64": "1.1.0", "@img/sharp-libvips-linuxmusl-arm64": "1.1.0", "@img/sharp-libvips-linuxmusl-x64": "1.1.0", - "@img/sharp-linux-arm": "0.34.1", - "@img/sharp-linux-arm64": "0.34.1", - "@img/sharp-linux-s390x": "0.34.1", - "@img/sharp-linux-x64": "0.34.1", - "@img/sharp-linuxmusl-arm64": "0.34.1", - "@img/sharp-linuxmusl-x64": "0.34.1", - "@img/sharp-wasm32": "0.34.1", - "@img/sharp-win32-ia32": "0.34.1", - "@img/sharp-win32-x64": "0.34.1" + "@img/sharp-linux-arm": "0.34.2", + "@img/sharp-linux-arm64": "0.34.2", + "@img/sharp-linux-s390x": "0.34.2", + "@img/sharp-linux-x64": "0.34.2", + "@img/sharp-linuxmusl-arm64": "0.34.2", + "@img/sharp-linuxmusl-x64": "0.34.2", + "@img/sharp-wasm32": "0.34.2", + "@img/sharp-win32-arm64": "0.34.2", + "@img/sharp-win32-ia32": "0.34.2", + "@img/sharp-win32-x64": "0.34.2" } }, "node_modules/shebang-command": { diff --git a/package.json b/package.json index 544fe7c4f..cfd80306b 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,9 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250515-00bd398d54", - "onnxruntime-web": "1.23.0-dev.20250509-3dc91e6c31", - "sharp": "^0.34.1" + "onnxruntime-node": "1.23.0-dev.20250522-ad7b0e368d", + "onnxruntime-web": "1.23.0-dev.20250522-ad7b0e368d", + "sharp": "^0.34.2" }, "devDependencies": { "@types/jest": "^29.5.14", From 297282863273aad366e144ab5399ca562e7323f7 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Tue, 3 Jun 2025 17:50:11 -0400 Subject: [PATCH 09/15] Bump ORT versions --- package-lock.json | 16 ++++++++-------- package.json | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 024e09d63..74d0d54af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250522-ad7b0e368d", - "onnxruntime-web": "1.23.0-dev.20250522-ad7b0e368d", + "onnxruntime-node": "1.23.0-dev.20250602-03b22ffc42", + "onnxruntime-web": "1.23.0-dev.20250602-03b22ffc42", "sharp": "^0.34.2" }, "devDependencies": { @@ -9131,9 +9131,9 @@ "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.23.0-dev.20250522-ad7b0e368d", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250522-ad7b0e368d.tgz", - "integrity": "sha512-LEI0Nw558a9sKw7zWVCp9LsoRVmVbHEOZLYQvS5t5EZq2ZAEMpNoaU0QZdI+AXxBtzZLcJQx7XeZztcvuIRRgw==", + "version": "1.23.0-dev.20250602-03b22ffc42", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250602-03b22ffc42.tgz", + "integrity": "sha512-P1OUP2+LZ3eQaZWHifucVByvmfg9bWwIXmck8DLOv9N2BRM0yqDVdZsmTT3J/eEqkupLriPrtxO/zkNjv6jFFQ==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9148,9 +9148,9 @@ } }, "node_modules/onnxruntime-web": { - "version": "1.23.0-dev.20250522-ad7b0e368d", - "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250522-ad7b0e368d.tgz", - "integrity": "sha512-Wrh8OLznmeCcuwJAqg+yksh++6yF3phkN+Ndd6bh4fCF3gs7z0qYU0GekZzNWvwYxo4Skfjva7pRFV5oh06MOQ==", + "version": "1.23.0-dev.20250602-03b22ffc42", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250602-03b22ffc42.tgz", + "integrity": "sha512-HgD5o7bvff5kaa+DIYrx7hXlPmPtJyU7WPS+CBXbd/JDkAkzwIbobfTc2l7ee37DF09Byw6gyA7cUJMeLIVlPg==", "license": "MIT", "dependencies": { "flatbuffers": "^25.1.24", diff --git a/package.json b/package.json index cfd80306b..47d6332c6 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250522-ad7b0e368d", - "onnxruntime-web": "1.23.0-dev.20250522-ad7b0e368d", + "onnxruntime-node": "1.23.0-dev.20250602-03b22ffc42", + "onnxruntime-web": "1.23.0-dev.20250602-03b22ffc42", "sharp": "^0.34.2" }, "devDependencies": { From ce7dfc08730eaa017d5aeffeb4da611f7ce3bc59 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:13:13 +0200 Subject: [PATCH 10/15] Bump versions --- package-lock.json | 80 +++++++++++++++++++---------------------------- package.json | 4 +-- 2 files changed, 34 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96b67aba7..be3913676 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "Apache-2.0", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250602-03b22ffc42", - "onnxruntime-web": "1.23.0-dev.20250602-03b22ffc42", + "onnxruntime-node": "1.23.0-dev.20250612-70f14d7670", + "onnxruntime-web": "1.23.0-dev.20250612-70f14d7670", "sharp": "^0.34.2" }, "devDependencies": { @@ -2102,9 +2102,9 @@ } }, "node_modules/@jest/reporters/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3748,10 +3748,11 @@ "license": "MIT" }, "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5423,23 +5424,6 @@ "safe-buffer": "~5.1.0" } }, - "node_modules/html-entities": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/html-entities/-/html-entities-2.5.2.tgz", - "integrity": "sha512-K//PSRMQk4FZ78Kyau+mZurHn3FH0Vwr+H36eE0rPbeYkRRi9YxceYPhuN60UwWorxyKHhqoAJl2OFKa4BVtaA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/mdevils" - }, - { - "type": "patreon", - "url": "https://patreon.com/mdevils" - } - ], - "license": "MIT" - }, "node_modules/html-escaper": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", @@ -6539,9 +6523,9 @@ } }, "node_modules/jest-config/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "dev": true, "license": "MIT", "dependencies": { @@ -7723,9 +7707,9 @@ } }, "node_modules/jest-runtime/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", + "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", "dev": true, "license": "MIT", "dependencies": { @@ -9125,15 +9109,15 @@ } }, "node_modules/onnxruntime-common": { - "version": "1.23.0-dev.20250515-00bd398d54", - "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.23.0-dev.20250515-00bd398d54.tgz", - "integrity": "sha512-cxGTqeD7TG6kjbojVKhVrK5wO9WwvlBpITuuWmSym8EjjsrR2t2XdywLtAEQhin39JPfJJFatSvRCVRUUCjAqA==", + "version": "1.23.0-dev.20250612-70f14d7670", + "resolved": "https://registry.npmjs.org/onnxruntime-common/-/onnxruntime-common-1.23.0-dev.20250612-70f14d7670.tgz", + "integrity": "sha512-cp61/t9AVKK9Wm6vdzHSsRBLvKTP/cZxZlnAF2f5Le/QsHGmBFHrq/M4Ma2G2KnakKczYMEc2WeIX4plVvf6Gg==", "license": "MIT" }, "node_modules/onnxruntime-node": { - "version": "1.23.0-dev.20250602-03b22ffc42", - "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250602-03b22ffc42.tgz", - "integrity": "sha512-P1OUP2+LZ3eQaZWHifucVByvmfg9bWwIXmck8DLOv9N2BRM0yqDVdZsmTT3J/eEqkupLriPrtxO/zkNjv6jFFQ==", + "version": "1.23.0-dev.20250612-70f14d7670", + "resolved": "https://registry.npmjs.org/onnxruntime-node/-/onnxruntime-node-1.23.0-dev.20250612-70f14d7670.tgz", + "integrity": "sha512-z2Y1a4bPNBGBr6qAvtzBcmyNV1pslJwAcCnKwCgbhIya6xPmtfwpjfccoB5y0hfR0aG5jQUk+4L8TmfwpgZBsQ==", "hasInstallScript": true, "license": "MIT", "os": [ @@ -9144,19 +9128,19 @@ "dependencies": { "adm-zip": "^0.5.16", "global-agent": "^3.0.0", - "onnxruntime-common": "1.23.0-dev.20250515-00bd398d54" + "onnxruntime-common": "1.23.0-dev.20250612-70f14d7670" } }, "node_modules/onnxruntime-web": { - "version": "1.23.0-dev.20250602-03b22ffc42", - "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250602-03b22ffc42.tgz", - "integrity": "sha512-HgD5o7bvff5kaa+DIYrx7hXlPmPtJyU7WPS+CBXbd/JDkAkzwIbobfTc2l7ee37DF09Byw6gyA7cUJMeLIVlPg==", + "version": "1.23.0-dev.20250612-70f14d7670", + "resolved": "https://registry.npmjs.org/onnxruntime-web/-/onnxruntime-web-1.23.0-dev.20250612-70f14d7670.tgz", + "integrity": "sha512-KUiUvThaujUGb1B7/grHRXJAGpERi3wSd1gmhZKCTfhMe99DzgVNveVqBhaInFeeICynJnxX3Qht85uDhzrSmg==", "license": "MIT", "dependencies": { "flatbuffers": "^25.1.24", "guid-typescript": "^1.0.9", "long": "^5.2.3", - "onnxruntime-common": "1.23.0-dev.20250515-00bd398d54", + "onnxruntime-common": "1.23.0-dev.20250612-70f14d7670", "platform": "^1.3.6", "protobufjs": "^7.2.4" } @@ -11089,15 +11073,16 @@ } }, "node_modules/webpack-dev-server": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/webpack-dev-server/-/webpack-dev-server-5.1.0.tgz", - "integrity": "sha512-aQpaN81X6tXie1FoOB7xlMfCsN19pSvRAeYUHOdFWOlhpQ/LlbfTqYwwmEDFV0h8GGuqmCmKmT+pxcUV/Nt2gQ==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/webpack-dev-server/-/webpack-dev-server-5.2.2.tgz", + "integrity": "sha512-QcQ72gh8a+7JO63TAx/6XZf/CWhgMzu5m0QirvPfGvptOusAxG12w2+aua1Jkjr7hzaWDnJ2n6JFeexMHI+Zjg==", "dev": true, "license": "MIT", "dependencies": { "@types/bonjour": "^3.5.13", "@types/connect-history-api-fallback": "^1.5.4", "@types/express": "^4.17.21", + "@types/express-serve-static-core": "^4.17.21", "@types/serve-index": "^1.9.4", "@types/serve-static": "^1.15.5", "@types/sockjs": "^0.3.36", @@ -11108,10 +11093,9 @@ "colorette": "^2.0.10", "compression": "^1.7.4", "connect-history-api-fallback": "^2.0.0", - "express": "^4.19.2", + "express": "^4.21.2", "graceful-fs": "^4.2.6", - "html-entities": "^2.4.0", - "http-proxy-middleware": "^2.0.3", + "http-proxy-middleware": "^2.0.9", "ipaddr.js": "^2.1.0", "launch-editor": "^2.6.1", "open": "^10.0.3", diff --git a/package.json b/package.json index 90cfd5eaa..6ae8aa8b3 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,8 @@ "homepage": "https://github.com/huggingface/transformers.js#readme", "dependencies": { "@huggingface/jinja": "^0.5.0", - "onnxruntime-node": "1.23.0-dev.20250602-03b22ffc42", - "onnxruntime-web": "1.23.0-dev.20250602-03b22ffc42", + "onnxruntime-node": "1.23.0-dev.20250612-70f14d7670", + "onnxruntime-web": "1.23.0-dev.20250612-70f14d7670", "sharp": "^0.34.2" }, "devDependencies": { From 87cdd0a0879ef8392de6850ae5316a0e3e189943 Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:14:30 +0200 Subject: [PATCH 11/15] Only check webgpu fp16 for non-node environments --- src/models.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models.js b/src/models.js index bd794484f..20df8c112 100644 --- a/src/models.js +++ b/src/models.js @@ -158,7 +158,7 @@ const MODEL_CLASS_TO_NAME_MAPPING = new Map(); * @returns {Promise<{buffer_or_path: Uint8Array|string, session_options: Object, session_config: Object}>} A Promise that resolves to the data needed to create an InferenceSession object. * @private */ -async function getSession(pretrained_model_name_or_path, fileName, options, is_decoder=false) { +async function getSession(pretrained_model_name_or_path, fileName, options, is_decoder = false) { let custom_config = options.config?.['transformers.js_config'] ?? {}; let device = options.device ?? custom_config.device; @@ -219,7 +219,14 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d if (!DEFAULT_DTYPE_SUFFIX_MAPPING.hasOwnProperty(selectedDtype)) { throw new Error(`Invalid dtype: ${selectedDtype}. Should be one of: ${Object.keys(DATA_TYPES).join(', ')}`); - } else if (selectedDtype === DATA_TYPES.fp16 && selectedDevice === 'webgpu' && !(await isWebGpuFp16Supported())) { + } else if ( + selectedDevice === 'webgpu' && ( + // NOTE: Currently, we assume that the Native WebGPU EP always supports fp16. In future, we will add a check for this. + apis.IS_NODE_ENV + || + (selectedDtype === DATA_TYPES.fp16 && !(await isWebGpuFp16Supported())) + ) + ) { throw new Error(`The device (${selectedDevice}) does not support fp16.`); } @@ -347,7 +354,7 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d * @returns {Promise>} A Promise that resolves to a dictionary of InferenceSession objects. * @private */ -async function constructSessions(pretrained_model_name_or_path, names, options, decoder_name=undefined) { +async function constructSessions(pretrained_model_name_or_path, names, options, decoder_name = undefined) { return Object.fromEntries(await Promise.all( Object.keys(names).map(async (name) => { const { buffer_or_path, session_options, session_config } = await getSession(pretrained_model_name_or_path, names[name], options, name === decoder_name); From 51c4bda2c0182a619cac9c37bf9e13ad07d368ec Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:15:56 +0200 Subject: [PATCH 12/15] Fix --- src/models.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models.js b/src/models.js index 20df8c112..465d58e25 100644 --- a/src/models.js +++ b/src/models.js @@ -222,8 +222,8 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d } else if ( selectedDevice === 'webgpu' && ( // NOTE: Currently, we assume that the Native WebGPU EP always supports fp16. In future, we will add a check for this. - apis.IS_NODE_ENV - || + !apis.IS_NODE_ENV + && (selectedDtype === DATA_TYPES.fp16 && !(await isWebGpuFp16Supported())) ) ) { From 0f58976eea57d705bab2a4e854bd79e4517a9cad Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:40:10 +0200 Subject: [PATCH 13/15] Assume node supports webgpu --- src/env.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/env.js b/src/env.js index 35a0e6875..44f2c3f6a 100644 --- a/src/env.js +++ b/src/env.js @@ -28,11 +28,16 @@ import url from 'url'; const VERSION = '3.5.2'; +const IS_PROCESS_AVAILABLE = typeof process !== 'undefined'; +const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node'; +const IS_FS_AVAILABLE = !isEmpty(fs); +const IS_PATH_AVAILABLE = !isEmpty(path); + // Check if various APIs are available (depends on environment) const IS_BROWSER_ENV = typeof window !== "undefined" && typeof window.document !== "undefined"; const IS_WEBWORKER_ENV = typeof self !== "undefined" && self.constructor?.name === 'DedicatedWorkerGlobalScope'; const IS_WEB_CACHE_AVAILABLE = typeof self !== "undefined" && 'caches' in self; -const IS_WEBGPU_AVAILABLE = typeof navigator !== 'undefined' && 'gpu' in navigator; +const IS_WEBGPU_AVAILABLE = IS_NODE_ENV || ( typeof navigator !== 'undefined' && 'gpu' in navigator); const IS_WEBNN_AVAILABLE = typeof navigator !== 'undefined' && 'ml' in navigator; /** @@ -63,11 +68,6 @@ const isSafari = () => { }; const IS_SAFARI = isSafari(); -const IS_PROCESS_AVAILABLE = typeof process !== 'undefined'; -const IS_NODE_ENV = IS_PROCESS_AVAILABLE && process?.release?.name === 'node'; -const IS_FS_AVAILABLE = !isEmpty(fs); -const IS_PATH_AVAILABLE = !isEmpty(path); - /** * A read-only object containing information about the APIs available in the current environment. */ From 00f177b39d3463b024fba77dda1f595809f6bcda Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:40:26 +0200 Subject: [PATCH 14/15] Update ORT node support comment --- src/backends/onnx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/onnx.js b/src/backends/onnx.js index 58b8114bb..3504881af 100644 --- a/src/backends/onnx.js +++ b/src/backends/onnx.js @@ -64,12 +64,12 @@ if (ORT_SYMBOL in globalThis) { } else if (apis.IS_NODE_ENV) { ONNX = ONNX_NODE.default ?? ONNX_NODE; - // Updated as of ONNX Runtime 1.22.0-dev.20250418-c19a49615b + // Updated as of ONNX Runtime 1.23.0-dev.20250612-70f14d7670 // The following table lists the supported versions of ONNX Runtime Node.js binding provided with pre-built binaries. // | EPs/Platforms | Windows x64 | Windows arm64 | Linux x64 | Linux arm64 | MacOS x64 | MacOS arm64 | // | --------------------- | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | ------------------ | // | CPU | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | - // | WebGPU (experimental) | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | + // | WebGPU (experimental) | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ✔️ | // | DirectML | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ | // | CUDA | ❌ | ❌ | ✔️ (CUDA v12) | ❌ | ❌ | ❌ | // | CoreML | ❌ | ❌ | ❌ | ❌ | ✔️ | ✔️ | From 11b59ed975ae81ec9807a5bee24d40f6d045d81a Mon Sep 17 00:00:00 2001 From: Joshua Lochner <26504141+xenova@users.noreply.github.com> Date: Fri, 13 Jun 2025 12:40:46 +0200 Subject: [PATCH 15/15] Relax test strictness --- tests/pipelines/test_pipelines_depth_estimation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pipelines/test_pipelines_depth_estimation.js b/tests/pipelines/test_pipelines_depth_estimation.js index 534e91030..daacbb128 100644 --- a/tests/pipelines/test_pipelines_depth_estimation.js +++ b/tests/pipelines/test_pipelines_depth_estimation.js @@ -26,7 +26,7 @@ export default () => { async () => { const output = await pipe(images[0]); expect(output.predicted_depth.dims).toEqual([224, 224]); - expect(output.predicted_depth.mean().item()).toBeCloseTo(0.000006106501587055391, 6); + expect(output.predicted_depth.mean().item()).toBeCloseTo(0.000006106501587055391, 4); expect(output.depth.size).toEqual(images[0].size); }, MAX_TEST_EXECUTION_TIME, @@ -40,10 +40,10 @@ export default () => { const output = await pipe(images); expect(output).toHaveLength(images.length); expect(output[0].predicted_depth.dims).toEqual([224, 224]); - expect(output[0].predicted_depth.mean().item()).toBeCloseTo(0.000006106501587055391, 6); + expect(output[0].predicted_depth.mean().item()).toBeCloseTo(0.000006106501587055391, 4); expect(output[0].depth.size).toEqual(images[0].size); expect(output[1].predicted_depth.dims).toEqual([224, 224]); - expect(output[1].predicted_depth.mean().item()).toBeCloseTo(0.0000014548650142387487, 6); + expect(output[1].predicted_depth.mean().item()).toBeCloseTo(0.0000014548650142387487, 4); expect(output[1].depth.size).toEqual(images[1].size); }, MAX_TEST_EXECUTION_TIME,