When a keras.models.Model instance is initialized from the input attribute from another Model that was constructed by passing an intermediate symbolic tensor that was an output of another external layer as the input, the resulting Model incorrectly includes layers that were used to construct the intermediate input tensor.

I'm afraid the above sentence will amount to little more than gibberish without an example, so please refer to the following notebook: https://colab.research.google.com/drive/1lfif-YosIn4wgzL8t8WjX520C_0eDTGV?usp=sharing

The notebook illustrates a simplified version of a text processing scenario, in which the full model is split into a preprocessing portion and a trainable portion.

Comment From: harshaljanjani

Hello @briango28, thanks for posting the issue and apologies for the fact that you haven't received a timely response.

The resulting Model incorrectly includes layers that were used to construct the intermediate input tensor.

Since you're referencing an input tensor tied to the computational graph of the trainable_model, this graph includes all layers and operations upstream of the input (input_layer and string_lookup even though they were not explicitly defined in the intermediate model), hence the behavior. The simple fix, as you also pointed out in the gist is to include the input_indices tensor itself as even though it carries dependencies of its own, it's treated as an atomic unit so to speak. Hence the behavior might be just as intended, the tensor is used when no inherited history is wanted, hence no extra unnecessary layers are included.

Comment From: github-actions[bot]

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

Comment From: github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.