Skip to content

Conversation

@yhwang
Copy link
Contributor

@yhwang yhwang commented Dec 7, 2019

Modify the install.js to support external binaries while installing
npm package. It reads the custom-binary.json configuration file to
get URLs for the following resources:

  • 'tf-lib': libtensorflow and libtensorflow_framework shared libraries.
    Its value is a URL that points to a tar.gz or zip and
    contains the shared libaries and header files.
  • 'addon': pre-compiled node binding. Its value is a object contains
    three values: host, remote_path and package_name. These three
    values are concatenated into a URL that points to the
    pre-compiled node binding.

If you only provide tf-lib and no addon. It compiles the node
binding while installing the npm package.

Signed-off-by: Yihong Wang yh.wang@ibm.com

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@yhwang
Copy link
Contributor Author

yhwang commented Dec 7, 2019

Hi @kangyizhang, in order to support aarch64, I added architecture into the filename of those pre-compiled resources which are stored in the cloud storage. For example, CPU-darwin-1.14.0.tar.gz becomes CPU-darwin-x86_64-1.14.0.tar.gz. Please review the naming change and see if it can support more platform and architectures in the future.

And I can help to provide the arm64 binaries for linux platform.

@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch from 86775a4 to 62381d8 Compare December 9, 2019 18:25
Copy link
Contributor

@kangyizhang kangyizhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yihong, thanks a lot for this PR. Left minor comment. Let me know when you want me to upload the libtensorflow of arm64.

Reviewable status: 0 of 1 approvals obtained (waiting on @yhwang)


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

  }

  return `${BASE_URI}${libType}-${PLATFORM_MAPPING[platform]}-` +

Can you add a special case here for GPU+darwin? Since there is no gpu libtensorflow for darwin, here the libType should always be CPU if platform is darwin.

@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch from 62381d8 to a337cb7 Compare December 9, 2019 21:46
Copy link
Contributor Author

@yhwang yhwang left a 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 @kangyizhang)


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

Previously, kangyizhang (Kangyi Zhang) wrote…

Can you add a special case here for GPU+darwin? Since there is no gpu libtensorflow for darwin, here the libType should always be CPU if platform is darwin.

or should we have a list to store all supported platforms, types and architectures. then reject the unsupported combination?

Copy link
Contributor Author

@yhwang yhwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have gpu-linux-arm64 binary. how about cpu-linux-arm64?

Reviewable status: 0 of 1 approvals obtained (waiting on @kangyizhang)

@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch from a337cb7 to 5df4cd2 Compare December 10, 2019 03:02
@yhwang
Copy link
Contributor Author

yhwang commented Dec 10, 2019

@kangyizhang I made some changes and it detects if the system is supported or not. In arm64 system, it also runs node-pre-gyp command with --build-from-source option.

Let me know when you want me to upload the libtensorflow of arm64.

I put gpu-linux-arm64 here

@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch from 5df4cd2 to 2b3be58 Compare December 10, 2019 19:05
@yhwang yhwang requested a review from kangyizhang December 13, 2019 00:56
@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch 3 times, most recently from b888da2 to c2022ca Compare December 13, 2019 23:42
@yhwang
Copy link
Contributor Author

yhwang commented Dec 13, 2019

In the latest change, install.js checks custom-binary.json at the same directory and retrieve the custom binaries if external resource URLs are specified. If custom-binary.json doesn't exist, then install.js retrieves binaries from GCP.

Copy link
Contributor Author

@yhwang yhwang left a 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 @kangyizhang)


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

Previously, yhwang (Yihong Wang) wrote…

or should we have a list to store all supported platforms, types and architectures. then reject the unsupported combination?

I added an array to store all official supported systems and throw an error if it's unsupported system.

Copy link
Contributor Author

@yhwang yhwang left a 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 @kangyizhang)


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

Previously, yhwang (Yihong Wang) wrote…

I added an array to store all official supported systems and throw an error if it's unsupported system.

Done.

Copy link
Contributor

@kangyizhang kangyizhang left a 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 @kangyizhang and @yhwang)


tfjs-node/scripts/get-addon-name.js, line 74 at r2 (raw file):

Quoted 6 lines of code…
  customTFLibUri: customBinaries['tf-lib'],
  customAddon: customBinaries['addon'],
  ARCH_MAPPING,
  PLATFORM_MAPPING,
  PLATFORM_EXTENSION,
  ALL_SUPPORTED_COMBINATION

can you move these constant values to scripts/deps-constants.js? I think you were having these fields in deps-constants.js file in the previous version of this PR. I'm requesting this because this file is suppose to be only used to generate pre-compiled addon-name, which is heavily used when we develop and publish new NPM package. Other constants should stay in the deps-constants.js file.


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

Previously, yhwang (Yihong Wang) wrote…

Done.

Thanks for adding the list of supported platforms. But we should still make an exception for mac+gpu with no customized binary. Because there might be existing users using tfjs-node-gpu on their mac, maybe developing process that runs on cloud with CUDA GPU, and a new version of this library should not break their development.


tfjs-node/scripts/install.js, line 168 at r2 (raw file):

      cp.exec('node scripts/deps-stage.js symlink ' + modulePath);
    }
    revertAddonName();

can you keep revertAddonName() here to ensure that it's called after node-pre-gyp install is executed. Otherwise the addon name in package.json might be reverted before node-pre-gyp runs.

Copy link
Contributor

@kangyizhang kangyizhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update. Do you mind to provide an example of the custom-binary.json file (base on the code it seems like it should include all the fields in package.json.binary) so that I can use it to update the readme file?

Reviewable status: 0 of 1 approvals obtained (waiting on @kangyizhang and @yhwang)

Modify the install.js to support external binaries while installing
npm package. It reads the `custom-binary.json` configuration file to
get URLs for the following resources:
- 'tf-lib': libtensorflow and libtensorflow_framework shared libraries.
  Its value is a URL that points to a `tar.gz` or `zip` and
  contains the shared libaries and header files.
- 'addon': pre-compiled node binding. Its value is a object contains
  three values: `host`, `remote_path` and `package_name`. These three
  values are concatenated into a URL that points to the
  pre-compiled node binding.

If you only provide `tf-lib` and no `addon`. It compiles the node
binding while installing the npm package.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
@yhwang yhwang force-pushed the tfjs-nodejs-support-aarch64 branch from c2022ca to 73c8461 Compare December 17, 2019 18:11
Copy link
Contributor Author

@yhwang yhwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added custom-binary.sample.json as the example for custom-binary.json

Reviewable status: 0 of 1 approvals obtained (waiting on @kangyizhang)


tfjs-node/scripts/get-addon-name.js, line 74 at r2 (raw file):

Previously, kangyizhang (Kangyi Zhang) wrote…
  customTFLibUri: customBinaries['tf-lib'],
  customAddon: customBinaries['addon'],
  ARCH_MAPPING,
  PLATFORM_MAPPING,
  PLATFORM_EXTENSION,
  ALL_SUPPORTED_COMBINATION

can you move these constant values to scripts/deps-constants.js? I think you were having these fields in deps-constants.js file in the previous version of this PR. I'm requesting this because this file is suppose to be only used to generate pre-compiled addon-name, which is heavily used when we develop and publish new NPM package. Other constants should stay in the deps-constants.js file.

sure. my thought is those constants belong to add-on. That's why I had them here. I moved them to deps-constants.js now


tfjs-node/scripts/install.js, line 93 at r1 (raw file):

Previously, kangyizhang (Kangyi Zhang) wrote…

Thanks for adding the list of supported platforms. But we should still make an exception for mac+gpu with no customized binary. Because there might be existing users using tfjs-node-gpu on their mac, maybe developing process that runs on cloud with CUDA GPU, and a new version of this library should not break their development.

add an exception for mac+gpu case. done


tfjs-node/scripts/install.js, line 168 at r2 (raw file):

Previously, kangyizhang (Kangyi Zhang) wrote…

can you keep revertAddonName() here to ensure that it's called after node-pre-gyp install is executed. Otherwise the addon name in package.json might be reverted before node-pre-gyp runs.

done. I also moved some related code to here. It's easier to read.

@yhwang yhwang requested a review from kangyizhang December 17, 2019 18:30
Copy link
Contributor

@kangyizhang kangyizhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

I made some edits for readability and added some instruction in readme file. Please verify if the edition works with your binary. Otherwise LGTM.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @kangyizhang)

@yhwang
Copy link
Contributor Author

yhwang commented Dec 18, 2019

looks good to me. thanks for removing the try/finally. I left it there and forgot to remove it.

@kangyizhang
Copy link
Contributor

thank you for the PR!

@kangyizhang kangyizhang merged commit 6323566 into tensorflow:master Dec 18, 2019
@yhwang yhwang deleted the tfjs-nodejs-support-aarch64 branch December 18, 2019 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants