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

load_file does apply to(device) when device = "cpu" #582

Open
2 tasks
mickvangelderen opened this issue Feb 28, 2025 · 0 comments · May be fixed by #583
Open
2 tasks

load_file does apply to(device) when device = "cpu" #582

mickvangelderen opened this issue Feb 28, 2025 · 0 comments · May be fixed by #583

Comments

@mickvangelderen
Copy link

System Info

latest

Information

  • The official example scripts
  • My own modified scripts

Reproduction

I think the code here omits calling tensor.to(device) when the device is "cpu". However, if you've called torch.set_default_device("something other than cpu") the tensor will be loaded on that device instead. I think the device argument should be optional, and remain optional throughout the code base and then always apply .to(device) when it is not None.

Expected behavior

tensor is loaded on cpu when calling load_model(..., device="cpu")

mickvangelderen added a commit to mickvangelderen/safetensors that referenced this issue Feb 28, 2025
This fixes huggingface#582 where if setting torch.set_default_device('not cpu'), the device for the tensor ends up being the default device rather than the passed device.
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 a pull request may close this issue.

1 participant