Skip to content

fix: load face-parse checkpoints with weights_only=False for PyTorch 2.6+ (#341)#419

Open
MushiSenpai wants to merge 1 commit into
TMElyralab:mainfrom
MushiSenpai:fix/face-parse-weights-only-341
Open

fix: load face-parse checkpoints with weights_only=False for PyTorch 2.6+ (#341)#419
MushiSenpai wants to merge 1 commit into
TMElyralab:mainfrom
MushiSenpai:fix/face-parse-weights-only-341

Conversation

@MushiSenpai

Copy link
Copy Markdown

Summary

Fixes #341. On PyTorch 2.6+, MuseTalk crashes during face parsing with:

RuntimeError: Cannot use `weights_only=True` with files saved in the legacy .tar format.

PyTorch 2.6 changed the default of torch.load's weights_only argument from False
to True. The face-parse BiSeNet backbone weights — resnet18-5c106cde.pth, downloaded
straight from the official torch model zoo (download.pytorch.org/models/...) — are saved
in the legacy .tar serialization format, which the new safe loader refuses
unconditionally
. The whole inference run dies after the UNet has already loaded.

The fix

Pass weights_only=False at the three face-parse checkpoint loads:

  • musetalk/utils/face_parsing/resnet.pyresnet18-5c106cde.pth (the exact 怎么设置 weights_only=False? #341 site)
  • musetalk/utils/face_parsing/__init__.py79999_iter.pth, CUDA and CPU branches

These 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 / keep weights_only=True? That route only helps the
"unsupported global" case. Here the error is the legacy .tar format branch — PyTorch
rejects weights_only=True for .tar files before the unpickler is ever reached, so
there is no global to allowlist. weights_only=False (or re-serializing the checkpoint)
is the only viable fix; weights_only=False is the minimal, in-repo one.

Validation (real before/after)

Against the actual resnet18-5c106cde.pth from the model zoo, on torch 2.12.1:

Result
Current code (torch.load(path) → default weights_only=True) RuntimeError: Cannot use weights_only=True with files saved in the legacy .tar formatthe exact #341 crash
This patch (torch.load(path, weights_only=False)) loads cleanly (102 tensors)

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_full image-input
NameError is 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-By trailer.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

怎么设置 weights_only=False?

1 participant