openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Feature Request]: Support converting safetensor file to OpenVINO IR format

Open Mirakurun opened this issue 1 year ago • 5 comments

Request Description

I'm trying to convert a safetensor file to openvino, but it just gave me an error where it said the file type is unknown.

sample code:

import openvino as ov
from safetensors.torch import load_file

print("Loading safetensor file...")
loaded = load_file("models/v1-5-pruned-emaonly.safetensors")

print("Converting to OpenVINO IR format...")
ov_model = ov.convert_model(loaded)

print("Saving model...")
ov.save_model(ov_model)

Feature Use Case

Directly convert safetensor file to openvino

Issue submission checklist

  • [X] The feature request or improvement must be related to OpenVINO

Mirakurun avatar Feb 09 '24 05:02 Mirakurun

@Mirakurun safetensors.torch.load_file just loads tensors and returns Dict[str, torch.Tensor], while it does not provide information about model topology, e.g. what operations model has and connections between these operations. You need to load original PyTorch model first which internally will load .safetensors file, then pass this model to openvino.convert_model

ilya-lavrenov avatar Feb 09 '24 08:02 ilya-lavrenov

hmmm, is there a way to convert a .safetensors file back to its original model? I found some safetensors models on some third party sites, but usually they only have it in those formats.

Mirakurun avatar Feb 09 '24 08:02 Mirakurun

hmmm, is there a way to convert a .safetensors file back to its original model?

No, as it contains only weights, but not the model structure.

ilya-lavrenov avatar Feb 09 '24 08:02 ilya-lavrenov

Oh ok, thanks I appreciate it.

Mirakurun avatar Feb 09 '24 09:02 Mirakurun

#150640

hbalasu1 avatar Aug 27 '24 03:08 hbalasu1

This issue will be closed in a week because of 9 months of no activity.

github-actions[bot] avatar May 29 '25 00:05 github-actions[bot]

This issue was closed because it has been stalled for 9 months with no activity.

github-actions[bot] avatar Jun 05 '25 00:06 github-actions[bot]