tensorflow / addons

Useful extra functionality for TensorFlow 2.x maintained by SIG-addons
Apache License 2.0
1.69k stars 611 forks source link

Avoid using lambda functions as default values for class __init__ #2773

Closed pbk0 closed 2 years ago

pbk0 commented 2 years ago

Describe the bug

Please avoid have default values as lambda function. They cause issues with serialization and pickling. Also theses instances cannot be used with asyncio. Note that the tensorflow classes do not have this issues and they can safely used with asyncio.

Instead of using lambda as defaults have them as global functions.

Code to reproduce the issue

Please check the code here Line 238 and Line 312

The scale_fn is lambda function. Can you please define them as global function. Defining it like this creates local functions and thus breaks serialization.

bhack commented 2 years ago

Can you contribute a failing serialization test PR for your case?

We have already other serialization tests in the repo.

pbk0 commented 2 years ago

I am closing this issue. The problem is on my side. I was caching some non serializable items from tfa in my wrapper class.