Skip to content

Commit 4faed8a

Browse files
author
Nikhil Thorat
authored
Create a tfjs-node-gpu directory. (tensorflow#1925)
Each of the following get copied during "prepare" phase, which is on local NPM install (but not when a dependent package installs): https://docs.npmjs.com/misc/scripts - tfjs-node/src => tfjs-node-gpu/src - tfjs-node/binding => tfjs-node-gpu/binding - tfjs-node/scripts => tfjs-node-gpu/scripts - tfjs-node/binding.gyp => tfjs-node-gpu/binding.gyp We do this with a copy because symlinks have the incorrect local directory structure. This PR also fixes a bug where the node backend file caches the backend (this is incorrect behavior because it may switch out during unit tests or if there are accidentally 2 copies of tfjs-node as a dependency). DEV
1 parent eef8a32 commit 4faed8a

39 files changed

+2718
-106
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ deps/
2626
dist/
2727
tfjs-layers/integration_tests/tfjs2keras/test-data/
2828
tfjs-layers/integration/typescript/yarn.lock
29+
30+
# Ignore the src, binding, scripts of tfjs-node-gpu since it is copied over when
31+
# building.
32+
/tfjs-node-gpu/src
33+
/tfjs-node-gpu/binding
34+
/tfjs-node-gpu/scripts
35+
/tfjs-node-gpu/binding.gyp
36+
2937
lib/
3038
local.log
3139
node_modules/

cloudbuild.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,20 @@ steps:
7171
args: ['./scripts/run-build.sh', 'tfjs-react-native']
7272
waitFor: ['diff']
7373

74-
# Node.
74+
# Node CPU.
7575
- name: 'gcr.io/cloud-builders/gcloud'
7676
entrypoint: 'bash'
7777
id: 'tfjs-node'
7878
args: ['./scripts/run-build.sh', 'tfjs-node']
7979
waitFor: ['diff']
8080

81+
# Node GPU.
82+
- name: 'gcr.io/cloud-builders/gcloud'
83+
entrypoint: 'bash'
84+
id: 'tfjs-node-gpu'
85+
args: ['./scripts/run-build.sh', 'tfjs-node-gpu']
86+
waitFor: ['diff']
87+
8188
# Integration tests
8289
- name: 'node:10'
8390
dir: 'tfjs-core'

scripts/publish-npm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fi
6262
./scripts/make-version.js $1
6363

6464
cd $1
65-
yarn build-npm
65+
yarn build-npm for-publish
6666
cd ..
6767

6868
./scripts/tag-version.js $1

tfjs-node-gpu/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../tfjs-node/.npmignore

tfjs-node-gpu/.nycrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../tfjs-node/.nycrc

tfjs-node-gpu/cloudbuild.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
steps:
2+
# Install common dependencies.
3+
- name: 'node:10'
4+
id: 'yarn-common'
5+
entrypoint: 'yarn'
6+
args: ['install']
7+
8+
# Install tfjs-node dependencies.
9+
- name: 'node:10'
10+
dir: 'tfjs-node-gpu'
11+
entrypoint: 'yarn'
12+
id: 'yarn'
13+
args: ['install']
14+
waitFor: ['yarn-common']
15+
16+
# Unit tests.
17+
- name: 'node:10'
18+
dir: 'tfjs-node-gpu'
19+
entrypoint: 'yarn'
20+
id: 'test'
21+
args: ['test-ci']
22+
waitFor: ['yarn']
23+
24+
# Integration test.
25+
- name: 'node:10'
26+
dir: 'tfjs-node-gpu'
27+
entrypoint: 'yarn'
28+
id: 'test-ts-integration'
29+
args: ['test-ts-integration']
30+
waitFor: ['yarn', 'test']
31+
32+
# CPU / GPU package alignment.
33+
- name: 'node:10'
34+
dir: 'tfjs-node-gpu'
35+
entrypoint: 'yarn'
36+
id: 'ensure-cpu-gpu-packages-align'
37+
args: ['ensure-cpu-gpu-packages-align']
38+
waitFor: ['yarn', 'test']
39+
40+
timeout: 1800s
41+
logsBucket: 'gs://tfjs-build-logs'
42+
options:
43+
logStreamingOption: 'STREAM_ON'
44+
substitution_option: 'ALLOW_LOOSE'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "typescript-integration-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"prep": "yalc link @tensorflow/tfjs-node-gpu && cd node_modules/@tensorflow/tfjs-node-gpu && yarn clean-deps && yarn install-gpu",
8+
"test": "ts-node src/test.ts && tsc && node dist/test.js"
9+
},
10+
"dependencies": {
11+
"ts-node": "^8.0.3",
12+
"typescript": "3.5.3",
13+
"yalc": "^1.0.0-pre.27"
14+
}
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @license
3+
* Copyright 2019 Google Inc. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
* =============================================================================
16+
*/
17+
18+
Error.stackTraceLimit = Infinity;
19+
20+
import * as tf from '@tensorflow/tfjs-node-gpu';
21+
22+
const a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'float32');
23+
const b = tf.tensor2d([5, 6, 7, 8], [2, 2], 'float32');
24+
const c = a.matMul(b);
25+
console.log(c.dataSync());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../tfjs-node/integration/typescript/tsconfig.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../tfjs-node/integration/typescript/yarn.lock

tfjs-node-gpu/package.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"name": "@tensorflow/tfjs-node-gpu",
3+
"version": "1.2.9",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"gypfile": true,
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/tensorflow/tfjs.git"
10+
},
11+
"engines": {
12+
"node": ">=8.11.0"
13+
},
14+
"scripts": {
15+
"build": "tsc",
16+
"build-npm": "./scripts/build-npm.sh",
17+
"build-addon": "./scripts/build-and-upload-addon.sh",
18+
"build-addon-from-source": "node-pre-gyp install --build-from-source",
19+
"clean-deps": "rm -rf deps && rm -rf lib",
20+
"coverage": "nyc ts-node src/run_tests.ts",
21+
"enable-gpu": "node scripts/install.js gpu download && yarn && yarn build-addon-from-source",
22+
"ensure-cpu-gpu-packages-align": "node scripts/ensure-cpu-gpu-packages-align.js",
23+
"format": "clang-format -i -style=Google binding/*.cc binding/*.h",
24+
"install": "yarn install-gpu",
25+
"install-gpu": "node scripts/install.js gpu download",
26+
"install-from-source": "yarn clean-deps && yarn && yarn build-addon-from-source",
27+
"link-local": "yalc link",
28+
"lint": "tslint -p . -t verbose",
29+
"prep": "cd node_modules/@tensorflow/tfjs-core && yarn && yarn build",
30+
"preinstall": "./prep-gpu.sh",
31+
"publish-local": "yarn prep && yalc push",
32+
"test": "ts-node src/run_tests.ts",
33+
"test-ci": "./scripts/test-ci.sh",
34+
"test-ts-integration": "./scripts/test-ts-integration.sh",
35+
"upload-windows-addon": "./scripts/build-and-upload-windows-addon-gpu.bat"
36+
},
37+
"devDependencies": {
38+
"@types/jasmine": "~2.8.6",
39+
"@types/node": "^10.5.1",
40+
"@types/progress": "^2.0.1",
41+
"@types/rimraf": "~2.0.2",
42+
"clang-format": "~1.2.2",
43+
"jasmine": "~3.1.0",
44+
"node-fetch": "^2.3.0",
45+
"node-gyp": "~5.0.3",
46+
"nyc": "^13.3.0",
47+
"tmp": "^0.0.33",
48+
"ts-node": "^5.0.1",
49+
"tslint": "~5.9.1",
50+
"tslint-no-circular-imports": "^0.7.0",
51+
"typescript": "3.5.3",
52+
"yalc": "~1.0.0-pre.21"
53+
},
54+
"dependencies": {
55+
"@tensorflow/tfjs": "1.2.9",
56+
"adm-zip": "^0.4.11",
57+
"https-proxy-agent": "^2.2.1",
58+
"node-pre-gyp": "0.13.0",
59+
"progress": "^2.0.0",
60+
"rimraf": "^2.6.2",
61+
"tar": "^4.4.6"
62+
},
63+
"binary": {
64+
"module_name": "tfjs_binding",
65+
"module_path": "./lib/napi-v{napi_build_version}",
66+
"host": "https://storage.googleapis.com/tf-builds/pre-built-binary",
67+
"remote_path": "./napi-v{napi_build_version}/{version}/",
68+
"napi_versions": [
69+
3,
70+
4
71+
]
72+
}
73+
}

tfjs-node/scripts/build-npm-gpu.sh renamed to tfjs-node-gpu/prep-gpu.sh

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,13 @@
1616

1717
set -e
1818

19-
# The binding builds with a symlink by default, for NPM packages change the
20-
# download option to move libtensorflow next to the prebuilt binary.
21-
sed -i -e 's/symlink/move/' binding.gyp
19+
rm -rf ./src
20+
rm -rf ./binding
21+
rm -rf ./scripts
22+
rm -f binding.gyp
2223

23-
# Build GPU:
24-
sed -i -e 's/tfjs-node"/tfjs-node-gpu"/' package.json
25-
sed -i -e 's/install.js"/install.js gpu download"/' package.json
26-
rimraf deps/
27-
rimraf dist/
28-
rimraf lib/
29-
yarn build-addon "$1"
30-
yarn prep
31-
tsc --sourceMap false
32-
# This produces a tarball that will later be used by `npm publish`.
33-
npm pack
24+
cp -R ../tfjs-node/src ./src
25+
cp -R ../tfjs-node/binding ./binding
26+
cp -R ../tfjs-node/scripts ./scripts
27+
cp -R ../tfjs-node/binding.gyp .
3428

35-
# Revert GPU changes:
36-
sed -i -e 's/move/symlink/' binding.gyp
37-
sed -i -e 's/tfjs-node-gpu"/tfjs-node"/' package.json
38-
sed -i -e 's/install.js gpu download"/install.js"/' package.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/gif_test.gif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/image_bmp_4_channel_test.bmp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/image_bmp_test.bmp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/image_jpeg_test.jpeg
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/image_png_4_channel_test.png
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tfjs-node/test_images/image_png_test.png

tfjs-node-gpu/tsconfig.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"moduleResolution": "node",
5+
"noImplicitAny": true,
6+
"sourceMap": true,
7+
"removeComments": false,
8+
"preserveConstEnums": true,
9+
"declaration": true,
10+
"target": "es5",
11+
"lib": [
12+
"es2015",
13+
"dom"
14+
],
15+
"outDir": "./dist",
16+
"noUnusedLocals": true,
17+
"noImplicitReturns": true,
18+
"noImplicitThis": true,
19+
"alwaysStrict": true,
20+
"noUnusedParameters": false,
21+
"pretty": true,
22+
"noFallthroughCasesInSwitch": true,
23+
"allowUnreachableCode": false
24+
},
25+
"include": [
26+
"src/"
27+
],
28+
"exclude": [
29+
"node_modules/"
30+
]
31+
}

tfjs-node-gpu/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../tfjs-node/tslint.json

0 commit comments

Comments
 (0)