Skip to content

fix: enable weights_only=True in torch.load for secure state loading#593

Open
RinZ27 wants to merge 2 commits intoPrunaAI:mainfrom
RinZ27:fix-secure-torch-load
Open

fix: enable weights_only=True in torch.load for secure state loading#593
RinZ27 wants to merge 2 commits intoPrunaAI:mainfrom
RinZ27:fix-secure-torch-load

Conversation

@RinZ27
Copy link
Copy Markdown

@RinZ27 RinZ27 commented Mar 24, 2026

Description

Enable weights_only=True for specific torch.load calls in data modules and metrics where only tensors or state dicts are being loaded. This reduces the security surface by preventing arbitrary code execution when loading these files.

Related Issue

Related to #592

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I've reviewed the loading logic in diffuser_distillation_data_module.py and aesthetic_laion.py to ensure they only load supported data types (tensors, dicts, strings). Everything looks green and compatible with weights_only=True.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

While src/pruna/engine/load.py still requires weights_only=False for loading full model objects, I've opted to fix these specific instances where it's safe and beneficial. I've also opened a separate issue #592 to discuss a longer-term architectural improvement for model persistence.

@sdiazlor sdiazlor linked an issue Mar 24, 2026 that may be closed by this pull request
@RinZ27 RinZ27 changed the title Enable weights_only=True in torch.load for secure state loading fix: enable weights_only=True in torch.load for secure state loading Mar 26, 2026
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.

[FEATURE] Enhance security of model loading architecture

1 participant