You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Functional API (keras.models.Model) yields erroneous graph when initialized by the input attribute of another Model constructed from an intermediate symbolic tensor.
#20668
Open
briango28 opened this issue
Dec 19, 2024
· 1 comment
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.
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.
The text was updated successfully, but these errors were encountered:
Hello @briango28, thanks for posting the issue and apologies for the fact that you haven't received a timely response.
The resulting Modelincorrectly 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.
When a
keras.models.Model
instance is initialized from theinput
attribute from anotherModel
that was constructed by passing an intermediate symbolic tensor that was an output of another external layer as the input, the resultingModel
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.
The text was updated successfully, but these errors were encountered: