huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.75k stars 26.45k forks source link

Error when loading models to DirectML after PR#24505 #26512

Closed pengan1987 closed 10 months ago

pengan1987 commented 12 months ago

System Info

Who can help?

@sgu

Information

Tasks

Reproduction

I'm trying to run Phi-1.5 using Pytorch with DirectML torch-directml==0.2.0.dev230426, my script is here: https://github.com/pengan1987/DirectML-demos/blob/main/Phi_1_5.py When transformers<=4.30.2, it works fine, when transformers>=4.31.0, I got an exception like this when loading the model It seems modeling_utils.py has been changed a lot in PR#24505 and caused this exception, is there any fix/workarond to address this issue?

E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\torch\utils\_device.py:62: UserWarning: TypedStorage is deprecated. It will be removed in the future and Unty
pedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_sto
rage() instead of tensor.storage()
  return func(*args, **kwargs)
Traceback (most recent call last):
  File "E:\StableDiffusion\DirectML-demos\Phi_1_5.py", line 14, in <module>
    model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True)
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\transformers\models\auto\auto_factory.py", line 488, in from_pretrained
    return model_class.from_pretrained(
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\transformers\modeling_utils.py", line 2903, in from_pretrained
    ) = cls._load_pretrained_model(
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\transformers\modeling_utils.py", line 3061, in _load_pretrained_model
    id_tensor = id_tensor_storage(tensor) if tensor.device != torch.device("meta") else id(tensor)
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\transformers\pytorch_utils.py", line 287, in id_tensor_storage
    return tensor.device, storage_ptr(tensor), storage_size(tensor)
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\safetensors\torch.py", line 33, in storage_size
    return tensor.untyped_storage().nbytes()
  File "E:\StableDiffusion\miniconda3\envs\pydml\lib\site-packages\torch\utils\_device.py", line 62, in __torch_function__
    return func(*args, **kwargs)
NotImplementedError: Cannot access storage of OpaqueTensorImpl

Expected behavior

model loading correctly like transformers<=4.30.2

github-actions[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

amyeroberts commented 11 months ago

Hi @pengan1987, thanks for raising this issue!

Two comments:

github-actions[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.