Description
PyTorch 2.6+ changed the default value of weights_only in torch.load() from False to True. This breaks loading the FastSAM checkpoint because the .pt file contains custom classes (e.g. ultralytics.nn.tasks.SegmentationModel) that are not in the default allowlist.
Error
_pickle.UnpicklingError: Weights only load failed.
WeightsUnpickler error: Unsupported global: GLOBAL ultralytics.nn.tasks.SegmentationModel was not an allowed global by default.
Location
ultralytics/nn/tasks.py lines 518 and 533 (two occurrences in torch_safe_load()):
return torch.load(file, map_location='cpu'), file # load
Suggested Fix
Add weights_only=False to the torch.load() calls:
return torch.load(file, map_location='cpu', weights_only=False), file # load
Since the checkpoint comes from the official model release (a trusted source), this is safe.
Related
Description
PyTorch 2.6+ changed the default value of
weights_onlyintorch.load()fromFalsetoTrue. This breaks loading the FastSAM checkpoint because the .pt file contains custom classes (e.g.ultralytics.nn.tasks.SegmentationModel) that are not in the default allowlist.Error
Location
ultralytics/nn/tasks.pylines 518 and 533 (two occurrences intorch_safe_load()):Suggested Fix
Add
weights_only=Falseto thetorch.load()calls:Since the checkpoint comes from the official model release (a trusted source), this is safe.
Related
safe_globalsapproach instead)