Skip to content

Commit d24fc6c

Browse files
authored
model.json support in custom bundle tool & converter
Adds support for parsing model.json(s) for ops to be included in the custom bundle. Allows for modifying ops available to tfjs-converter's op executors at build time of an end user program along with a custom build. DEV
1 parent b54dfa9 commit d24fc6c

File tree

130 files changed

+4919
-2243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+4919
-2243
lines changed

e2e/karma.conf.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@
1717

1818
const karmaTypescriptConfig = {
1919
tsconfig: 'tsconfig.json',
20-
coverageOptions: {instrumentation: false}
20+
coverageOptions: {instrumentation: false},
21+
bundlerOptions: {
22+
acornOptions: {ecmaVersion: 8},
23+
transforms: [
24+
require('karma-typescript-es6-transform')({
25+
presets: [
26+
// ensure we get es5 by adding IE 11 as a target
27+
['@babel/env', {targets: {browsers: ['defaults', 'IE 11']}}]
28+
]
29+
}),
30+
]
31+
}
2132
};
2233

2334
const devConfig = {
2435
frameworks: ['jasmine', 'karma-typescript'],
2536
files: [
37+
{pattern: './node_modules/@babel/polyfill/dist/polyfill.js'},
2638
'integration_tests/setup_test.ts',
2739
{pattern: 'integration_tests/**/*.ts'},
2840
{

e2e/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
"url": "https://github.com/tensorflow/tfjs"
99
},
1010
"devDependencies": {
11-
"@tensorflow/tfjs-core": "link:../tfjs-core",
12-
"@tensorflow/tfjs-converter": "link:../tfjs-converter",
13-
"@tensorflow/tfjs-layers": "link:../tfjs-layers",
11+
"@babel/polyfill": "^7.10.4",
12+
"@tensorflow/tfjs": "link:../tfjs",
1413
"@tensorflow/tfjs-backend-cpu": "link:../tfjs-backend-cpu",
1514
"@tensorflow/tfjs-backend-webgl": "link:../tfjs-backend-webgl",
15+
"@tensorflow/tfjs-converter": "link:../tfjs-converter",
16+
"@tensorflow/tfjs-core": "link:../tfjs-core",
1617
"@tensorflow/tfjs-data": "link:../tfjs-data",
17-
"@tensorflow/tfjs": "link:../tfjs",
18+
"@tensorflow/tfjs-layers": "link:../tfjs-layers",
1819
"@tensorflow/tfjs-node": "link:../tfjs-node",
1920
"@types/detect-browser": "^4.0.0",
2021
"@types/jasmine": "~3.0.0",
@@ -28,6 +29,7 @@
2829
"karma-chrome-launcher": "~2.2.0",
2930
"karma-jasmine": "~1.1.0",
3031
"karma-typescript": "~4.1.1",
32+
"karma-typescript-es6-transform": "^5.1.0",
3133
"mathjs": "^5.7.0",
3234
"request": "^2.88.0",
3335
"ts-node": "~8.8.2",

e2e/yarn.lock

Lines changed: 1116 additions & 12 deletions
Large diffs are not rendered by default.

tfjs-backend-wasm/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,11 @@
7474
"typescript": "3.5.3",
7575
"yalc": "~1.0.0-pre.21"
7676
},
77-
"license": "Apache-2.0"
77+
"license": "Apache-2.0",
78+
"sideEffects": [
79+
"./dist/register_all_kernels.js",
80+
"./dist/flags_wasm.js",
81+
"./dist/base.js",
82+
"./dist/index.js"
83+
]
7884
}

tfjs-backend-wasm/src/kernels/DepthwiseConv2dNative.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function depthwiseConv2d(args: {
102102
return out;
103103
}
104104

105-
export const depthwiseConv2DNativeConfig: KernelConfig = {
105+
export const depthwiseConv2dNativeConfig: KernelConfig = {
106106
kernelName: DepthwiseConv2dNative,
107107
backendName: 'wasm',
108108
setupFunc: setup,

tfjs-backend-wasm/src/register_all_kernels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {conv2DBackpropInputConfig} from './kernels/Conv2DBackpropInput';
3434
import {cosConfig} from './kernels/Cos';
3535
import {cropAndResizeConfig} from './kernels/CropAndResize';
3636
import {cumsumConfig} from './kernels/Cumsum';
37-
import {depthwiseConv2DNativeConfig} from './kernels/DepthwiseConv2dNative';
37+
import {depthwiseConv2dNativeConfig} from './kernels/DepthwiseConv2dNative';
3838
import {divConfig} from './kernels/Div';
3939
import {equalConfig} from './kernels/Equal';
4040
import {expConfig} from './kernels/Exp';
@@ -110,7 +110,7 @@ const kernelConfigs: KernelConfig[] = [
110110
cosConfig,
111111
cropAndResizeConfig,
112112
cumsumConfig,
113-
depthwiseConv2DNativeConfig,
113+
depthwiseConv2dNativeConfig,
114114
divConfig,
115115
equalConfig,
116116
expConfig,

tfjs-converter/metadata/kernel2op.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@
315315
"onesLike"
316316
],
317317
"Pack": [
318-
"tidy",
319318
"squeeze",
320-
"util.arraysEqual",
321319
"reshape",
322320
"stack"
323321
],

tfjs-converter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"devDependencies": {
2121
"@rollup/plugin-commonjs": "^11.0.2",
2222
"@rollup/plugin-node-resolve": "^7.1.1",
23+
"@rollup/plugin-replace": "^2.3.3",
2324
"@rollup/plugin-typescript": "^3.0.0",
2425
"@tensorflow/tfjs-backend-cpu": "link:../tfjs-backend-cpu",
2526
"@tensorflow/tfjs-core": "link:../tfjs-core",

tfjs-converter/rollup.config.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import commonjs from '@rollup/plugin-commonjs';
1919
import resolve from '@rollup/plugin-node-resolve';
20+
import replace from '@rollup/plugin-replace';
2021
import typescript from '@rollup/plugin-typescript';
2122
import {terser} from 'rollup-plugin-terser';
2223
import visualizer from 'rollup-plugin-visualizer';
@@ -74,10 +75,16 @@ function config({
7475
output: {
7576
banner: PREAMBLE,
7677
sourcemap: true,
77-
globals: {'@tensorflow/tfjs-core': 'tf'},
78+
globals: {
79+
'@tensorflow/tfjs-core': 'tf',
80+
'@tensorflow/tfjs-core/dist/ops/ops_for_converter': 'tf'
81+
},
7882
...output
7983
},
80-
external: ['@tensorflow/tfjs-core', ...external],
84+
external: [
85+
'@tensorflow/tfjs-core',
86+
'@tensorflow/tfjs-core/dist/ops/ops_for_converter', ...external
87+
],
8188
onwarn: warning => {
8289
let {code} = warning;
8390
if (code === 'CIRCULAR_DEPENDENCY' || code === 'CIRCULAR' ||
@@ -161,6 +168,29 @@ module.exports = cmdOptions => {
161168
},
162169
tsCompilerOptions: {target: 'es2017'}
163170
}));
171+
172+
// Miniprogram entry (minified es5)
173+
bundles.push(config({
174+
plugins: [
175+
// replace dist import with tfjs-core because miniprogram build
176+
// systems modify the package structure of our npm package, and only
177+
// mirrors the 'main' entries.
178+
replace({
179+
'@tensorflow/tfjs-core/dist/ops/ops_for_converter':
180+
'@tensorflow/tfjs-core',
181+
delimiters: ['', '']
182+
}),
183+
terserPlugin
184+
],
185+
output: {
186+
format: browserFormat,
187+
name,
188+
extend,
189+
file: `dist/miniprogram/index.js`,
190+
freeze: false
191+
},
192+
tsCompilerOptions: {target: 'es5'},
193+
}));
164194
}
165195

166196
return bundles;

tfjs-converter/scripts/build-npm.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,5 @@ yarn
2222
yarn build-ci
2323
yarn rollup -c --visualize --npm
2424

25-
# Use minified files for miniprogram
26-
mkdir dist/miniprogram
27-
cp dist/tf-converter.min.js dist/miniprogram/index.js
28-
cp dist/tf-converter.min.js.map dist/miniprogram/index.js.map
29-
3025
echo "Stored standalone library at dist/tf-converter(.min).js"
3126
npm pack

0 commit comments

Comments
 (0)