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

serialize & deserialize does not work as the documentation specify. #559

Open
1 of 2 tasks
csaybar opened this issue Jan 12, 2025 · 0 comments
Open
1 of 2 tasks

serialize & deserialize does not work as the documentation specify. #559

csaybar opened this issue Jan 12, 2025 · 0 comments

Comments

@csaybar
Copy link

csaybar commented Jan 12, 2025

System Info

  • transformers version: 4.42.3
  • Platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.35
  • Python version: 3.10.12
  • Huggingface_hub version: 0.25.2
  • Safetensors version: 0.5.2
  • Accelerate version: 0.27.0
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.3.1+cu121 (True)
  • Tensorflow version (GPU?): 2.15.0 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using distributed or parallel set-up in script?:
  • Using GPU in script?:
  • GPU type: NVIDIA GeForce RTX 3050 Laptop GPU

Information

  • The official example scripts
  • My own modified scripts

Reproduction

Hi,

I’m unsure if this is expected behavior or a bug since it does not align with what the documentation for these functions describes. Below is the code to reproduce the issue:

Expected behavior

import numpy as np
import safetensors
from safetensors.numpy  import save_file, load

# Save as a safetensors file
data_ran_uint16 = np.random.randint(0, 255, (2, 2, 2)).astype(np.uint16)
save_file({"toy": data_ran_uint16}, "toy.safetensors")

# Deserialize the file
with open("toy.safetensors", "rb") as f:
    fbytes = safetensors.deserialize(f.read())

# Expected to work
serialized = safetensors.serialize({"toy": fbytes[0][1]})

# Workaround
fbytes[0][1]["data"] = bytes(fbytes[0][1]["data"]) # I had to convert the bytearray to bytes
fbytes[0][1]["dtype"] = "uint16" # I had to change the dtype to uint16
fbytes[0][1]["shape"]
serialized = safetensors.serialize({"toy": fbytes[0][1]})
load(serialized)
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