tensor2tensor
tensor2tensor copied to clipboard
module 'tensorflow' has no attribute 'to_float'
Description
TensorFlow 2.0 has no attribute to_float
.
Environment information
OS: Windows 10 Home Edition
$ pip freeze | grep tensor
mesh-tensorflow==0.1.4
tensor2tensor==1.14.1
tensorboard==2.0.1
tensorflow==2.0.0
tensorflow-datasets==1.3.0
tensorflow-estimator==2.0.1
tensorflow-gan==2.0.0
tensorflow-hub==0.7.0
tensorflow-metadata==0.15.0
tensorflow-probability==0.7.0
$ python -V
Python 3.7.5
For bugs: reproduction and error logs
# Steps to reproduce:
$ conda create -n test python=3.7
$ conda activate test
$ pip install tensor2tensor[tensorflow]
$ python -c "from tensor2tensor.models.transformer import Transformer"
# Error logs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\me\Anaconda3\envs\nlp\lib\site-packages\tensor2tensor\models\__init__.py", line 25, in <module>
from tensor2tensor.layers import modalities # pylint: disable=g-import-not-at-top
File "C:\Users\me\Anaconda3\envs\nlp\lib\site-packages\tensor2tensor\layers\modalities.py", line 28, in <module>
from tensor2tensor.layers import common_attention
File "C:\Users\me\Anaconda3\envs\nlp\lib\site-packages\tensor2tensor\layers\common_attention.py", line 954, in <module>
def attention_bias_to_padding(attention_bias, cast_fn=tf.to_float):
AttributeError: module 'tensorflow' has no attribute 'to_float'
I am new to tensorflow and just wanted to get started with some of the models. I also ran into this issue with the 'Quickstart' problem in the tensor2tensor documentation. Briefly switching back to tensorflow 1.15 has allowed me to get around this error for now so i can at least get to grips with the core functionality - keen to find a solution to allow tf2.0 if anyone has any ideas
You need to change tf.to_float call to tf.cast(..., dtype=tf.float32)
I tried the above solution: I get the following error
ValueError Traceback (most recent call last)
9 frames
/usr/local/lib/python3.7/dist-packages/tensor2tensor/problems.py in
/usr/local/lib/python3.7/dist-packages/tensor2tensor/data_generators/all_problems.py in import_modules(modules) 138 for module in modules: 139 try: --> 140 importlib.import_module(module) 141 except ImportError as error: 142 errors.append((module, error))
/usr/lib/python3.7/importlib/init.py in import_module(name, package) 125 break 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level) 128 129
/usr/local/lib/python3.7/dist-packages/tensor2tensor/data_generators/algorithmic.py in
/usr/local/lib/python3.7/dist-packages/tensor2tensor/data_generators/problem.py in
/usr/local/lib/python3.7/dist-packages/tensor2tensor/utils/metrics.py in
/usr/local/lib/python3.7/dist-packages/tensor2tensor/layers/modalities.py in
/usr/local/lib/python3.7/dist-packages/tensor2tensor/layers/common_attention.py in
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs) 151 except Exception as e: 152 filtered_tb = _process_traceback_frames(e.traceback) --> 153 raise e.with_traceback(filtered_tb) from None 154 finally: 155 del filtered_tb
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype) 100 dtype = dtypes.as_dtype(dtype).as_datatype_enum 101 ctx.ensure_initialized() --> 102 return ops.EagerTensor(value, ctx.device_name, dtype) 103 104
ValueError: Attempt to convert a value (Ellipsis) with an unsupported type (<class 'ellipsis'>) to a Tensor.