[go: nahoru, domu]

Skip to content
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

Making tensorflow size smaller using selective registration for MacOs #53202

Open
Nizarazo opened this issue Nov 25, 2021 · 5 comments
Open

Making tensorflow size smaller using selective registration for MacOs #53202

Nizarazo opened this issue Nov 25, 2021 · 5 comments
Assignees
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower subtype:macOS macOS Build/Installation issues TF 2.7 Issues related to TF 2.7.0 type:build/install Build and install issues type:feature Feature requests

Comments

@Nizarazo
Copy link
Nizarazo commented Nov 25, 2021

Please make sure that this is a build/installation issue. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:build_template

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOs Monterey
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: not relevant
  • TensorFlow installed from (source or binary): source
  • TensorFlow version: 2.7.0
  • Python version: 3.9
  • Installed using virtualenv? pip? conda?: not relevant
  • Bazel version (if compiling from source): 3.7.2
  • GCC/Compiler version (if compiling from source): not relevant
  • CUDA/cuDNN version: not relevant
  • GPU model and memory: not relevant

Describe the problem
I am trying to make TF size smaller on MacOs the size is 950mb but after using the below optional flags the size is reduced to 839mb:
--config=nogcp --config=nonccl --config=noaws --config=nohdfs --define=with_xla_support=false --define=with_ignite_support=false --define=with_kafka_support=false

  1. Is there any more flags that can be used to reduce the size of TF?

  2. Since it is still big 839mb I would like to use the selective registration method to get only the operations I use in my model as described in:
    https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/print_selective_registration_header.py

I followed the steps mentioned in this link but I am not finding equivalent command for MacOs for the following step:
bazel build -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/tools/android/inference_interface:libtensorflow_inference.so
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain
--crosstool_top=//external:android/crosstool --cpu=armeabi-v7a

My questions:

  1. Is the selective registration supported for android only? I didn't find a directory named MacOs in //tensorflow/tools/?

  2. I need to support both cpu intel and arm so what I should type in --cpu?
    I tried --cpu=x86_64 and --cpu=arm64 got:
    ERROR: /private/var/tmp/_bazel_integrator/0a793f72f57e57f678a00d6fdcdcda5e/external/local_config_cc/BUILD:41:19: in cc_toolchain_suite rule @local_config_cc//:toolchain: cc_toolchain_suite '@local_config_cc//:toolchain' does not contain a toolchain for cpu 'x86_64'

  3. What is the equivalent command for MacOs for --crosstool_top=//external:android/crosstool ?
    I tried --crosstool_top=//external:macos/crosstool but got error:
    no such target '//external:macos/crosstool': target 'macos/crosstool' not declared in package 'external' defined by /Users/integrator/tensorflow/WORKSPACE

Provide the exact sequence of commands / steps that you executed before running into the problem

  1. git clone https://github.com/tensorflow/tensorflow.git
  2. cd tensorflow
  3. git checkout v2.7.0
  4. ./configure all is no
  5. bazel build tensorflow/python/tools:print_selective_registration_header
  6. bazel-bin/tensorflow/python/tools/print_selective_registration_header --graphs=/Users/integrator/Downloads/vgg_16.ckpt > tensorflow/core/framework/ops_to_register.h

I used an official trained model from here: http://download.tensorflow.org/models/vgg_16_2016_08_28.tar.gz
I got runtime warning for this step:

INFO:tensorflow:Loading proto file /Users/integrator/Downloads/vgg_16.ckpt
I1125 15:27:19.769747 8639198720 selective_registration_header_lib.py:84] Loading proto file /Users/integrator/Downloads/vgg_16.ckpt
/Users/integrator/tensorflow/bazel-bin/tensorflow/python/tools/print_selective_registration_header.runfiles/org_tensorflow/tensorflow/python/tools/selective_registration_header_lib.py:93: RuntimeWarning: Unexpected end-group tag: Not all data was converted
graph_def = graph_pb2.GraphDef.FromString(file_data)

  1. bazel build -c opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/tools/android/inference_interface:libtensorflow_inference.so
    --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
    --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a

Got different errors when running the last step three times in sequence:

  1. ERROR: /private/var/tmp/_bazel_integrator/0a793f72f57e57f678a00d6fdcdcda5e/external/highwayhash/BUILD.bazel:8:11: undeclared inclusion(s) in rule '@highwayhash//:sip_hash':
    this rule is missing dependency declarations for the following files included by 'highwayhash/highwayhash/sip_hash.cc':

  2. ERROR: /Users/integrator/tensorflow/tensorflow/core/lib/jpeg/BUILD:47:11: undeclared inclusion(s) in rule '//tensorflow/core/lib/jpeg:portable_jpeg_internal':
    this rule is missing dependency declarations for the following files included by 'tensorflow/core/lib/jpeg/jpeg_handle.cc':

  3. ERROR:/private/var/tmp/_bazel_integrator/0a793f72f57e57f678a00d6fdcdcda5e/external/com_google_absl/absl/hash/BUILD.bazel:29:11: undeclared inclusion(s) in rule '@com_google_absl//absl/hash:hash':
    this rule is missing dependency declarations for the following files included by 'com_google_absl/absl/hash/internal/hash.cc':

Any other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

@Nizarazo Nizarazo added the type:build/install Build and install issues label Nov 25, 2021
@mohantym mohantym added TF 2.7 Issues related to TF 2.7.0 subtype:macOS macOS Build/Installation issues labels Nov 25, 2021
@mohantym
Copy link
Contributor

Hi @sanatmpa1! Could you please look at this issue?

@mohantym mohantym assigned sanatmpa1 and unassigned mohantym Nov 25, 2021
@Nizarazo
Copy link
Author

@sachinprasadhs any help would be appreciated.
Thanks

@sachinprasadhs
Copy link
Contributor

Could you please post this issue in the dedicated Apple developer forum https://developer.apple.com/forums/

@sachinprasadhs sachinprasadhs added the stat:awaiting response Status - Awaiting response from author label Nov 30, 2021
@Nizarazo
Copy link
Author
Nizarazo commented Dec 1, 2021

Hi @sachinprasadhs

I don't think it is related to apple developer forum since I am talking about reducing tensorflow size using:

  1. optional flags.
  2. selective registration method.

Why do you think it is related to apple developer forum?

Thanks

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Dec 4, 2021
@sachinprasadhs sachinprasadhs added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Dec 14, 2021
@Nizarazo
Copy link
Author

Hi @sachinprasadhs

Can you explain what do you mean by "awaiting tensorflower" status? and is there a real person with user name "learning-to-play" or it is a bot?

Thanks

@sachinprasadhs sachinprasadhs added the type:feature Feature requests label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower subtype:macOS macOS Build/Installation issues TF 2.7 Issues related to TF 2.7.0 type:build/install Build and install issues type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

6 participants