def _restore_h5_file(self):
        """Ensure the current shard is the last one created.

        We use mode="a" to avoid truncating the file during the switching.
        """
        if (
            pathlib.Path(self.h5_file.filename).name
            != self.current_shard_path.name
        ):
            self._switch_h5_file(self.current_shard_path.name, mode="a")
Ensure the current shard is the last one created.

        We use mode="a" to avoid truncating the file during the switching.
        
keras/src/saving/saving_lib.py