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
FutureWarning: You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details).
In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
Current recognition.py
net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device)))
model.load_state_dict(torch.load(model_path, map_location=device))
Change to:
state_dict = torch.load(model_path, map_location=device, weights_only=True)
model.load_state_dict(torch.load(model_path, map_location=device, weights_only=True))
Considerations
Compatibility: Ensure that your version of PyTorch supports the weights_only=True parameter. This feature is available starting from PyTorch 1.10 as a security measure for preventing the execution of arbitrary code upon loading a model. If your PyTorch version is older, consider upgrading to a supported version to use this feature.
Handling State Dictionaries: When setting weights_only=True, ensure that the model’s state dictionary keys align correctly with the keys in the loaded state dictionary. Sometimes prefixes need to be adjusted, as seen with new_key = key[7:], which is common when moving from DataParallel models to standard models.
Quantization: The try-except block around model quantization is a good practice, especially when experimenting with performance optimizations that may not be supported across all model configurations.
Next Steps
Once you've modified the code, it's essential to test the loading process thoroughly to ensure that the model behaves as expected with the new security settings. If you encounter errors related to key mismatches or other issues, you might need to adjust how you manipulate the keys in the state dictionary or reconsider other aspects of the model loading process.
Thanks for great work.
The text was updated successfully, but these errors were encountered:
FutureWarning: You are using
torch.load
withweights_only=False
(the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details).In a future release, the default value for
weights_only
will be flipped toTrue
. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user viatorch.serialization.add_safe_globals
. We recommend you start settingweights_only=True
for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.Current recognition.py
net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device)))
model.load_state_dict(torch.load(model_path, map_location=device))
Change to:
state_dict = torch.load(model_path, map_location=device, weights_only=True)
model.load_state_dict(torch.load(model_path, map_location=device, weights_only=True))
Considerations
Compatibility: Ensure that your version of PyTorch supports the weights_only=True parameter. This feature is available starting from PyTorch 1.10 as a security measure for preventing the execution of arbitrary code upon loading a model. If your PyTorch version is older, consider upgrading to a supported version to use this feature.
Handling State Dictionaries: When setting weights_only=True, ensure that the model’s state dictionary keys align correctly with the keys in the loaded state dictionary. Sometimes prefixes need to be adjusted, as seen with new_key = key[7:], which is common when moving from DataParallel models to standard models.
Quantization: The try-except block around model quantization is a good practice, especially when experimenting with performance optimizations that may not be supported across all model configurations.
Next Steps
Once you've modified the code, it's essential to test the loading process thoroughly to ensure that the model behaves as expected with the new security settings. If you encounter errors related to key mismatches or other issues, you might need to adjust how you manipulate the keys in the state dictionary or reconsider other aspects of the model loading process.
Thanks for great work.
The text was updated successfully, but these errors were encountered: