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 passing of keyword args to Dense layers in create_tower #339

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

b4russell
Copy link

@b4russell b4russell commented Dec 8, 2022

Current behavior: kwargs are passed to tf.keras.Sequential.add, so they are not passed on to tf.keras.layers.Dense as intended. For example, when passing use_bias=False to create_tower with the kwarg name kernel_regularizer, it throws an exception:

Traceback (most recent call last):
  File "/Users/brussell/development/ranking/tensorflow_ranking/python/keras/layers_test.py", line 33, in test_create_tower_with_kwargs
    tower = layers.create_tower([3, 2, 1], 1, activation='relu', use_bias=False)
  File "/Users/brussell/development/ranking/tensorflow_ranking/python/keras/layers.py", line 70, in create_tower
    model.add(tf.keras.layers.Dense(units=layer_width), **kwargs)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/tensorflow/python/trackable/base.py", line 205, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 61, in error_handler
    return fn(*args, **kwargs)
TypeError: add() got an unexpected keyword argument 'use_bias' test_create_tower_with_kwargs

Fix: This PR fixes the behavior by shifting the closing paren of tf.keras.layers.Dense to the correct location.

@google-cla
Copy link

google-cla bot commented Dec 8, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@b4russell b4russell closed this Dec 8, 2022
@b4russell b4russell reopened this Dec 8, 2022
Current behavior: kwargs are passed to tf.keras.Sequential.add, so they
are not passed on to tf.keras.layers.Dense as intended. For example,
when passing `use_bias=False` to create_tower with the kwarg name
`kernel_regularizer`, it throws an exception:

Traceback (most recent call last):
  File "/Users/brussell/development/ranking/tensorflow_ranking/python/keras/layers_test.py", line 33, in test_create_tower_with_kwargs
    tower = layers.create_tower([3, 2, 1], 1, activation='relu', use_bias=False)
  File "/Users/brussell/development/ranking/tensorflow_ranking/python/keras/layers.py", line 70, in create_tower
    model.add(tf.keras.layers.Dense(units=layer_width), **kwargs)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/tensorflow/python/trackable/base.py", line 205, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/usr/local/anaconda3/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 61, in error_handler
    return fn(*args, **kwargs)
TypeError: add() got an unexpected keyword argument 'use_bias'
test_create_tower_with_kwargs

Fix: This PR fixes the behavior by shifting the closing paren of
tf.keras.layers.Dense to the correct location.
@b4russell
Copy link
Author

Hi! I want to follow up on this PR, which has been open for a year. Are you interested in fixing this behavior or should I close the PR? Tagging @lyyanlely , since you incorporated my colleague @JackGammack PR recently.

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