Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save checkpoint to file descriptor. #531

Open
2 tasks
GLivshits opened this issue Oct 2, 2024 · 0 comments
Open
2 tasks

Can't save checkpoint to file descriptor. #531

GLivshits opened this issue Oct 2, 2024 · 0 comments

Comments

@GLivshits
Copy link

System Info

safetensors==0.4.5
torch==2.4.0+cu124

Information

  • The official example scripts
  • My own modified scripts

Reproduction

import io
import torch
from safetensors.torch import save_file as safetensors_save

data = {}
tensor_shape = (64, 128, 256)
num_tensors = 16
for i in range(num_tensors):
    data[str(i)] = torch.randn(*tensor_shape)

stream = io.BytesIO()
out = safetensors_save(data, stream)

Error:

TypeError: argument 'filename': expected str, bytes or os.PathLike object, not BytesIO

Expected behavior

I've expected serialized checkpoint bytes to be written to buffer.
It would be convenient to do so for:

  1. Further uploading from file object.
  2. Use custom file object, representing database file.

There are only options to serialize checkpoint and get bytes (which is not convenient when checkpoint is large and it is materialized only on master process), and to serialize checkpoint to specified filename.

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

No branches or pull requests

1 participant