reorganize tfjs bundle

pull/356/head
Vladimir Mandic 2021-09-14 22:07:13 -04:00
parent fae1e76af5
commit 246415b8cc
5 changed files with 44 additions and 25 deletions

View File

@ -9,8 +9,9 @@
## Changelog
### **HEAD -> main** 2021/09/13 mandic00@live.com
### **HEAD -> main** 2021/09/14 mandic00@live.com
- add platform and backend capabilities detection
- enhanced automated tests
- enable canvas patching for nodejs
- full ts strict typechecks

View File

@ -83,6 +83,14 @@
"output": "dist/human.node-wasm.js",
"external": ["@tensorflow"]
},
{
"name": "tfjs/browser/version",
"platform": "browser",
"format": "esm",
"input": "tfjs/tf-version.ts",
"output": "dist/tfjs.version.js",
"external": ["fs", "os", "buffer", "util"]
},
{
"name": "tfjs/browser/esm/nobundle",
"platform": "browser",

View File

@ -102,7 +102,7 @@ export async function backendInfo() {
env.webgl.backend = env.backends.includes('webgl');
if (env.webgl.supported && env.webgl.backend) {
// @ts-ignore getGPGPUContext only exists on WebGL backend
const gl = tf.backend().gpgpu !== 'undefined' ? await tf.backend().getGPGPUContext().gl : null;
const gl = (tf.backend().gpgpu !== 'undefined') && (tf.backend().getGPGPUContext) ? await tf.backend().getGPGPUContext().gl : null;
if (gl) {
env.webgl.version = gl.getParameter(gl.VERSION);
env.webgl.renderer = gl.getParameter(gl.RENDERER);

View File

@ -3,16 +3,6 @@
* @external
*/
// get versions of all packages
import { version as tfjsVersion } from '@tensorflow/tfjs/package.json';
import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json';
import { version as tfjsDataVersion } from '@tensorflow/tfjs-data/package.json';
import { version as tfjsLayersVersion } from '@tensorflow/tfjs-layers/package.json';
import { version as tfjsConverterVersion } from '@tensorflow/tfjs-converter/package.json';
import { version as tfjsBackendCPUVersion } from '@tensorflow/tfjs-backend-cpu/package.json';
import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-webgl/package.json';
import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json';
// export all from sources
// requires treeShaking:ignore-annotations due to tfjs misconfiguration
/*
@ -25,7 +15,8 @@ export * from '@tensorflow/tfjs-backend-webgl/src/index';
export * from '@tensorflow/tfjs-backend-wasm/src/index';
*/
// export all from build
// export all from build individual packages
/*
export * from '@tensorflow/tfjs-core/dist/index.js';
export * from '@tensorflow/tfjs-layers/dist/index.js';
export * from '@tensorflow/tfjs-converter/dist/index.js';
@ -33,16 +24,15 @@ export * as data from '@tensorflow/tfjs-data/dist/index.js';
export * from '@tensorflow/tfjs-backend-cpu/dist/index.js';
export * from '@tensorflow/tfjs-backend-webgl/dist/index.js';
export * from '@tensorflow/tfjs-backend-wasm/dist/index.js';
// export * from '@tensorflow/tfjs-backend-webgpu/dist/index.js'; // experimental
*/
// export versions
export const version = {
tfjs: tfjsVersion,
'tfjs-core': tfjsCoreVersion,
'tfjs-data': tfjsDataVersion,
'tfjs-layers': tfjsLayersVersion,
'tfjs-converter': tfjsConverterVersion,
'tfjs-backend-cpu': tfjsBackendCPUVersion,
'tfjs-backend-webgl': tfjsBackendWebGLVersion,
'tfjs-backend-wasm': tfjsBackendWASMVersion,
};
// export all from build bundle
export * from '@tensorflow/tfjs/dist/index.js';
export * from '@tensorflow/tfjs-backend-webgl/dist/index.js';
export * from '@tensorflow/tfjs-backend-wasm/dist/index.js';
// add webgpu to bundle, experimental
// export * from '@tensorflow/tfjs-backend-webgpu/dist/index.js';
// export versions, overrides version object from @tensorflow/tfjs
export { version } from '../dist/tfjs.version.js';

20
tfjs/tf-version.ts Normal file
View File

@ -0,0 +1,20 @@
// get versions of all packages
import { version as tfjsVersion } from '@tensorflow/tfjs/package.json';
import { version as tfjsCoreVersion } from '@tensorflow/tfjs-core/package.json';
import { version as tfjsDataVersion } from '@tensorflow/tfjs-data/package.json';
import { version as tfjsLayersVersion } from '@tensorflow/tfjs-layers/package.json';
import { version as tfjsConverterVersion } from '@tensorflow/tfjs-converter/package.json';
import { version as tfjsBackendCPUVersion } from '@tensorflow/tfjs-backend-cpu/package.json';
import { version as tfjsBackendWebGLVersion } from '@tensorflow/tfjs-backend-webgl/package.json';
import { version as tfjsBackendWASMVersion } from '@tensorflow/tfjs-backend-wasm/package.json';
export const version = {
tfjs: tfjsVersion,
'tfjs-core': tfjsCoreVersion,
'tfjs-data': tfjsDataVersion,
'tfjs-layers': tfjsLayersVersion,
'tfjs-converter': tfjsConverterVersion,
'tfjs-backend-cpu': tfjsBackendCPUVersion,
'tfjs-backend-webgl': tfjsBackendWebGLVersion,
'tfjs-backend-wasm': tfjsBackendWASMVersion,
};