Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Webpack: add/build RTI target #409

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
40b4c62
commit all
kungfooman Nov 22, 2023
ca19c34
Webpack: add/build RTI target
kungfooman Nov 22, 2023
1208398
devtool=false for RTI build
kungfooman Nov 25, 2023
db5e07d
npm i @runtime-type-inspector/plugin-webpack5@1.1.4
kungfooman Nov 25, 2023
d8f9f4d
Use custom type validation for ONNXTensor
kungfooman Nov 25, 2023
01b60c7
jsdoc fixes + jsconfig strict
kungfooman Dec 14, 2023
7f570ba
Merge branch 'main' into webpack-rti
kungfooman Dec 14, 2023
9d2632f
npm i @runtime-type-inspector/plugin-webpack5@1.2.1 --save-dev
kungfooman Dec 14, 2023
ab2fec4
A bit of JSDoc
kungfooman Dec 14, 2023
97dd7af
Update to @runtime-type-inspector/plugin-webpack5@3.0.0
kungfooman Jan 5, 2024
ef491fb
Merge main
kungfooman Jan 5, 2024
41cc69f
npm update @runtime-type-inspector/plugin-webpack5
kungfooman Jan 5, 2024
3eba48d
package.json rewrite
kungfooman Jan 6, 2024
0d5c14a
Simplify AliasTasks
kungfooman Jan 8, 2024
7675841
update RTI runtime
kungfooman Jan 8, 2024
772c815
Fix tokenizer arguments
kungfooman Jan 8, 2024
2c124d6
npm update RTI
kungfooman Jan 13, 2024
05ee202
Merge branch 'main' into webpack-rti
kungfooman Jan 13, 2024
8a304fb
Merge branch 'main' into webpack-rti
kungfooman Jan 25, 2024
62f6a7e
Merge branch 'main' into webpack-rti
kungfooman Jan 25, 2024
55e150d
Update to @runtime-type-inspector/plugin-webpack5@3.2.0
kungfooman Jan 25, 2024
12a2373
Merge branch 'main' into webpack-rti
kungfooman May 19, 2024
b849e4a
npm i @runtime-type-inspector/plugin-webpack5@3.2.6
kungfooman May 19, 2024
9069406
Bump RTI to 3.3.7
kungfooman Jun 21, 2024
0655a4b
src/processors.js: Fix some types for ImageFeatureExtractor
kungfooman Jun 21, 2024
395b0ef
Merge branch 'main' into webpack-rti
kungfooman Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"compilerOptions": {
// Tells the compiler to check JS files
"checkJs": true,
"strict": true,
"noImplicitAny": true,
"target": "esnext",
"module": "esnext",
"moduleResolution": "nodenext",
Expand Down
103 changes: 88 additions & 15 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"onnxruntime-node": "1.14.0"
},
"devDependencies": {
"@runtime-type-inspector/plugin-webpack5": "^3.3.7",
"@types/jest": "^29.5.1",
"catharsis": "github:xenova/catharsis",
"copy-webpack-plugin": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,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) {
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,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<typeof SUPPORTED_TASKS[K]["pipeline"]>}} SupportedTasks A mapping of pipeline names to their corresponding pipeline classes.
* @typedef {{[K in AliasType]: InstanceType<typeof SUPPORTED_TASKS[TASK_ALIASES[K]]["pipeline"]>}} 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.
*/

Expand Down
18 changes: 11 additions & 7 deletions src/processors.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,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.
Expand Down Expand Up @@ -567,7 +567,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<PreprocessedImage>} The preprocessed image.
*/
async preprocess(image, {
Expand Down
11 changes: 11 additions & 0 deletions src/transformers.rti.js
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions src/utils/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
86 changes: 54 additions & 32 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@ import CopyWebpackPlugin from 'copy-webpack-plugin';
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));

/**
* @type {import('webpack').Configuration}
* Build a target that webpack is supposed to build.
*
* @param {'release'|'rti'} buildType - The build type.
* @returns {import('webpack').Configuration} One webpack target.
*/
export default {
mode: 'development',
devtool: 'source-map',
entry: {
function buildTarget(buildType) {
let entry = {
// include dist in entry point so that when running dev server,
// we can access the files with /dist/...
'dist/transformers': './src/transformers.js',
'dist/transformers.min': './src/transformers.js',
},
output: {
filename: '[name].js',
path: __dirname,
library: {
type: 'module',
},
},
plugins: [
};
let plugins = [
// Copy .wasm files to dist folder
new CopyWebpackPlugin({
patterns: [
Expand All @@ -33,22 +28,49 @@ export default {
to: 'dist/[name][ext]'
},
],
}),
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
test: /\.min\.js$/,
extractComments: false,
})],
},
devServer: {
static: {
directory: __dirname
})
];
let devtool = 'source-map';
if (buildType === 'rti') {
entry = {
'dist/transformers.rti': './src/transformers.rti.js',
};
plugins = [
new RuntimeTypeInspectorPlugin()
];
devtool = false;
}
return {
mode: 'development',
devtool,
entry,
output: {
filename: '[name].js',
path: __dirname,
library: {
type: 'module',
},
},
plugins,
optimization: {
minimize: buildType === 'release',
minimizer: [new TerserPlugin({
test: /\.min\.js$/,
extractComments: false,
})],
},
devServer: {
static: {
directory: __dirname
},
port: 8080
},
experiments: {
outputModule: true,
},
port: 8080
},
experiments: {
outputModule: true,
},
};
};
}
export default [
buildTarget('release'),
buildTarget('rti'),
];