diff --git a/package-lock.json b/package-lock.json index 410ae35a7..cc976bf2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "sharp": "^0.33.5" }, "devDependencies": { + "@runtime-type-inspector/plugin-webpack5": "^4.0.1", "@types/jest": "^29.5.14", "@webgpu/types": "^0.1.44", "catharsis": "github:xenova/catharsis", @@ -2630,6 +2631,40 @@ "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, + "node_modules/@runtime-type-inspector/plugin-webpack5": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@runtime-type-inspector/plugin-webpack5/-/plugin-webpack5-4.0.1.tgz", + "integrity": "sha512-Z+bYfQKq95eiOLlnq2sxxfgOf+xnTgAutPygbWZtu5QHiiJX7orMFMZXqaytoqw5bQWBOVprIfHW5KzmWD0dvw==", + "dev": true, + "dependencies": { + "@runtime-type-inspector/transpiler": "^4.0.1", + "loader-utils": "^2.0.4", + "webpack": "^5.89.0" + } + }, + "node_modules/@runtime-type-inspector/runtime": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@runtime-type-inspector/runtime/-/runtime-4.0.1.tgz", + "integrity": "sha512-wpJtqMAWlnlcONgyK9id8rMYVo1MvOL4ZNdWzHIymF/mYLwoG/BKWyslZPAGRGq8AClqqUyQ9bmnAbppBchzFA==", + "dev": true, + "dependencies": { + "display-anything": "^1.2.0" + } + }, + "node_modules/@runtime-type-inspector/transpiler": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@runtime-type-inspector/transpiler/-/transpiler-4.0.1.tgz", + "integrity": "sha512-OVQZdfna3NBK6MgD/jU5122OWqbM/mlEMKl+TqSdzcP52O8onufa4BPHD7f+fLQhrFYPV3QEtf+eFWBCDOzkZg==", + "dev": true, + "dependencies": { + "@babel/parser": "^7.23.0", + "@runtime-type-inspector/runtime": "^4.0.1", + "typescript": "^5.1.6" + }, + "bin": { + "transpiler": "bin.js" + } + }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -3454,6 +3489,15 @@ "integrity": "sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw==", "dev": true }, + "node_modules/big.js": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", + "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -4263,6 +4307,12 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/display-anything": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/display-anything/-/display-anything-1.2.0.tgz", + "integrity": "sha512-QeMtc1JMjZWH0iswd9f0LBiphQUekYClPr5wve5d+QsdZ+UWOAjsdmrLDO1XxomlCL/vAhPY7PRgu5KVN4WdOQ==", + "dev": true + }, "node_modules/dmd": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/dmd/-/dmd-6.2.0.tgz", @@ -4340,6 +4390,15 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, + "node_modules/emojis-list": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, "node_modules/encodeurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", @@ -8270,6 +8329,20 @@ "node": ">=6.11.5" } }, + "node_modules/loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "dependencies": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + }, + "engines": { + "node": ">=8.9.0" + } + }, "node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", diff --git a/package.json b/package.json index 94e59b866..8d0b8612b 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "sharp": "^0.33.5" }, "devDependencies": { + "@runtime-type-inspector/plugin-webpack5": "^4.0.1", "@types/jest": "^29.5.14", "@webgpu/types": "^0.1.44", "catharsis": "github:xenova/catharsis", diff --git a/src/models.js b/src/models.js index 031b85f01..ecb1e5c44 100644 --- a/src/models.js +++ b/src/models.js @@ -1648,7 +1648,7 @@ export class PreTrainedModel extends Callable { * Adds past key values to the decoder feeds object. If pastKeyValues is null, creates new tensors for past key values. * * @param {Object} decoderFeeds The decoder feeds object to add past key values to. - * @param {Object} pastKeyValues An object containing past key values. + * @param {Object} [pastKeyValues] An object containing past key values. */ addPastKeyValues(decoderFeeds, pastKeyValues) { if (pastKeyValues) { diff --git a/src/pipelines.js b/src/pipelines.js index 3b7373cf9..5027ab996 100644 --- a/src/pipelines.js +++ b/src/pipelines.js @@ -3172,7 +3172,7 @@ const TASK_ALIASES = Object.freeze({ * @typedef {keyof typeof TASK_ALIASES} AliasType * @typedef {TaskType | AliasType} PipelineType All possible pipeline types. * @typedef {{[K in TaskType]: InstanceType}} SupportedTasks A mapping of pipeline names to their corresponding pipeline classes. - * @typedef {{[K in AliasType]: InstanceType}} AliasTasks A mapping from pipeline aliases to their corresponding pipeline classes. + * @typedef {{[K in AliasType]: SupportedTasks[TASK_ALIASES[K]]}} AliasTasks A mapping from pipeline aliases to their corresponding pipeline classes. * @typedef {SupportedTasks & AliasTasks} AllTasks A mapping from all pipeline names and aliases to their corresponding pipeline classes. */ diff --git a/src/processors.js b/src/processors.js index 9af0791be..b4edc1312 100644 --- a/src/processors.js +++ b/src/processors.js @@ -602,13 +602,13 @@ export class ImageFeatureExtractor extends FeatureExtractor { * Constructs a new ImageFeatureExtractor instance. * * @param {Object} config The configuration for the feature extractor. - * @param {number[]} config.image_mean The mean values for image normalization. - * @param {number[]} config.image_std The standard deviation values for image normalization. - * @param {boolean} config.do_rescale Whether to rescale the image pixel values to the [0,1] range. - * @param {number} config.rescale_factor The factor to use for rescaling the image pixel values. - * @param {boolean} config.do_normalize Whether to normalize the image pixel values. + * @param {number[]} [config.image_mean] The mean values for image normalization. + * @param {number[]} [config.image_std] The standard deviation values for image normalization. + * @param {boolean} [config.do_rescale] Whether to rescale the image pixel values to the [0,1] range. + * @param {number} [config.rescale_factor] The factor to use for rescaling the image pixel values. + * @param {boolean} [config.do_normalize] Whether to normalize the image pixel values. * @param {boolean} config.do_resize Whether to resize the image. - * @param {number} config.resample What method to use for resampling. + * @param {number} [config.resample] What method to use for resampling. * @param {number|Object} config.size The size to resize the image to. * @param {boolean} [config.do_flip_channel_order=false] Whether to flip the color channels from RGB to BGR. * Can be overridden by the `do_flip_channel_order` parameter in the `preprocess` method. @@ -932,7 +932,11 @@ export class ImageFeatureExtractor extends FeatureExtractor { * Preprocesses the given image. * * @param {RawImage} image The image to preprocess. - * @param {Object} overrides The overrides for the preprocessing options. + * @param {Object} [overrides] The overrides for the preprocessing options. + * @param {boolean|null} [overrides.do_normalize] Do normalize? + * @param {boolean|null} [overrides.do_pad] Do pad? + * @param {boolean|null} [overrides.do_convert_rgb] Do convert RGB? + * @param {boolean|null} [overrides.do_convert_grayscale] Do convert grayscale? * @returns {Promise} The preprocessed image. */ async preprocess(image, { diff --git a/src/transformers.rti.js b/src/transformers.rti.js new file mode 100644 index 000000000..0ef2a500e --- /dev/null +++ b/src/transformers.rti.js @@ -0,0 +1,11 @@ +import { customTypes } from '@runtime-type-inspector/runtime'; +// import { ONNX } from './backends/onnx.js'; +//import 'display-anything/src/style.js'; +/** + * @param {*} value + * @returns {boolean} + */ +// customTypes.ONNXTensor = value => { +// return value instanceof ONNX.Tensor; +// } +export * from './transformers.js'; diff --git a/src/utils/core.js b/src/utils/core.js index 6a6137dff..dc63e55e7 100644 --- a/src/utils/core.js +++ b/src/utils/core.js @@ -11,8 +11,8 @@ /** * Helper function to dispatch progress callbacks. * - * @param {Function} progress_callback The progress callback function to dispatch. - * @param {any} data The data to pass to the progress callback function. + * @param {Function} [progress_callback] The progress callback function to dispatch. + * @param {any} [data] The data to pass to the progress callback function. * @returns {void} * @private */ diff --git a/webpack.config.js b/webpack.config.js index 218249249..8962168a3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,6 +1,7 @@ import TerserPlugin from "terser-webpack-plugin"; import { fileURLToPath } from "url"; import path from "path"; +import { RuntimeTypeInspectorPlugin } from '@runtime-type-inspector/plugin-webpack5'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -28,15 +29,25 @@ function buildConfig({ return [module, false]; }), ); - + const plugins = []; + let devtool = 'source-map'; + let entry = { + [`transformers${name}`]: './src/transformers.js', + [`transformers${name}.min`]: './src/transformers.js', + }; + const buildType = 'rti'; + if (buildType === 'rti') { + entry = { + [`transformers${name}.rti`]: './src/transformers.rti.js', + }; + plugins.push(new RuntimeTypeInspectorPlugin()); + devtool = false; + } /** @type {import('webpack').Configuration} */ const config = { mode: 'development', - devtool: 'source-map', - entry: { - [`transformers${name}`]: './src/transformers.js', - [`transformers${name}.min`]: './src/transformers.js', - }, + devtool, + entry, output: { filename: `[name]${suffix}`, path: path.join(__dirname, 'dist'), @@ -46,6 +57,7 @@ function buildConfig({ assetModuleFilename: '[name][ext]', chunkFormat: 'module', }, + plugins, optimization: { minimize: true, minimizer: [new TerserPlugin({