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

For xla tensors, use an alternative way to get a unique id #25802

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

qihqi
Copy link
Contributor

@qihqi qihqi commented Aug 28, 2023

What does this PR do?

XLA tensors don't have storage and attempting to get it's storage will get

RuntimeError: Attempted to access the data pointer on an
invalid python storage.

Repro:

from transformers import pytorch_utils
import torch_xla.core.xla_model as xm
device = xm.xla_device()
a = torch.ones((10,10)).to(device)
pytorch_utils.id_tensor_storage(a)  # raises RuntimeError

With this patch it would print out
(device(type='xla', index=0), 1, 400).

@qihqi
Copy link
Contributor Author

qihqi commented Aug 28, 2023

Hi @muellerzr moved huggingface/safetensors#349 to here

@qihqi
Copy link
Contributor Author

qihqi commented Aug 28, 2023

LMK if I should add a test (and in which file) I am not sure if the CI machines has torch_xla installed so import torch_xla can succeed...

Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Some general feedback on how we check torch_tpu, cc @amyeroberts

src/transformers/pytorch_utils.py Outdated Show resolved Hide resolved
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

Changes look OK to me. However, it feels contradictory to add a work around for tensors that don't have storage within a functional called id_tensor_storage: this function shouldn't be called on those tensors at all.

@muellerzr @qipeng Could you provide some more context for this change? i.e. is this enabling functionality elsewhere?

src/transformers/pytorch_utils.py Show resolved Hide resolved
@qihqi qihqi requested a review from muellerzr August 29, 2023 17:22
@muellerzr
Copy link
Contributor

@amyeroberts this stems from huggingface/safetensors#349, where we specified that it should be done in transformers and accelerate separately.

Copy link
Contributor

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as @amyeroberts is happy with the explanation, lg2m

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this fix!

@amyeroberts amyeroberts merged commit f8468b4 into huggingface:main Aug 31, 2023
parambharat pushed a commit to parambharat/transformers that referenced this pull request Sep 26, 2023
…ce#25802)

* For xla tensors, use an alternative way to get a unique id

Because xla tensors don't have storage.

* add is_torch_tpu_available check
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

Successfully merging this pull request may close these issues.

4 participants