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

Can't infer Python side-effects for tf.keras.Models with implicit callables #291

Open
khatchad opened this issue Nov 30, 2023 · 1 comment
Labels
blocked bug Something isn't working worked around

Comments

@khatchad
Copy link
Member

Consider the following model:

class SequentialModel(tf.keras.Model):
def __init__(self, **kwargs):
super(SequentialModel, self).__init__(**kwargs)
self.flatten = tf.keras.layers.Flatten(input_shape=(28, 28))
# Add a lot of small layers
num_layers = 100
self.my_layers = [tf.keras.layers.Dense(64, activation="relu")
for n in range(num_layers)]
self.dropout = tf.keras.layers.Dropout(0.2)
self.dense_2 = tf.keras.layers.Dense(10)
def call(self, x):
x = self.flatten(x)
for layer in self.my_layers:
x = layer(x)
x = self.dropout(x)
x = self.dense_2(x)
return x

And the following client code:

This code implicitly calls SequentialModel.call() because Model's __call__() method calls Model.call() and SequentialModel overrides call().

@khatchad
Copy link
Member Author

Blocked on wala/ML#106.

khatchad added a commit that referenced this issue Dec 6, 2023
@khatchad khatchad added worked around bug Something isn't working labels Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked bug Something isn't working worked around
Projects
None yet
Development

No branches or pull requests

1 participant