tfjs

Custom build of Tensorflow/JS for Browsers as pure ESNext

This solution builds TensorFlow/JS for Browsers, including individual modules as well as a unified bundle

Included Backends: CPU, WebGL, WebGPU, WASM

Node packages (tfjs-node and tfjs-node-gpu) are not covered

Notes


<hr>

Install

  1. Internal dependencies: npm install
  2. External dependencies: git, bazel, python Git: assumed to be already installed if you’re here :)
    Bazel: requires bazel 4.x https://docs.bazel.build/versions/4.2.1/install-ubuntu.html
    Python: requires python 3.x aliased as python, not compatible with python 2.x

Steps

Full Build

Downloads sources and performs full build of all TFJS modules

npm run build executes steps:

  1. scripts/download.sh
    on first run it clones @tensorflow/tfjs from git into ./src
    on subsequent runs it rolls forward cloned copy of @tensorflow/tfjs
  2. scripts/prepare.sh
    creates versioned .tfjs-*.ts from build templates
    and .js imports from .json files
  3. scripts/build-wasm.sh
    build wasm binaries and wasm .js exports using bazel
  4. node scripts/build-tfjs.js
    build targets in /dist using esbuild with custom resolver plugins and TypeScript compiler settings

Fast Build

Available once full build has been completed

npm run build executes steps:

  1. node scripts/build-tfjs.js
    build targets in /dist using esbuild with custom resolver plugins and TypeScript compiler settings

TypeDefs

Default typedefs in types/index.d.ts are re-exports of official @tensorflow/* modules Buildinging typedefs from sources is an experimental feature

npm run types executes steps:

  1. compile all modules using TSC to types/lib
  2. build rollup using API-Extractor to types/tfjs-core.d.ts and types/tfjs.d.ts
  3. patch rollup

Clean

Remove currently downloaded version of TFJS and reset all cached info

npm run clean

Notes


<hr>