pytorch/pytorch

[Feature request] `torch.export` .save/.load could support `safetensors` and/or `weights_only=True`

開放

#153,410 建立於 2025年5月12日

 (14 則留言) (2 個反應) (0 位負責人)Python (28,951 個分叉)batch import
export-triagedgood first issueoncall: exportoncall: pt2

倉庫指標

星標
 (102,530 顆星)
PR 合併指標
 (平均合併 1天 10小時) (30 天內合併 42 個 PR)

描述

🚀 The feature, motivation and pitch

Today, torch.export will load tensors via

def deserialize_torch_artifact(serialized: Union[Dict[str, Any], Tuple[Any, ...], bytes]):
    if isinstance(serialized, (dict, tuple)):
        return serialized
    if len(serialized) == 0:
        return {}
    buffer = io.BytesIO(serialized)
    buffer.seek(0)
    # weights_only=False as we want to load custom objects here (e.g. ScriptObject)
    artifact = torch.load(buffer, weights_only=False)
    assert isinstance(artifact, (tuple, dict))
    return artifact

Security teams really don't like this I have learned 🙂. In the interest of leveraging the awesome benefits of export more safely, it would be amazing to add optional support for any or all of safetensors and/or weights_only=True!

Thank you for all the work on torch.export, it has a very promising future!

Alternatives

No response

Additional context

No response

cc @chauhang @penguinwu @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4

貢獻者指南