New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wasm] Build tfjs-backend-wasm entirely with Bazel #6458
Conversation
98f5cae
to
87bd487
Compare
c97c499
to
126dccc
Compare
126dccc
to
9e26e90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 approvals obtained (waiting on @jinjingforever and @pyu10055)
link-package/build_deps.ts
line 23 at r2 (raw file):
import * as path from 'path'; import * as rimraf from 'rimraf'; import {BAZEL_PACKAGES} from '../scripts/bazel_packages';
This change is moved to #6510
Code quote:
import {BAZEL_PACKAGES} from '../scripts/bazel_packages';
scripts/bundle-size-util.js
line 24 at r2 (raw file):
+(exec(`ls -l ${filename} | awk '{print $5}'`, {silent: true})); const gzipFileSizeBytes = +(exec(`ls -l ${gzipFilename} | awk '{print $5}'`, {silent: true}));
Moved to #6509
Code quote:
function getFileSizeBytes(filename) {
const gzipFilename = `${filename}.gzip`;
exec(`gzip -c ${filename} > ${gzipFilename}`, {silent: true});
const fileSizeBytes =
+(exec(`ls -l ${filename} | awk '{print $5}'`, {silent: true}));
const gzipFileSizeBytes =
+(exec(`ls -l ${gzipFilename} | awk '{print $5}'`, {silent: true}));
return {fileSizeBytes, gzipFileSizeBytes};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 approvals obtained (waiting on @jinjingforever and @pyu10055)
tfjs-backend-wasm/wasm-out/BUILD.bazel
line 57 at r3 (raw file):
create_worker_module( name = "create_worker_module", cjs = True,
Note that this changes the WASM worker module's format to commonjs.
export const wasmWorkerContents =
becomes module.exports.wasmWorkerContents =
This is to make node tests work.
Code quote:
cjs = True,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Thank you for making this work. And it is nice to see the checklist in the PR!
BTW, do we already have a way to test the output package of this new build method in some end-to-end tests?
Thanks for the review, Jing! I added tfjs-backend-wasm to our e2e tests. It loads correctly, but there seems to be a memory leak when calculating gradients.
I added the original wasm build to e2e to see if this is a regression, and it doesn't seem to be. The same error appears in the original build. Maybe I should skip that test for this PR and fix it in a different one. |
SGTM. Thanks! |
19888d6
to
c6491d3
Compare
Enable esModuleInterop in the root tsconfig to allow importing the generated wasm js entrypoints from node. Change the threaded worker module format from ESM to CJS to support loading it from node. Remove `sideEffects` from package.json.
util is a module, so it should not be spied on (not supported in ts4). platform is an object, so it can be spied on.
f8b8a1e
to
ede8197
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pushing this forward!
Reviewable status: complete! 2 of 1 approvals obtained (waiting on @mattsoulanille)
e2e/integration_tests/setup_test.ts
line 39 at r5 (raw file):
}); registerTestEnv({
if we are not testing wasm yet in e2e, should this registration be added later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
Reviewable status: complete! 2 of 1 approvals obtained (waiting on @pyu10055)
e2e/integration_tests/setup_test.ts
line 39 at r5 (raw file):
Previously, pyu10055 (Ping Yu) wrote…
if we are not testing wasm yet in e2e, should this registration be added later?
We're still testing wasm in e2e. I've just disabled the one failing test that appeared when I added it to e2e.
Build tfjs-backend-wasm with Bazel. tfjs-backend-wasm already uses Bazel for Emscripten. This PR makes it use Bazel for TypeScript as well and replaces the build scripts with a single pkg_npm target.
Fixes #5282
BAZEL_PACKAGES
in e2e/scripts/publish-tfjs-ci.shBAZEL_PACKAGES
in scripts/bazel_packages.tspkg_npm
has all the files it needs, e.g. the README.enumerate_tests
rule is usually necessary to make the browser actually run tests.cloudbuild.yml
file is removed. Do not remove the package from scripts/package_dependencies.json.nightly
orci
(tfjs_web_test
automatically tags tests withnightly
andci
).pkg_npm
rule is tagged withci
ornightly
so all parts of the build are tested.package.json
scripts are updated and that the package.json includes@bazel/bazelisk
as a dev dependency.build-npm
script and apublish-npm
script. These are used by the release script._stats
files for info on this.To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
This change is