-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Sequentials _maybe_rebuild
does not make sense
#19916
Comments
@DLumi is the issue that certain layers won't get rebuilt without the If you have a colab showing the actual issue this causes, that would help us! |
@mattdangerw yes, you got it. The model will not be rebuilt on |
This might be expected. Thinking about the simple case. class CustomSequential(...):
__init__():
...
self.add(Dense(10))
self.add(Dense(10))
self.add(Dense(10)) In this case, we have no idea what the input shape is. So we can't build yet. I think this is how it's supposed to work.
But if we really don't know the input shape yet -- the model does not define it, the model has not been called or built -- then it is correct for maybe rebuild to just skip. If this still seems like a bug, a colab might help understand the use case better. |
@mattdangerw I thought that might be expected, but then I've noticed that there's a failsafe for that that implicitly inserts That's why for me it's not exactly a bug, rather an inconsistent behavior. And to address consistency, I'd lean into one or the other. So either prompt the user to explicitly provide an |
@DLumi there is a reason for that difference actually. If you look at the top of the In Build can be triggered a few ways.
In both those cases we now know the shape that was previously unknown. And it will be propagated to the build call. So that's the answer to the first question of why can't we just always rebuild in |
As for the second question. Why can't we just demand an Honestly I suspect we would if we could. That's a fairly simple approach, and means the model can always be built "eagerly" much like we do with functional models. However, a lot of code out in the wild depends on the fact that you can make a sequential with an unknown shape, which will be built the first time it is called. We don't want to ship a change that breaking. |
I think this is all works as intended. But feel free to reopen if above explanations seem incorrect! |
If we check the code for
build
it has a failsafe for cases when the first layer of the model is not an Input layer:Here's the snippet from the source code
Yet the
_maybe_rebuild
's code ignores rebuilding entirely if input layer is missing:Due to that the
rebuild=True
argument inadd()
is basically ignored entirely.The only option here is to call
build()
explicitly after you added all the layers.Am I missing something? Is this the intended behavior? If so, it would be great to expand documentation on that.
The text was updated successfully, but these errors were encountered: