Refering the inferface of save_model, add force_contiguous(default=True) to force the state_dict to be saved as contiguous tensors, and finally into raw bytes in safetensors format.
The fix could contribute such scenario, when running workloads w/ channels_last format in PyTorch, but need finally saved to .safetensor by calling transformers::safe_save_file. Meanwhile, it could also align the semantics between save_model & save_file.
What does this PR do?
Refering the inferface of
save_model
, addforce_contiguous
(default=True) to force the state_dict to be saved as contiguous tensors, and finally into raw bytes in safetensors format.The fix could contribute such scenario, when running workloads w/ channels_last format in PyTorch, but need finally saved to .safetensor by calling transformers::safe_save_file. Meanwhile, it could also align the semantics between
save_model
&save_file
.A related issue encountered such scenario: https://github.com/huggingface/safetensors/issues/308