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

Fix for transformer failure in dtype conversion #1272

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olivas
Copy link

@olivas olivas commented May 13, 2024

The current version of this example fails out of the box because no where is the scalar tensor converted to an integer, where the dtype can be inferred in keras.

In the latest version of tensorflow, this example fails, because vocab_size is a scalar tensor (type EagerTensor) and keras can't determine the dtype.  The failure occurs pretty deep in the call stack, so it's best to determine as early as possible whether that type conversion is going to succeed or not.

Python3.10
TensorFlow 2.16.1

Attached is the relevant part of the traceback:
  File "/home/olivas/qaintum.ai/./transformer.py", line 404, in call
    x = self.embedding(x)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 113, in error_handler
    return fn(*args, **kwargs)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/layers/layer.py", line 771, in __call__
    self._maybe_build(call_spec)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/layers/layer.py", line 1279, in _maybe_build
    self.build(**shapes_dict)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/layers/layer.py", line 223, in build_wrapper
    original_build_method(*args, **kwargs)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/layers/core/embedding.py", line 124, in build
    self._embeddings = self.add_weight(
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/layers/layer.py", line 511, in add_weight
    variable = backend.Variable(
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/backend/common/variables.py", line 161, in __init__
    shape = self._validate_shape(shape)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/backend/common/variables.py", line 184, in _validate_shape
    shape = standardize_shape(shape)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/backend/common/variables.py", line 549, in standardize_shape
    if not is_int_dtype(type(e)):
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/backend/common/variables.py", line 580, in is_int_dtype
    dtype = standardize_dtype(dtype)
  File "/home/olivas/qaintum.ai/venv/lib/python3.10/site-packages/keras/src/backend/common/variables.py", line 521, in standardize_dtype
    raise ValueError(f"Invalid dtype: {dtype}")
ValueError: Invalid dtype: <property object at 0x7f6c0c458d10>
Exception ignored in: <function AtomicFunction.__del__ at 0x7f6c0b4dbc70>
…ding-patch

Fix transformer.ipynb failure in dtype determination
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

hasattr doesn't detect the numpy method.
Copy link
Author

@olivas olivas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine yet better implementations, but this should be enough to illustrate the problem.

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

Successfully merging this pull request may close these issues.

None yet

1 participant