fix: load face-parse checkpoints with weights_only=False for PyTorch 2.6+ (#341)#419
Open
MushiSenpai wants to merge 1 commit into
Open
fix: load face-parse checkpoints with weights_only=False for PyTorch 2.6+ (#341)#419MushiSenpai wants to merge 1 commit into
MushiSenpai wants to merge 1 commit into
Conversation
…2.6+ (TMElyralab#341) PyTorch 2.6 changed torch.load's default to weights_only=True, which refuses the legacy .tar-format face-parse checkpoints (resnet18-5c106cde.pth from the official torch model zoo, and 79999_iter.pth) and crashes the run. Pass weights_only=False at the three face-parse loads; these checkpoints come from trusted sources. add_safe_globals cannot help here: the legacy .tar format is rejected before the safe unpickler is reached. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
Fixes #341. On PyTorch 2.6+, MuseTalk crashes during face parsing with:
PyTorch 2.6 changed the default of
torch.load'sweights_onlyargument fromFalseto
True. The face-parse BiSeNet backbone weights —resnet18-5c106cde.pth, downloadedstraight from the official torch model zoo (
download.pytorch.org/models/...) — are savedin the legacy
.tarserialization format, which the new safe loader refusesunconditionally. The whole inference run dies after the UNet has already loaded.
The fix
Pass
weights_only=Falseat the three face-parse checkpoint loads:musetalk/utils/face_parsing/resnet.py—resnet18-5c106cde.pth(the exact 怎么设置 weights_only=False? #341 site)musetalk/utils/face_parsing/__init__.py—79999_iter.pth, CUDA and CPU branchesThese checkpoints come from trusted sources (the official PyTorch model zoo and the
project's own published weights), so disabling the safe loader for them is appropriate.
Why not
add_safe_globals/ keepweights_only=True? That route only helps the"unsupported global" case. Here the error is the legacy
.tarformat branch — PyTorchrejects
weights_only=Truefor.tarfiles before the unpickler is ever reached, sothere is no global to allowlist.
weights_only=False(or re-serializing the checkpoint)is the only viable fix;
weights_only=Falseis the minimal, in-repo one.Validation (real before/after)
Against the actual
resnet18-5c106cde.pthfrom the model zoo, ontorch 2.12.1:torch.load(path)→ defaultweights_only=True)RuntimeError: Cannot use weights_only=True with files saved in the legacy .tar format— the exact #341 crashtorch.load(path, weights_only=False))Scope
Surgical, face-parse-only. This does not overlap PR #414 (which fixes the UNet load
only and does not resolve #341); the two are complementary. The
save_dir_fullimage-inputNameErroris a separate issue and will be its own PR to keep blast radius minimal.Disclosure: this fix was drafted with AI assistance (Claude) and reviewed, tested, and
submitted by me. The commit carries a
Co-Authored-Bytrailer.