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

tfa.text.parse_time fails with has no attribute 'addons_parse_time' #2805

Open
sshcherbakov opened this issue Feb 4, 2023 · 0 comments
Open

Comments

@sshcherbakov
Copy link

sshcherbakov commented Feb 4, 2023

System information

  • OS Platform and Distribution: MacOS 12.6.2 (also tried in Ubuntu 20.04)
  • TensorFlow version and how it was installed: 2.11.0 (Miniconda3, tried with penv pip)
  • TensorFlow-Addons version and how it was installed: 0.19.0 (Miniconda3, tried with penv pip)
  • Python version: 3.9.1 (tried with 3.10.8)
  • Is GPU used? (yes/no): no

Describe the bug

The following code:

import tensorflow as tf
import tensorflow_addons as tfa
import numpy as np
from importlib import reload

file_path = 'input.csv'
dataset = tf.data.TextLineDataset(file_path).skip(1)

def parse_csv_line(line):
  fields = tf.io.decode_csv(line, record_defaults=[[""]] * 4)
  timestamp   = tfa.text.parse_time(fields[0], '%Y-%m-%dT%H:%M:%SZ', 'MILLISECOND')
  f1        = tf.strings.to_number(fields[1], tf.float32)  
  return {"timestamp": timestamp, "f1": f1}

dataset = dataset.map(parse_csv_line).batch(5)

Sample input.csv:

2013-09-11T00:33:54Z,99.9
2013-09-16T21:36:36Z,90.0
2013-09-17T15:09:14Z,95.0
2013-09-24T10:20:49Z,90.25
2013-10-01T19:59:40Z,96.0
2013-10-02T02:03:07Z,96.0
2013-10-02T13:41:21Z,93.5

always fails with

WARNING:tensorflow:AutoGraph could not transform <function parse_csv_line at 0x7fe12f5deb90> and will run it as-is.
Cause: Unable to locate the source code of <function parse_csv_line at 0x7fe12f5deb90>. Note that functions defined in certain environments, like the interactive Python shell, do not expose their source code. If that is the case, you should define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.experimental.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING: AutoGraph could not transform <function parse_csv_line at 0x7fe12f5deb90> and will run it as-is.
Cause: Unable to locate the source code of <function parse_csv_line at 0x7fe12f5deb90>. Note that functions defined in certain environments, like the interactive Python shell, do not expose their source code. If that is the case, you should define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.experimental.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
Traceback (most recent call last):
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/parser.py", line 148, in parse_entity
    original_source = inspect_utils.getimmediatesource(entity)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/inspect_utils.py", line 124, in getimmediatesource
    lines, lnum = inspect.findsource(obj)
  File "/Users/sergey/miniconda3/lib/python3.10/inspect.py", line 958, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 427, in converted_call
    converted_f = _convert_actual(target_entity, program_ctx)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 269, in _convert_actual
    transformed, module, source_map = _TRANSPILER.transform(entity, program_ctx)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/transpiler.py", line 282, in transform
    return self.transform_function(obj, user_context)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/transpiler.py", line 466, in transform_function
    nodes, ctx = super(PyToPy, self).transform_function(fn, user_context)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/transpiler.py", line 342, in transform_function
    node, source = parser.parse_entity(fn, future_features=future_features)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/parser.py", line 150, in parse_entity
    raise errors.InaccessibleSourceCodeError(
tensorflow.python.autograph.pyct.errors.InaccessibleSourceCodeError: Unable to locate the source code of <function parse_csv_line at 0x7fe12f5deb90>. Note that functions defined in certain environments, like the interactive Python shell, do not expose their source code. If that is the case, you should define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.experimental.do_not_convert. Original error: could not get source code

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 2294, in map
    return MapDataset(self, map_func, preserve_cardinality=True, name=name)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 5499, in __init__
    self._map_func = structured_function.StructuredFunctionWrapper(
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/data/ops/structured_function.py", line 263, in __init__
    self._function = fn_factory()
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 226, in get_concrete_function
    concrete_function = self._get_concrete_function_garbage_collected(
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 192, in _get_concrete_function_garbage_collected
    concrete_function, _ = self._maybe_define_concrete_function(args, kwargs)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 157, in _maybe_define_concrete_function
    return self._maybe_define_function(args, kwargs)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 360, in _maybe_define_function
    concrete_function = self._create_concrete_function(args, kwargs)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py", line 284, in _create_concrete_function
    func_graph_module.func_graph_from_py_func(
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/framework/func_graph.py", line 1283, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/data/ops/structured_function.py", line 240, in wrapped_fn
    ret = wrapper_helper(*args)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/data/ops/structured_function.py", line 171, in wrapper_helper
    ret = autograph.tf_convert(self._func, ag_ctx)(*nested_args)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 689, in wrapper
    return converted_call(f, args, kwargs, options=options)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 434, in converted_call
    return _fall_back_unconverted(f, args, kwargs, options, e)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 484, in _fall_back_unconverted
    return _call_unconverted(f, args, kwargs, options)
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow/python/autograph/impl/api.py", line 458, in _call_unconverted
    return f(*args, **kwargs)
  File "<stdin>", line 5, in parse_csv_line
  File "/Users/sergey/miniconda3/lib/python3.10/site-packages/tensorflow_addons/text/parse_time_op.py", line 86, in parse_time
    return _parse_time_so.ops.addons_parse_time(time_string, time_format, output_unit)
AttributeError: module '012ff3e36e3c24aefc4a3a7b68a03fedd1e7a7e1' has no attribute 'addons_parse_time'

I've tried multiple combinations on multiple OSes and environments, including IDE, command line, interactive and non-interactive execution. The result is always the same.

The combination of the Python, TensorFlow and TensorFlow Addons seems to be fully supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant