Skip to content

tf.contrib.lookup.HashTable(kv_initializer) does not work in eager mode. #16160

Closed

Description

@xiaoyunwu

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.


== cat /etc/issue ===============================================
Darwin Xiaoyuns-MBP 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
Mac OS X 10.11.4

== are we in docker =============================================
No

== compiler =====================================================
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

== uname -a =====================================================
Darwin Xiaoyuns-MBP 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

== check pips ===================================================
numpy (1.11.2)
protobuf (3.4.0)

== check for virtualenv =========================================
False

== tensorflow import ============================================
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named tensorflow

== env ==========================================================
LD_LIBRARY_PATH is unset
DYLD_LIBRARY_PATH /usr/local/cuda/lib:/usr/local/cuda/lib:

== nvidia-smi ===================================================
/Users/xiaoyun/tf14py3/bin/tf_env_collect.sh: line 105: nvidia-smi: command not found

== cuda libs  ===================================================

== cat /etc/issue ===============================================
Darwin Xiaoyuns-MBP 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
Mac OS X 10.11.4

== are we in docker =============================================
No

== compiler =====================================================
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

== uname -a =====================================================
Darwin Xiaoyuns-MBP 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

== check pips ===================================================
numpy (1.11.2)
protobuf (3.4.0)

== check for virtualenv =========================================
False

== tensorflow import ============================================
tf.VERSION = 1.5.0-rc1
tf.GIT_VERSION = v1.5.0-rc0-9-gf9472619f6
tf.COMPILER_VERSION = v1.5.0-rc0-9-gf9472619f6
Sanity check: array([1], dtype=int32)

== env ==========================================================
LD_LIBRARY_PATH is unset
DYLD_LIBRARY_PATH /usr/local/cuda/lib:/usr/local/cuda/lib:

== nvidia-smi ===================================================
/Users/xiaoyun/tf14py3/bin/tf_env_collect.sh: line 105: nvidia-smi: command not found

== cuda libs  ===================================================

System information

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

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)"
v1.5.0-rc0-9-gf9472619f6 1.5.0-rc1

Describe the problem

Can not use hashtable in eager mode.

Source code / logs

import tensorflow as tf
import tensorflow.contrib.eager as tfe

tfe.enable_eager_execution()

keyfile = "./key_dict"
kv_initializer = tf.contrib.lookup.TextFileInitializer(
    keyfile, tf.string, 0, tf.int64, 1, delimiter="\t")
table = tf.contrib.lookup.HashTable(kv_initializer, 0)
table.init.run()

filenames = ["./data1"]
dataset = tf.data.TextLineDataset(filenames)
#dataset = dataset.map(lambda tkns:table.lookup(tkns))
for x in tfe.Iterator(dataset):
    print(x)

Traceback (most recent call last):
  File "torch/textline.py", line 13, in <module>
    table = tf.contrib.lookup.HashTable(kv_initializer, 0)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/lookup_ops.py", line 282, in __init__
    super(HashTable, self).__init__(table_ref, default_value, initializer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/lookup_ops.py", line 168, in __init__
    self._init = initializer.initialize(self)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/lookup_ops.py", line 531, in initialize
    if constant_op.is_constant(filename):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 224, in is_constant
    op = tensor_or_op.op
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 825, in op
    raise AttributeError("op not supported for Eager Tensors.")
AttributeError: op not supported for Eager Tensors.

Activity

  1. aselle commented on Jan 16, 2018

    @aselle
    Contributor

    @alextp, please comment/take a look.

  2. added
    stat:awaiting response
    stat:awaiting tensorflower
    comp:eager
    and removed
    stat:awaiting response
    on Jan 16, 2018
  3. added a commit that references this issue on Jan 17, 2018
    0830cee
  4. xiaoyunwu commented on Jan 18, 2018

    @xiaoyunwu
    Author

    thanks for the fix. But now

    File "torch/textline.py", line 16, in <module>
        table.init.run()
    AttributeError: 'NoneType' object has no attribute 'run'
    

    And if I comment this out,

    dataset = dataset.map(lambda tkns:table.lookup(tkns))
    

    give this:

    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
        preferred_dtype=default_dtype)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
        ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 100, in _convert_to_graph_tensor
        return constant_op.constant(value.numpy())
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 677, in numpy
        raise ValueError("Resource handles are not convertible to numpy.")
    ValueError: Resource handles are not convertible to numpy.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 524, in _apply_op_helper
        values, as_ref=input_arg.is_ref).dtype.name
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1022, in internal_convert_to_tensor
        ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/eager/function.py", line 100, in _convert_to_graph_tensor
        return constant_op.constant(value.numpy())
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 677, in numpy
        raise ValueError("Resource handles are not convertible to numpy.")
    ValueError: Resource handles are not convertible to numpy.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "torch/textline.py", line 39, in <module>
        dataset = dataset.map(lambda tkns:table.lookup(tkns))
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 780, in map
        return MapDataset(self, map_func)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1591, in __init__
        self._map_func.add_to_graph(ops.get_default_graph())
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 486, in add_to_graph
        self._create_definition_if_needed()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 321, in _create_definition_if_needed
        self._create_definition_if_needed_impl()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/function.py", line 338, in _create_definition_if_needed_impl
        outputs = self._func(*inputs)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1556, in tf_map_func
        ret = map_func(nested_args)
      File "torch/textline.py", line 39, in <lambda>
        dataset = dataset.map(lambda tkns:table.lookup(tkns))
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/lookup_ops.py", line 229, in lookup
        self._table_ref, key_tensor, self._default_value, name=scope)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/gen_lookup_ops.py", line 457, in _lookup_table_find_v2
        default_value=default_value, name=name)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 528, in _apply_op_helper
        (input_name, err))
    ValueError: Tried to convert 'table_handle' to a tensor and failed. Error: Resource handles are not convertible to numpy.
    
  5. alextp commented on Jan 18, 2018

    @alextp
    Contributor
  6. xiaoyunwu commented on Jan 19, 2018

    @xiaoyunwu
    Author

    it is the same code that still failing... I do not get the reason for file another issue.

  7. alextp commented on Jan 19, 2018

    @alextp
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp:eagerstat:awaiting tensorflowertype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions