Skip to content

Conversation

@t-reents
Copy link
Contributor

I get the following error when trying to use the MACE model for structural optimization (or MD):

  File "/home/reents_t/project/dev-torch-sim/git/torch-sim/torch_sim/models/mace.py", line 232, in setup_from_system_idx
    atomic_numbers_to_indices(atomic_numbers.numpy(), z_table=self.z_table),
                              ^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

This PR fixes this error by transferring the atomic_numbers to the CPU first (in case the data is on the GPU, which should be the case), before converting the tensor to numpy.

I just used the example scripts or tried to follow the instructions in the README: https://github.com/TorchSim/torch-sim/tree/v0.4.0?tab=readme-ov-file#running-batched-relaxation

I'm not sure whether this was really a problem or whether I just did something else in a wrong way, as I'd expect that this would have been encountered before. Nonetheless, also comparing with other models, this change seems to be reasonable.

If this is not a bug, just close this PR 😄

@thomasloux
Copy link
Collaborator

thomasloux commented Oct 16, 2025

Relevant bug, I can reproduce.
I think it is because the pytests are run on CPU and not GPU so that the tests currently don't cover these bugs

By the way, the README example needs to be updated to new API (I added that in #290 )

@t-reents
Copy link
Contributor Author

Thanks @thomasloux for confirming!

I think it is because the pytests are run on CPU and not GPU

Yes, I was also mainly referring to users, as I would have expected that someone has encountered this before

@CompRhys
Copy link
Member

CompRhys commented Oct 17, 2025

The mace and elastic test failures here are blocking merge but in principal this is good. I can look over weekend

@t-reents
Copy link
Contributor Author

Thanks @CompRhys
Just checked it again and the tests are passing locally. According to the message, it seems that something goes wrong during the loading process, so it might not really be related to the changes introduced in this PR.

Thanks for having a look at it!

@CompRhys
Copy link
Member

Likely uv downloads a new MACE release which is breaking for us somehow

@abhijeetgangan
Copy link
Collaborator

The mace tests are only failing on mac OS because of the hdf5. I think there might be a easy fix. In case it is blocking we can skip them for mac.

@abhijeetgangan abhijeetgangan merged commit 58d87cd into TorchSim:main Oct 17, 2025
169 of 185 checks passed
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