Loading non-safetensors model causes problem in spaces.zero.torch.patching._untyped_storage_new_register

#164
by ejschwartz - opened

I have a space that loads in zerogpu when using a safetensors model, but causes a strange error when using use_safetensors=False:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 556, in load_state_dict
    return torch.load(
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1351, in load
    return _load(
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1848, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.10/site-packages/torch/_weights_only_unpickler.py", line 385, in load
    self.append(self.persistent_load(pid))
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1812, in persistent_load
    typed_storage = load_tensor(
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1784, in load_tensor
    wrap_storage=restore_location(storage, location),
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 1685, in restore_location
    return default_restore_location(storage, map_location)
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 601, in default_restore_location
    result = fn(storage, location)
  File "/usr/local/lib/python3.10/site-packages/torch/serialization.py", line 472, in _meta_deserialize
    return torch.UntypedStorage(obj.nbytes(), device="meta")
  File "/usr/local/lib/python3.10/site-packages/spaces/zero/torch/patching.py", line 250, in _untyped_storage_new_register
    if (device := kwargs.get('device')) is not None and device.type == 'cuda':
AttributeError: 'str' object has no attribute 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 565, in load_state_dict
    if f.read(7) == "version":
  File "/usr/local/lib/python3.10/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/app/app.py", line 31, in <module>
    vardecoder_model = AutoModelForCausalLM.from_pretrained(
  File "/usr/local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 571, in from_pretrained
    return model_class.from_pretrained(
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 279, in _wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4399, in from_pretrained
    ) = cls._load_pretrained_model(
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4638, in _load_pretrained_model
    load_state_dict(checkpoint_files[0], map_location="meta", weights_only=weights_only).keys()
  File "/usr/local/lib/python3.10/site-packages/transformers/modeling_utils.py", line 577, in load_state_dict
    raise OSError(
OSError: Unable to load weights from pytorch checkpoint file for '/home/user/.cache/huggingface/hub/models--ejschwartz--resym-vardecoder/snapshots/7d5d43a99e614ce980ee1351ef385354a4d968af/pytorch_model.bin' at '/home/user/.cache/huggingface/hub/models--ejschwartz--resym-vardecoder/snapshots/7d5d43a99e614ce980ee1351ef385354a4d968af/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

Space is available here

Unfortunately, I am trying to work-around a problem involving accelerate, transformers, and safetensors, which is why I want to disable safetensors. Issue for context

Sign up or log in to comment