#18419·keras

Model weights are not de-duplicated on save

Author: mattdangerwCreated Aug 8, 2023Updated Sep 24, 2026
Labelstype:Bug

When a model shares a single variable across many layers, model.weights is deduped. Only one weight will be returned no matter how many times it is referenced.

However when a model is saved, every layer that has a ref to variable will save their own copy. Weights are not deduped on save.

This can lead to a funny flow where things appear to be working, but the saved weights are actually duplicated on disk, and a single variable is assigned multiple times during load. This colab shows the issue -> https://colab.research.google.com/gist/mattdangerw/2fabb09d53bd19cb6407d219e34155ab/weight-sharing-weirdness.ipynb