Skip to content

tensorflow: add tensorflow.keras.activations members#11444

Merged
JelleZijlstra merged 6 commits intopython:mainfrom
hoel-bagard:hoel/add_tf_keras_activations
Mar 1, 2024
Merged

tensorflow: add tensorflow.keras.activations members#11444
JelleZijlstra merged 6 commits intopython:mainfrom
hoel-bagard:hoel/add_tf_keras_activations

Conversation

@hoel-bagard
Copy link
Contributor

No description provided.

@github-actions

This comment has been minimized.

@hoel-bagard hoel-bagard marked this pull request as ready for review February 18, 2024 14:19
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

threshold: FloatTensorCompatible | FloatDataSequence = 0.0,
) -> Tensor: ...
def selu(x: _ActivationInput) -> Tensor: ...
def serialize(activation: Callable[..., Any], use_legacy_format: bool = False) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

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

It can also return a dict:

In [15]: tensorflow.keras.activations.serialize(len)
Out[15]: 
{'module': 'builtins',
 'class_name': 'builtin_function_or_method',
 'config': 'len',
 'registered_name': 'builtin_function_or_method'}

In [16]: tensorflow.keras.activations.serialize(lambda: 42)
/Users/jelle/py/venvs/py311/lib/python3.11/site-packages/keras/src/activations.py:549: UserWarning: The object being serialized includes a `lambda`. This is unsafe. In order to reload the object, you will have to pass `safe_mode=False` to the loading function. Please avoid using `lambda` in the future, and use named Python functions instead. This is the `lambda` being serialized: tensorflow.keras.activations.serialize(lambda: 42)

  fn_config = serialization_lib.serialize_keras_object(activation)
Out[16]: 
{'value': ('4wAAAAAAAAAAAAAAAAEAAAADAAAA8wYAAACXAGQBUwApAk7pKgAAAKkAcgMAAADzAAAAAPofPGlw\neXRob24taW5wdXQtMTYtYjFiYzU1YjgzOGViPvoIPGxhbWJkYT5yBgAAAAEAAABzBgAAAIAAqHKA\nAHIEAAAA\n',
  None,
  None)}

In [17]: tensorflow.keras.activations.serialize(os.path.exists)
Out[17]: 
{'module': 'builtins',
 'class_name': 'function',
 'config': 'exists',
 'registered_name': 'function'}

Copy link
Contributor Author

@hoel-bagard hoel-bagard Feb 29, 2024

Choose a reason for hiding this comment

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

@JelleZijlstra Thanks for pointing it out, I've fixed it in d25b89f. Do you have a method / tool to find this kind of errors ?
For this particular function, looking at the source code would have made it clear that the return type could be a dict. Is it how you found out about it ?

When doing the TensorFlow stubs, I usually try a few inputs, but I can't test everything, so I often rely on what the docs say 😞

Copy link
Member

Choose a reason for hiding this comment

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

Just by trying it out. I didn't do that for all functions, I think at first I was mostly curious what this function would do with a builtin.

@github-actions

This comment has been minimized.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit ea2002d into python:main Mar 1, 2024
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.

3 participants