Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #14811
A sharded
.bincheckpoint — whatsave_pretrained(..., safe_serialization=False)writes for a model bigger thanmax_shard_size— can't be loaded with the defaultfrom_pretrained, because whenuse_safetensorsisNonethe index lookup only checks the safetensors index name. It raisesOSError: Error no file named diffusion_pytorch_model.bin, and passinguse_safetensors=Falseis the only way to load it.When the unsharded
.binisn't found either, anduse_safetensorswas left atNone, this now looks for the.binindex before raising. It only runs where loading raises today, so:use_safetensorsyourself,TrueorFalse, behaves as beforeuse_flashpack=Truekeeps raising as before rather than being handed pickled shardsThe shard fetch sits outside the
exceptblock so a later failure (a missing shard, say) is reported on its own instead of under the earlier "no file named ..." error.test_sharded_bin_checkpoint_loads_with_default_use_safetensorscovers no variant,variant="ema", and the legacy variant index name. All three fail on main and pass here.Checked on CPU against main @ 7221eef:
tests/models/test_modeling_common.py(15 passed), the save/load/sharding/variant tests of the UNet2D, UNet2DCondition, AutoencoderKL and Flux model suites (62 passed), andtests/pipelines/test_pipelines.py, all matching main. I also compared main and this branch over 32 load scenarios (container × sharding × variant ×use_safetensors) and 48 save-twice scenarios: the only differences are the sharded.bincases that now load and the clearer missing-shard error; every other outcome, including error text, is unchanged.Self-review notes
I used an AI agent and ran the
self-reviewskill; findings from the rounds:use_flashpack=Trueas well, so a missing FlashPack file could end up handing a pickled shard toflashpack.mixin.assign_from_file. It now re-raises, matching main._get_checkpoint_shard_fileswas called inside theexcept, chaining unrelated errors under "no file named ...". Moved out.if not (allow_pickle and use_safetensors)was redundant —allow_pickleis onlyTruewhenuse_safetensorsis — so it's nowif not allow_pickle, like the check above it.code_style.mdprefers a clear error over fallback logic. I went with the fallback becauseuse_safetensors=Nonealready promises one and does it for unsharded checkpoints, and for a pipeline saved this way a better message wouldn't help —use_safetensors=Falsefails on the transformers components, so nothing loads it. Happy to switch to an error instead..binindex would then shadow a freshly written unsharded.bin— so I kept it in the fallback..binweights now makes one 404 request for the unsharded.binbefore the index is found. Repos that load today are unaffected.Before submitting
self-reviewskill on the diff?Who can review?
@sayakpaul @DN6