Skip to content

Commit 0815ff2

Browse files
[tfjs-converter] Bazel build migration (#5388)
FEATURE INTERNAL * init check in for converter bazel migration * fixed build failure * fix test target error * tests are passing * added test_snippets target * add gen_json rule * create gen-json bazel rule * added build rules for converter pyton package * added python runtimes and update pip test script * fixed dupe deps * updated cloud build * fixed bazel lint error * fix test generated cloudbuild * use bazel installed python interpreter for pip_install; * fix bazel format * fix pip test * update converter npm link * add link package for tfjs-converter * Generate converter files needed for the build with Bazel (#5393) * Generate .ts op files from json * Generate kernel2op with bazel * Remove console.logs * Bazel lint * Build all ops with a single target * Update contributing missing op readme * Bazel lint * fixed converter python tests * fix failed test * Update converter entrypoints (#5395) * Update converter entrypoints * Add converter to 'reinstall' in link-package * fixed tfjs union package test * remove gen_json rule * fix bazel lint * fix lint * Add kernel2ops to converter pkg (#5399) * Add kernel2ops to converter pkg * remove copy metadata target * disable python toolchain registration * added py toolchain back * update th link package * remove numpy requirement * disable python runtime registration * register the python runtimes * update the make-version script to update the python BUILD file for the package.json version * updated converter nightly test cloud build * fixed the cloud build file * build the wheel in the test script * use root dir * fixed tests * fixes * update iamge * fix yml * revert * fixed cloudbuild test * list the pip files * update cloudbuild * cp instead of mv * adding more log * update log * update log * update log * Use a different symlink prefix for wasm builds (#5455) FEATURE * removed debug logging * limit numpy version * increase nightly time limit * added converter to bazel packages * address the comments * fixed js and python tests * addressed comments * fixed build file test * fix bazel format * fix typo * fix tfjs tool test Co-authored-by: Matthew Soulanille <[email protected]>
1 parent 5ce7b3e commit 0815ff2

Some content is hidden

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

67 files changed

+1356
-4249
lines changed

CONTRIBUTING_MISSING_OP.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,14 @@ In `run_tests.ts`, `IGNORE_LIST`, add test_name to the list.
7171
* [WASM backend Round](https://github.com/tensorflow/tfjs/pull/4486)
7272

7373
### Step 3. Add the op to Converter’s executor.
74-
1. Add op mapping in the op list ts file, use your best judgement to assign an op category: `tfjs-converter/src/operations/op_list/{corresponding_op_category}.ts`. Use
74+
1. Add op mapping in the op list ts file, use your best judgement to assign an op category: `tfjs-converter/python/tensorflowjs/op_list/{corresponding_op_category}.json`. The corresponding `.ts` file will be automatically generated when converter is built. Use
7575
the [TF C++ op api](https://www.tensorflow.org/api_docs/cc/) as reference for tfOpName, inputs, and attrs.
7676

77-
2. Auto generates corresponding json file by running following command in directory tfjs-converter: `yarn gen-json`. Check that the json object is generated in `python/tensorflowjs/op_list/{corresponding_op_group}.json`
77+
2. Find the corresponding executor for the op and add the op to the switch, the [executors](https://github.com/tensorflow/tfjs/tree/master/tfjs-converter/src/operations/executors) are in `tfjs-converter/src/operations/executors`.
7878

79-
3. Find the corresponding executor for the op and add the op to the switch, the [executors](https://github.com/tensorflow/tfjs/tree/master/tfjs-converter/src/operations/executors) are in `tfjs-converter/src/operations/executors`.
79+
3. Add a test to the corresponding executor test file.
8080

81-
4. Add a test to the corresponding executor test file.
82-
83-
5. Update the supported op doc in `tfjs-converter/docs/supported_ops.md`.
84-
85-
6. Add a mapping in kernel2op.json.
81+
4. Update the supported op doc in `tfjs-converter/docs/supported_ops.md`.
8682

8783
**Example PRs**
8884
* [SparseReshape Op](https://github.com/tensorflow/tfjs/pull/4963)

WORKSPACE

+86
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,89 @@ http_archive(
209209
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
210210

211211
bazel_skylib_workspace()
212+
213+
# Special logic for building python interpreter with OpenSSL from homebrew.
214+
# See https://devguide.python.org/setup/#macos-and-os-x
215+
_py3_configure = """
216+
if [[ "$OSTYPE" == "darwin"* ]]; then
217+
./configure --prefix=$(pwd)/bazel_install_py3 --with-openssl=$(brew --prefix openssl)
218+
else
219+
./configure --prefix=$(pwd)/bazel_install_py3
220+
fi
221+
"""
222+
223+
_py2_configure = """
224+
if [[ "$OSTYPE" == "darwin"* ]]; then
225+
./configure --prefix=$(pwd)/bazel_install_py2 --with-openssl=$(brew --prefix openssl)
226+
else
227+
./configure --prefix=$(pwd)/bazel_install_py2
228+
fi
229+
"""
230+
231+
http_archive(
232+
name = "python3_interpreter",
233+
build_file_content = """
234+
exports_files(["python3_bin"])
235+
filegroup(
236+
name = "files",
237+
srcs = glob(["bazel_install_py3/**"], exclude = ["**/* *"]),
238+
visibility = ["//visibility:public"],
239+
)
240+
""",
241+
patch_cmds = [
242+
"mkdir $(pwd)/bazel_install_py3",
243+
_py3_configure,
244+
"make",
245+
"make install",
246+
"ln -s bazel_install_py3/bin/python3 python3_bin",
247+
],
248+
sha256 = "fb1a1114ebfe9e97199603c6083e20b236a0e007a2c51f29283ffb50c1420fb2",
249+
strip_prefix = "Python-3.8.11",
250+
urls = ["https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tar.xz"],
251+
)
252+
253+
http_archive(
254+
name = "python2_interpreter",
255+
build_file_content = """
256+
exports_files(["python_bin"])
257+
filegroup(
258+
name = "files",
259+
srcs = glob(["bazel_install_py2/**"], exclude = ["**/* *"]),
260+
visibility = ["//visibility:public"],
261+
)
262+
""",
263+
patch_cmds = [
264+
"mkdir $(pwd)/bazel_install_py2",
265+
_py2_configure,
266+
"make",
267+
"make install",
268+
"ln -s bazel_install_py2/bin/python python_bin",
269+
],
270+
sha256 = "a4f05a0720ce0fd92626f0278b6b433eee9a6173ddf2bced7957dfb599a5ece1",
271+
strip_prefix = "Python-2.7.13",
272+
urls = ["https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz"],
273+
)
274+
275+
register_toolchains("//tfjs-converter/python:tfjs_py_toolchain")
276+
277+
http_archive(
278+
name = "rules_python",
279+
sha256 = "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b",
280+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.3.0/rules_python-0.3.0.tar.gz",
281+
)
282+
283+
load("@rules_python//python:pip.bzl", "pip_install")
284+
285+
# Create a central external repo, @tensorflowjs_dev_deps, that contains Bazel targets for all the
286+
# third-party packages specified in the requirements.txt file.
287+
pip_install(
288+
name = "tensorflowjs_dev_deps",
289+
python_interpreter_target = "@python3_interpreter//:python3_bin",
290+
requirements = "//tfjs-converter/python:requirements-dev.txt",
291+
)
292+
293+
pip_install(
294+
name = "tensorflowjs_deps",
295+
python_interpreter_target = "@python3_interpreter//:python3_bin",
296+
requirements = "//tfjs-converter/python:requirements.txt",
297+
)
4 MB
Binary file not shown.
4 MB
Binary file not shown.
982 KB
Binary file not shown.

e2e/benchmarks/movenet/model.json

+1
Large diffs are not rendered by default.

e2e/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@tensorflow/tfjs-backend-cpu": "link:../link-package/node_modules/@tensorflow/tfjs-backend-cpu",
1414
"@tensorflow/tfjs-backend-wasm": "link:../tfjs-backend-wasm",
1515
"@tensorflow/tfjs-backend-webgl": "link:../tfjs-backend-webgl",
16-
"@tensorflow/tfjs-converter": "link:../tfjs-converter",
16+
"@tensorflow/tfjs-converter": "link:../link-package/node_modules/@tensorflow/tfjs-converter",
1717
"@tensorflow/tfjs-core": "link:../link-package/node_modules/@tensorflow/tfjs-core",
1818
"@tensorflow/tfjs-data": "link:../tfjs-data",
1919
"@tensorflow/tfjs-layers": "link:../tfjs-layers",

e2e/scripts/publish-tfjs-ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ fi
5454

5555
# Packages to publish.
5656
PACKAGES=("tfjs-core" "tfjs-backend-cpu" "tfjs-backend-webgl" \
57-
"tfjs-backend-wasm" "tfjs-layers" "tfjs-converter" "tfjs-data" "tfjs" \
57+
"tfjs-backend-wasm" "tfjs-layers" "tfjs-data" "tfjs" \
5858
"tfjs-node" "tfjs-node-gpu")
5959

6060
# Packages that build with Bazel
61-
BAZEL_PACKAGES=("tfjs-core" "tfjs-backend-cpu" "tfjs-tflite")
61+
BAZEL_PACKAGES=("tfjs-core" "tfjs-backend-cpu" "tfjs-tflite" "tfjs-converter")
6262

6363
for package in "${PACKAGES[@]}"
6464
do

link-package/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"license": "Apache 2.0",
66
"private": true,
77
"scripts": {
8-
"build": "yarn build-link-package-core && yarn reinstall",
8+
"build": "yarn build-link-package-core && yarn build-converter && yarn reinstall",
99
"build-link-package-core": "cd ../link-package-core && yarn build",
10+
"build-converter": "cd ../tfjs-converter && yarn && yarn build",
1011
"reinstall-link-package-core": "cd ../link-package-core && yarn reinstall",
1112
"reinstall": "yarn && yarn reinstall-link-package-core && rimraf node_modules && yarn"
1213
},
1314
"devDependencies": {
1415
"@tensorflow/tfjs-backend-cpu": "link:../link-package-core/node_modules/@tensorflow/tfjs-backend-cpu",
1516
"@tensorflow/tfjs-core": "link:../link-package-core/node_modules/@tensorflow/tfjs-core",
17+
"@tensorflow/tfjs-converter": "file:../dist/bin/tfjs-converter/tfjs-converter_pkg",
1618
"rimraf": "^3.0.2"
1719
}
1820
}

link-package/yarn.lock

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
version "0.0.0"
77
uid ""
88

9+
"@tensorflow/tfjs-converter@file:../dist/bin/tfjs-converter/tfjs-converter_pkg":
10+
version "0.0.0"
11+
912
"@tensorflow/tfjs-core@link:../link-package-core/node_modules/@tensorflow/tfjs-core":
1013
version "0.0.0"
1114
uid ""

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
"@types/node-fetch": "~2.1.2",
2020
"@types/seedrandom": "^2.4.28",
2121
"@types/shelljs": "^0.8.7",
22+
"ajv": "~6.3.0",
2223
"argparse": "^1.0.10",
2324
"chalk": "~2.4.2",
2425
"clang-format": "~1.2.4",
2526
"console-table-printer": "^2.4.32",
27+
"copyfiles": "~1.2.0",
2628
"core-js": "3",
29+
"deep-equal": "^1.0.1",
2730
"jasmine": "~3.1.0",
2831
"jasmine-core": "~3.1.0",
2932
"js-yaml": "^3.14.0",
@@ -36,6 +39,8 @@
3639
"karma-sourcemap-loader": "^0.3.8",
3740
"long": "4.0.0",
3841
"mkdirp": "~0.5.1",
42+
"opn": "~5.1.0",
43+
"protobufjs": "~6.8.6",
3944
"requirejs": "^2.3.6",
4045
"rollup": "^2.46.0",
4146
"rollup-plugin-sourcemaps": "^0.6.3",
@@ -44,6 +49,7 @@
4449
"seedrandom": "^3.0.5",
4550
"shelljs": "~0.8.3",
4651
"terser": "^5.7.0",
52+
"ts-morph": "^11.0.3",
4753
"ts-node": "~8.8.2",
4854
"tslint": "~6.1.3",
4955
"typescript": "3.5.3"

scripts/cloudbuild_tfjs_core_expected.yml

+10-52
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ steps:
6363
waitFor:
6464
- yarn-common
6565
- yarn-link-package
66-
- name: 'node:10'
67-
dir: tfjs-converter
68-
entrypoint: yarn
69-
id: build-tfjs-converter
70-
args:
71-
- build-ci
72-
waitFor:
73-
- yarn-tfjs-converter
74-
- yarn-common
75-
- yarn-link-package
7666
- name: 'node:10'
7767
dir: tfjs-converter
7868
entrypoint: yarn
@@ -84,18 +74,13 @@ steps:
8474
- yarn-common
8575
- yarn-link-package
8676
- name: 'node:10'
87-
dir: tfjs-converter
88-
entrypoint: yarn
89-
id: test-js-tfjs-converter
77+
id: 'create-pips-tfjs-converter'
78+
entrypoint: 'bash'
9079
args:
91-
- test-ci
80+
- './tfjs-converter/scripts/create_python_pips.sh'
9281
waitFor:
93-
- yarn-tfjs-converter
94-
- lint-tfjs-converter
9582
- yarn-common
9683
- yarn-link-package
97-
env:
98-
- NIGHTLY=$_NIGHTLY
9984
- name: gcr.io/google-appengine/python
10085
dir: tfjs-converter/python
10186
entrypoint: bash
@@ -105,34 +90,7 @@ steps:
10590
- '--test'
10691
- /tmp/tfjs-pips
10792
waitFor:
108-
- yarn-common
109-
- yarn-link-package
110-
- name: 'python:2'
111-
dir: tfjs-converter/python
112-
entrypoint: bash
113-
id: test-python2-tfjs-converter
114-
args:
115-
- ./run-python-tests.sh
116-
waitFor:
117-
- yarn-common
118-
- yarn-link-package
119-
- name: 'python:3.6'
120-
dir: tfjs-converter/python
121-
entrypoint: bash
122-
id: test-python3.6-tfjs-converter
123-
args:
124-
- ./run-python-tests.sh
125-
waitFor:
126-
- yarn-common
127-
- yarn-link-package
128-
- name: 'node:10'
129-
dir: tfjs-converter
130-
entrypoint: yarn
131-
id: test-snippets-tfjs-converter
132-
args:
133-
- test-snippets-ci
134-
waitFor:
135-
- build-tfjs-converter
93+
- create-pips-tfjs-converter
13694
- yarn-common
13795
- yarn-link-package
13896
- name: 'node:10'
@@ -412,8 +370,8 @@ steps:
412370
- yarn-common
413371
- yarn-link-package
414372
- yarn-tfjs-converter
415-
- build-tfjs-converter
416373
- lint-tfjs-converter
374+
- create-pips-tfjs-converter
417375
- yarn-tfjs-layers
418376
- build-tfjs-layers
419377
- lint-tfjs-layers
@@ -434,8 +392,8 @@ steps:
434392
- yarn-common
435393
- yarn-link-package
436394
- yarn-tfjs-converter
437-
- build-tfjs-converter
438395
- lint-tfjs-converter
396+
- create-pips-tfjs-converter
439397
- yarn-tfjs-layers
440398
- build-tfjs-layers
441399
- lint-tfjs-layers
@@ -456,8 +414,8 @@ steps:
456414
- yarn-common
457415
- yarn-link-package
458416
- yarn-tfjs-converter
459-
- build-tfjs-converter
460417
- lint-tfjs-converter
418+
- create-pips-tfjs-converter
461419
- yarn-tfjs-layers
462420
- build-tfjs-layers
463421
- lint-tfjs-layers
@@ -479,8 +437,8 @@ steps:
479437
- yarn-common
480438
- yarn-link-package
481439
- yarn-tfjs-converter
482-
- build-tfjs-converter
483440
- lint-tfjs-converter
441+
- create-pips-tfjs-converter
484442
- yarn-tfjs-layers
485443
- build-tfjs-layers
486444
- lint-tfjs-layers
@@ -680,8 +638,8 @@ steps:
680638
- build-tfjs-backend-webgl
681639
- lint-tfjs-backend-webgl
682640
- yarn-tfjs-converter
683-
- build-tfjs-converter
684641
- lint-tfjs-converter
642+
- create-pips-tfjs-converter
685643
- yarn-tfjs-data
686644
- build-tfjs-data
687645
- lint-tfjs-data
@@ -718,8 +676,8 @@ steps:
718676
- build-tfjs-backend-webgl
719677
- lint-tfjs-backend-webgl
720678
- yarn-tfjs-converter
721-
- build-tfjs-converter
722679
- lint-tfjs-converter
680+
- create-pips-tfjs-converter
723681
- yarn-tfjs-data
724682
- build-tfjs-data
725683
- lint-tfjs-data

0 commit comments

Comments
 (0)