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
{{ message }}
Repository navigation
save_pretrained can delete shards from another variant and leave stale indexes #14719
On current main (c5469b7ceb606edd7ba6570dcd17d38590a18db6), saving default weights into a directory containing a sharded variant deletes that variant's weight files. Its index remains, so the previously loadable variant fails to reload.
The cleanup loop matches shards by prefix rather than exact checkpoint identity. The replacement path can also leave a stale index when saving a formerly sharded checkpoint as one file; loading follows that index instead of the new weights.
I have a local fix that limits cleanup to the selected variant and serialization format and removes its obsolete index. Would you be open to a PR for that scope?
Reproduction
This uses a small local model and needs no download or GPU. Set variant = None to reproduce the stale default-index case instead.
I would like to take this issue. I reproduced the failure on current main with the small UNet2DModel example.
Proposed scope:
restrict stale shard cleanup to the currently selected variant and serialization format;
remove the selected variant's obsolete index when the new save is unsharded;
add CPU regression coverage that preserves another variant's shards, removes the stale index, and verifies both checkpoints can reload.
The patch will stay limited to ModelMixin.save_pretrained and its regression test. Is this scope okay to proceed with? I will open the PR after maintainer acknowledgment.
I'd like to take this on. I have a fix scoped exactly to the two issues you describe: (1) scope the old-weight cleanup in save_pretrained to the checkpoint identity being replaced (matching variant + serialization format) instead of prefix-matching shard files, and (2) remove the now-obsolete model.safetensors.index.json when switching between sharded and unsharded layouts. Will validate against the repro in this issue (tiny UNet2DModel, variant='ema', sharded save followed by a default-variant save) with regression tests for both cases.
Activity
Vaishnavi220506 commentedon Sep 6, 2026
I would like to take this issue. I reproduced the failure on current
mainwith the smallUNet2DModelexample.Proposed scope:
The patch will stay limited to
ModelMixin.save_pretrainedand its regression test. Is this scope okay to proceed with? I will open the PR after maintainer acknowledgment.DawnofGenX commentedon Sep 22, 2026
I'd like to take this on. I have a fix scoped exactly to the two issues you describe: (1) scope the old-weight cleanup in
save_pretrainedto the checkpoint identity being replaced (matching variant + serialization format) instead of prefix-matching shard files, and (2) remove the now-obsoletemodel.safetensors.index.jsonwhen switching between sharded and unsharded layouts. Will validate against the repro in this issue (tiny UNet2DModel, variant='ema', sharded save followed by a default-variant save) with regression tests for both cases.fix: scope save_pretrained shard cleanup to the saved variant (avoid …