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

Sequentials _maybe_rebuild does not make sense #19916

Open
DLumi opened this issue Jun 25, 2024 · 0 comments
Open

Sequentials _maybe_rebuild does not make sense #19916

DLumi opened this issue Jun 25, 2024 · 0 comments
Assignees

Comments

@DLumi
Copy link

DLumi commented Jun 25, 2024

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

        if isinstance(self._layers[0], InputLayer):
            ...
        else:
            dtype = self._layers[0].compute_dtype
            self._layers = [
                InputLayer(batch_shape=input_shape, dtype=dtype)
            ] + self._layers

Yet the _maybe_rebuild's code ignores rebuilding entirely if input layer is missing:

    def _maybe_rebuild(self):
        self.built = False
        self._functional = None
        if isinstance(self._layers[0], InputLayer) and len(self._layers) > 1:
            input_shape = self._layers[0].batch_shape
            self.build(input_shape)

Due to that the rebuild=True argument in add() 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.

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

No branches or pull requests

2 participants