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

WARNING:absl:Found untraced functions such as [...] #16469

Closed
mhorlacher opened this issue Apr 27, 2022 · 17 comments
Closed

WARNING:absl:Found untraced functions such as [...] #16469

mhorlacher opened this issue Apr 27, 2022 · 17 comments

Comments

@mhorlacher
Copy link

I run into the above warning when saving sub-classed models with model.save().

After some investigation, the error seems to occur when using sub-classed layers in combination with sub-classed models.

See the code below for a minimal example:

import tensorflow as tf

class CustomLayer(tf.keras.layers.Layer):
    def __init__(self, units=2):
        super(CustomLayer, self).__init__()

        self.units = units

        self.layer = tf.keras.layers.Dense(units)

    def get_config(self):
        config = super(CustomLayer, self).get_config()
        config['units'] = self.units

        return config

    def call(self, x, **kwargs):
        x = self.layer(x)
        return x


class CustomModel(tf.keras.Model):
    def __init__(self, hidden_units):
        super(CustomModel, self).__init__()
        self.hidden_units = hidden_units
        self.dense_layers = [CustomLayer(u) for u in hidden_units]

    def call(self, inputs):
        x = inputs
        for layer in self.dense_layers:
            x = layer(x)
        return x

    def get_config(self):
        return {"hidden_units": self.hidden_units}

    @classmethod
    def from_config(cls, config):
        return cls(**config)


model = CustomModel([16, 16, 10])
print(model(tf.random.uniform((1, 5))).shape)
model.compile()
model.save("my_model", )
print('---')
loaded_model = tf.keras.models.load_model('my_model')

Or check out this gist.

My TF version is 2.8.0.

@mhorlacher
Copy link
Author

mhorlacher commented Apr 27, 2022

This issue has also been discussed here: tensorflow/models#10562

@saberkun
Copy link
Contributor

@qlzh727

@qlzh727
Copy link
Member

qlzh727 commented Apr 27, 2022

@k-w-w for saving related question.

@qlzh727
Copy link
Member

qlzh727 commented Apr 27, 2022

Also the warnings a bit weird that it contains layer name like dense_4_layer_call_fn, whereas there are only 3 layers in the model. It seems that there are duplicated tf.functions being created and somehow discarded.

@mhorlacher
Copy link
Author

@qlzh727 Do you observe this after re-starting the runtime? The exact warning I get is:

WARNING:absl:Found untraced functions such as dense_layer_call_fn, dense_layer_call_and_return_conditional_losses, dense_1_layer_call_fn, dense_1_layer_call_and_return_conditional_losses, dense_2_layer_call_fn while saving (showing 5 of 6). These functions will not be directly callable after loading.

Which makes sense IMO, as the model has 3 dense layers.

@gadagashwini
Copy link
Contributor

I could able to reproduce the issue, please take a look at gist.
Similar issue opened on Tensorflow repo #47554. Thanks!

@gadagashwini gadagashwini added the keras-team-review-pending Pending review by a Keras team member. label May 2, 2022
@hertschuh hertschuh removed the keras-team-review-pending Pending review by a Keras team member. label May 5, 2022
@mhorlacher
Copy link
Author

Any updates on this?

@jenabesaman
Copy link

I have same issue and when I load the saved model then my predicts become randomly or uncorrected
I search for this issue hole the web but I didn't get any answer

@mhorlacher
Copy link
Author

@jenabesaman This warning can probably be ignored, as it appears even in guides on the official Tensorflow website, e.g. https://www.tensorflow.org/text/tutorials/text_generation. Still, it would be great if someone could have a closer look at this.

@juemrami
Copy link

juemrami commented Dec 10, 2022

Anyway to suppress the warning then. I'm seeing it every time Keras saves a model at a checkpoint during training. rather annoying

@mhorlacher
Copy link
Author

@juemrami Try something like this, to turn of absl-related warning messages.

# Disable absl INFO and WARNING log messages
from absl import logging as absl_logging
absl_logging.set_verbosity(absl_logging.ERROR)

@SuryanarayanaY
Copy link
Collaborator

Hi @mhorlacher ,
The warnings that you are getting can be safely ignored.AFAIK It should not be problem if the saved model reloads without error.Please find the attached gist where reloading does not change Model architecture or Parameters.

You can also find such warning in Tensorflow text Tutorial which are safely ignored.You can refer groups.google and SO also which supports Ignoring this warning.You can also disable the warnings as mentioned in the above comment.

Thank you!

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@BukenyaLukman
Copy link

I am getting the same issue here. Tensorflow 3+

@JuLieAlgebra
Copy link

Same, tensorflow 3.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests