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

Link error for libtensorflow_cc.so when using LoadSavedModel #40004

Closed
dgel opened this issue May 29, 2020 · 13 comments
Closed

Link error for libtensorflow_cc.so when using LoadSavedModel #40004

dgel opened this issue May 29, 2020 · 13 comments
Assignees
Labels
comp:ops OPs related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author TF 2.2 Issues related to TF 2.2 type:bug Bug

Comments

@dgel
Copy link

dgel commented May 29, 2020

The version scripts don't export any symbols from protobuf. This is fine as long as basic functionality doesn't use symbols from protobuf, but LoadSavedModel seems to me to be a part of the basic functionality of tensorflow. Adding *google*protobuf* to the version scripts fixes the issue, as would hiding the protobuf data from the interface

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): 2.2.0
  • Python version: n/a
  • Bazel version (if compiling from source): 2.0.0
  • GCC/Compiler version (if compiling from source): GCC 7.5.0
  • CUDA/cuDNN version: CUDA 10.1, cuDNN 7.6.3
  • GPU model and memory: n/a

Describe the current behavior
When using the LoadSavedModel function from c++ and linking against tensorflow_cc.so, a link error appears saying undefined reference to 'google::protobuf::internal::MapFieldBase::SyncMapWithRepeatedField() const'

Describe the expected behavior
The program links and runs without issues

Standalone code to reproduce the issue
Any c++ program using LoadSavedModel and linking libtensorflow_cc.so will do

@dgel dgel added the type:bug Bug label May 29, 2020
@ravikyram ravikyram added subtype: ubuntu/linux Ubuntu/Linux Build/Installation Issues type:build/install Build and install issues and removed type:bug Bug labels Jun 1, 2020
@ravikyram
Copy link
Contributor

@dgel

Can you go through the link1,link2,link3 and see if it helps you.Thanks!

@ravikyram ravikyram added the stat:awaiting response Status - Awaiting response from author label Jun 1, 2020
@dgel
Copy link
Author

dgel commented Jun 1, 2020

Hi @ravikyram

It seems links 1 and 3 are about building tensorflow_cc.so itself. I'm having no issues building the tensorflow library, just with linking against it, so I'll discard those.

If I understand correctly from link 2, any any code that calls some tensorflow API that uses parts of protobuf needs to additionally link against libtensorflow_framework.so? Why is this done instead of just exporting the protobuf symbols from libtensorflow_cc.so directly? I haven't built libtensorflow_framework yet, so I'll try that and see how it goes

I just realised, I built tensorflow_cc with the commandline bazel build --config=opt --config=monolithic tensorflow:libtensorflow_cc.so tensorflow:install_headers. If I recall correctly, the monolithic config already includes libtensorflow_cc.so inside the binary, so the advice from link 2 does not apply

@ravikyram ravikyram added TF 2.2 Issues related to TF 2.2 and removed stat:awaiting response Status - Awaiting response from author labels Jun 2, 2020
@ravikyram ravikyram assigned ymodak and unassigned ravikyram Jun 2, 2020
@ymodak ymodak added comp:ops OPs related issues type:bug Bug and removed subtype: ubuntu/linux Ubuntu/Linux Build/Installation Issues type:build/install Build and install issues labels Jun 4, 2020
@ymodak ymodak assigned aselle and unassigned ymodak Jun 8, 2020
@dgel
Copy link
Author

dgel commented Jun 10, 2020

To supplement the information I already put here, I continued developing my program after having exported the protobuf symbols from libtensorflow_cc.so. However, I ran into a version issue where another dependency used a different version of protobuf.

I understand that such are not really concerns of tensorflow, and just exporting the symbols is the simpler option, but an ideal solution for me would be to make sure the header "tensorflow/cc/saved_model/loader.h" does not depend on protobuf symbols. Or more likely, implement an alternative interface that does not use protobuf::Map and an implementation similar to SavedModelBundleLite

@xiandong79
Copy link

@dgel could you have a look on #44899

@dhgelling
Copy link

@xiandong79 That is exactly the error I reported here, perhaps mark it duplicate and close? No need to open multiple issues for the same problem

@xiandong79
Copy link

xiandong79 commented Nov 16, 2020

@dhgelling Sure, I have closed it. #44899

do you have solutions to overcome/bypass the error?

@dhgelling
Copy link

dhgelling commented Nov 16, 2020

yes, expanding on the solution I mentioned when reporting the issue, before building / linking libtensorflow_cc.so, add *google*protobuf* to the version scripts (that's tensorflow/tf_version_script.lds for linux and tensorflow/tf_exported_symbols.lds for mac)

@xiandong79
Copy link

xiandong79 commented Nov 17, 2020

add *google*protobuf*; into tensorflow/tf_version_script.lds

ubuntu@ip-172-31-14-28:~$ cat /home/ubuntu/tensorflow_cc/tensorflow_cc/build/tensorflow/tensorflow/tf_version_script.lds
tensorflow {
  global:
    *tensorflow*;
    *absl*kSeed*;
    *toco*;
    *google*protobuf*;
    *perftools*gputools*;
    *tf_*;
    *TF_*;
    *Eager*;
    *TFE_*;
    *nsync_*;
    *stream_executor*;
    *xla*;
    *PyInit_*;
  local:
    *;
};

As I use FloopCZ /tensorflow_cc

(re-)Build and (re-)install the library

cd /home/ubuntu/tensorflow_cc/tensorflow_cc/build
cmake ..
make
sudo make install

however, it does not work yet. @dhgelling should I do other modification?
I will try FloopCZ/tensorflow_cc#219 this solution for now.

@dhgelling
Copy link

I mean if that solution works then go with that, no? The reason my solution doesn't work with FloopCZ/tensorflow_cc is that the resulting make script will download all the sources needed, and overwrite any changes we make. I 'solved' this by running make, waiting for bazel to start compiling, then interrupt with ctrl+c, then edit the version script and running make again.

Another option would be to just make the changes in a branch of tensorflow and make FloopCZ/tensorflow_cc use that branch instead. Also, it's possible that you won't need the fix at all if you use SavedModelBundleLite instead of SavedModelBundle

@sushreebarsa
Copy link
Contributor

@dgel
It looks like you are using an older Version of Tensorflow. Many bugs have been fixed in the latest version. Can you please try using Latest Version 2.7.0 and let us know if it helps? Thanks!

@sushreebarsa sushreebarsa self-assigned this Dec 13, 2021
@sushreebarsa sushreebarsa added the stat:awaiting response Status - Awaiting response from author label Dec 13, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler google-ml-butler bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Dec 20, 2021
@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author TF 2.2 Issues related to TF 2.2 type:bug Bug
Projects
None yet
Development

No branches or pull requests

7 participants