-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedOpen to be worked onOpen to be worked on
Description
🐛 Bug
move_data_to_device has special handling of dataclasses, but in case the dataclass has a non-init field, elem_type(**out) in apply_to_collection will fail
To Reproduce
from pytorch_lightning.utilities import move_data_to_device
import torch
from dataclasses import dataclass, field
from typing import NamedTuple, List
@dataclass
class Data:
example_id: List[str]
x: torch.Tensor
y: int = field(init=False)
def __post_init__(self):
self.y = 3
batch_size = 5
batch = Data(
example_id=[f"e-{i}" for i in range(batch_size)],
x = torch.rand(batch_size),
)
assert batch.y == 3
device = torch.device("cuda:0")
move_data_to_device(batch=batch, device=device)
Expected behavior
Should run without exceptions
Environment
- Packages:
- numpy: 1.21.2
- pyTorch_debug: False
- pyTorch_version: 1.9.1
- pytorch-lightning: 20211014
- tqdm: 4.62.3 - System:
- OS: Linux
- architecture:
- 64bit
-
- processor: x86_64
- python: 3.9.7
awaelchli
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedOpen to be worked onOpen to be worked on