UNPKG

3.4 kBMarkdownView Raw
1# TensorFlow.js Node.js bindings development.
2
3The @tensorflow/tfjs-node repo supports npm package @tensorflow/tfjs-node and @tensorflow/tfjs-node-gpu on Windows/Mac/Linux. This guide lists commands to use when developing this package.
4
5## Install
6
7#### Dependencies and addon module
8
9```sh
10$ yarn
11```
12
13This command installs all dependencies and devDependencies listed in package.json. It also downloads the TensorFlow C library and native node addon.
14
15#### Compile native addon from source files
16
17```sh
18$ yarn build-addon-from-source
19```
20
21This command will compile a new native node addon from source files.
22
23####
24
25```sh
26$ yarn install-from-source
27```
28
29This command does the following:
30
311. Clears local binary and addon resources
322. Downloads the TensorFlow C library
333. Compiles the native addon from source files (instead of downloading pre-compile addon)
34
35#### Switching local workflow to CUDA/GPU
36
37```sh
38$ yarn enable-gpu
39```
40
41This command is the same as `yarn install-from-source` except it uses the TensorFlow GPU library.
42
43## Build and test
44
45#### Compile javascript files from typescript
46
47```sh
48$ yarn build
49```
50
51#### Publish locally through yalc to test this package in another repo
52
53```sh
54$ yarn publish-local
55```
56
57This command packs the `tfjs-node` package and publishes locally through [yalc](https://github.com/whitecolor/yalc).
58NOTE: Dependent packages must install this locally published package through yalc and compile the node native addon locally. In the dependent package run the following command to link local published `tfjs-node` package:
59
60```sh
61$ yalc link @tensorflow/tfjs-node
62$ cd .yalc/@tensorflow/tfjs-node
63$ yarn && yarn build-addon-from-source
64$ cd ../../..
65```
66
67#### Run tests
68
69```sh
70$ yarn test
71```
72
73## Prepare and publish
74
75#### Prerequisite: install GCP command line tool
76
77Publishing this package requires uploading objects to GCP bucket. Developers need to install GCP command line tool [gsutil](https://cloud.google.com/storage/docs/gsutil_install) before publishing. Please ask TFJS developers for GCP project ID.
78
79#### Build and upload node addon to Google Cloud Platform
80
81```sh
82$ yarn build-addon upload
83```
84
85This command will compile, compress, and upload a new node addon to GCP bucket. Please read [build-and-upload-addon.sh](./scripts/build-and-upload-addon.sh) for details.
86
87#### Build NPM package
88
89```sh
90$ yarn build-npm
91```
92
93This command will build a new version of tfjs-node/tfjs-node-gpu NPM tarball. NOTE: this command does not update the pre-compiled node addon to GCP (see `yarn build-addon upload`).
94
95#### Build NPM package and upload node addon
96
97```sh
98$ yarn build-npm upload
99```
100
101This command combines the above two commands.
102
103#### Publish NPM package
104
105```sh
106$ yarn publish-npm
107```
108
109This command compiles a new node addon, upload it to GCP, then builds and publishes a new npm package. Please read instruction in [publish-npm.sh](./scripts/publish.sh) before publishing.
110
111#### Build and upload node addon on Windows
112
113```sh
114$ yarn upload-windows-addon
115$ yarn upload-windows-addon-gpu
116```
117
118Most times the NPM package is published on Linux machine, and only the Linux node addon is compiled and uploaded to GCP bucket. To build and upload the native node addon for Windows, developers should run the above commands on Windows machine. Please read [build-and-upload-windows-addon.bat](./scripts/build-and-upload-windows-addon.bat) for details.