Skip to content

fix: move tensors to correct device in batch_to_dict#147

Merged
yanghan234 merged 2 commits intomainfrom
fix/issue-113-batch-to-dict-device
Apr 21, 2026
Merged

fix: move tensors to correct device in batch_to_dict#147
yanghan234 merged 2 commits intomainfrom
fix/issue-113-batch-to-dict-device

Conversation

@yanghan234
Copy link
Copy Markdown
Collaborator

Summary

Fixes #113batch_to_dict accepted a device parameter but never used it, leaving all tensors on their original device.

Changes

  • Add .to(device) to every tensor extracted from graph_batch in batch_to_dict()
  • Create num_graphs tensor with device=device
  • Pass self.device at all 5 internal call sites so the correct runtime device (cpu/mps/cuda) is always used

Tests

Added tests/forcefield/test_batch_to_dict.py with 9 test cases covering:

  • Tensor placement on all available devices (CPU, MPS, CUDA)
  • Cross-device movement
  • Value preservation after device transfer
  • num_graphs scalar-to-tensor conversion on correct device
  • Unsupported model type error handling

Also added tests/conftest.py with a shared device fixture that auto-detects available devices.

yanghan234 and others added 2 commits April 21, 2026 14:54
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yanghan234 yanghan234 merged commit cc84ddc into main Apr 21, 2026
20 checks passed
@yanghan234 yanghan234 deleted the fix/issue-113-batch-to-dict-device branch April 27, 2026 13:17
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.

[Bug]: Batch_to_dict function does not move Tensors to the correct device.

1 participant