-
Notifications
You must be signed in to change notification settings - Fork 337
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
olivas
wants to merge
3
commits into
tensorflow:master
Choose a base branch
from
olivas:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
hasattr doesn't detect the numpy method.
olivas
commented
May 13, 2024
There was a problem hiding this 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.