Skip to content

tensorflow contrib modules break when running in a pyc only environment #12466

Closed

Description

@gotyaoi

Please go to Stack Overflow for help and support:

https://stackoverflow.com/questions/tagged/tensorflow

If you open a GitHub issue, here is our policy:

  1. It must be a bug or a feature request.
  2. The form below must be filled out.
  3. It shouldn't be a TensorBoard issue. Those go here.

Here's why we have that policy: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.


System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
    No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
    Amazon Linux 2016.09
  • TensorFlow installed from (source or binary):
    binary, no gpu, virtualenv method
  • TensorFlow version (use command below):
    1.2.1
  • Python version:
    2.7.12
  • Bazel version (if compiling from source):
    N/A
  • CUDA/cuDNN version:
    N/A
  • GPU model and memory:
    N/A
  • Exact command to reproduce:
    python -c "from tensorflow.contrib.layers import fully_connected"

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

Describe the problem

When building a python install for a disk space constrained environment, it's fairly common to first compile all .py files to .pyc files, and then only install the .pyc files, to save a few megabytes of space. When attempting this for tensorflow, it became unable to import it's contrib modules (traceback below). From some testing I did, this appears to be due to differing behavior in this snippet from the get_path_to_datafile function in python/platform/resource_loader.py: data_files_path = _os.path.dirname(_inspect.getfile(_sys._getframe(1)))

when the .py files are present, this snippet produces an absolute path. When only the .pyc files are present, it produces a relative path, which is then concatenated with another path, as the get_path_to_datafile function is called twice.

Source code / logs

File "./tensorflow/contrib/__init__.py", line 27, in <module>
File "./tensorflow/contrib/cudnn_rnn/__init__.py", line 28, in <module>
File "./tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py", line 34, in <module>
File "./tensorflow/contrib/util/loader.py", line 55, in load_op_library
File "./tensorflow/python/framework/load_library.py", line 64, in load_op_library
NotFoundError: ./tensorflow/contrib/util/./tensorflow/contrib/cudnn_rnn/python/ops/_cudnn_rnn_ops.so: cannot open shared object file: No such file or directory

Activity

  1. bignamehyp commented on Nov 7, 2017

    @bignamehyp

    Does this problem still exist at TF 1.4?

  2. added
    stat:awaiting tensorflower
    stat:awaiting response
    and removed
    stat:awaiting tensorflower
    on Nov 7, 2017
  3. gotyaoi commented on Nov 7, 2017

    @gotyaoi
    Author

    The issue still exists in tensorflow 1.4.0. The stack trace looks to have changed slightly, but the error is very similar.

    >>> from tensorflow.contrib.layers import fully_connected
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "./tensorflow/contrib/__init__.py", line 28, in <module>
    
      File "./tensorflow/contrib/cudnn_rnn/__init__.py", line 33, in <module>
    
      File "./tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py", line 21, in <module>
      File "./tensorflow/contrib/rnn/__init__.py", line 83, in <module>
    
      File "./tensorflow/contrib/rnn/python/ops/gru_ops.py", line 33, in <module>
      File "./tensorflow/contrib/util/loader.py", line 55, in load_op_library
      File "./tensorflow/python/framework/load_library.py", line 56, in load_op_library
      File "./tensorflow/python/framework/errors_impl.py", line 473, in __exit__
    tensorflow.python.framework.errors_impl.NotFoundError: ./tensorflow/contrib/util/./tensorflow/contrib/rnn/python/ops/_gru_ops.so: cannot open shared object file: No such file or directory
    
  4. removed
    stat:awaiting response
    on Nov 8, 2017
  5. aselle commented on Nov 29, 2017

    @aselle
    Contributor

    This appears to be because pyc files store the paths relative to where they were generated from. So if you run the python command that generates the pyc from the root directory in an environment with the same root, it will give you full paths and work properly. That being said, it would be great if we could make this work no matter what the relative paths were.

  6. added
    stat:awaiting response
    type:support
    on Nov 29, 2017
  7. aselle commented on Nov 29, 2017

    @aselle
    Contributor

    @annarev, could you look into making getfile() more robust to only pyc environments? I think we have the same issue if you try to put a PYTHONPATH with a relative path specified i.e. ../foo/bar/tensorflow

  8. tensorflowbutler commented on Dec 20, 2017

    @tensorflowbutler
    Member

    It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.

  9. tensorflowbutler commented on Jan 3, 2018

    @tensorflowbutler
    Member

    It has been 14 days with no activity and this issue has an assignee.Please update the label and/or status accordingly.

  10. tensorflowbutler commented on Jan 18, 2018

    @tensorflowbutler
    Member

    Nagging Assignee: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

  11. added a commit that references this issue on Jan 19, 2018
    aa8f737
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stat:awaiting responsetype:support

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions