Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upLayerNormalization fails when given tuple as axis input #32311
Comments
This comment has been minimized.
This comment has been minimized.
The same code appears in Tensorflow 2 as well: if isinstance(axis, (list, tuple)):
self.axis = axis[:] # Convert axis to list and resolve negatives
if isinstance(self.axis, int):
self.axis = [self.axis] |
This comment has been minimized.
This comment has been minimized.
What is the convention? Some functions accept tuples, lists and ints for the axis argument. Others only accept lists and integers. |
This comment has been minimized.
This comment has been minimized.
I can reproduce the issue even with Please check the gist with 1.15.0rc0`. Thanks! |
This comment has been minimized.
This comment has been minimized.
Should I submit a pull request with the fix? |
This comment has been minimized.
This comment has been minimized.
Please feel free to create a fix and tag me. |
This comment has been minimized.
This comment has been minimized.
@robieta I did post a fix in the original post. I didn't create a pull request because I am not sure what the convention is. Some functions in tensorflow accept tuples, lists and ints as axis while others only accept list and ints for axis. Fix is simple, replace the lines: # Convert axis to list and resolve negatives
if isinstance(self.axis, int):
self.axis = [self.axis]
elif isinstance(self.axis, tuple):
self.axis = list(axis) |
This comment has been minimized.
This comment has been minimized.
@robieta Also note that the same code is present in tensorflow 2. Maybe tag the issue as tf2 as well. |
This comment has been minimized.
This comment has been minimized.
I think the fix you proposed is reasonable. Particularly for higher level symbols like Layers we try to be fairly permissive as long as it's unambiguous what the user wants. (Which in this case it is.) |
Previously the code only handled ints and lists as axis. Gave an error `TypeError: 'tuple' object does not support item assignment` when giving tuple as axis argument. See this issue tensorflow#32311
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@robieta So the pull request got merged into version 1.14, but the same code is present in r2.0. |
This comment has been minimized.
This comment has been minimized.
I don't think this warrants a cherrypick given how far along the 2.0 RC process is. It will automatically be picked up in 2.1. |
This comment has been minimized.
This comment has been minimized.
Closing issue since pull request fixing it has been merged in v1.14 |
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
You can collect some of this information using our environment capture
script
You can also obtain the TensorFlow version with: 1. TF 1.0:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
2. TF 2.0:python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"
Describe the current behavior
fails with error
This is because the lines:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/layers/normalization.py#L929-L930
make a copy of the tuple instead of converting it to a list and later the lines:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/layers/normalization.py#L954-L956
do not take care of the case when axis is a tuple.
Describe the expected behavior
Fix is simple, replace the lines:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/layers/normalization.py#L954-L956
with:
Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.
Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.