Skip to content

pin_memory_fn returns None when NamedTuple is provied #1085

@ejguan

Description

@ejguan

🐛 Describe the bug

Per title

Min-repro:

from typing import NamedTuple
import torch
from torchdata.datapipes.utils import pin_memory_fn

class NamedTensors(NamedTuple):
    a: torch.Tensor
    b: torch.Tensor

data = NamedTensors(torch.tensor(1), torch.tensor(2))

print(pin_memory_fn(data))  # None

To fix it, we just need to add a return https://github.com/pytorch/data/blob/fea20d416cd40e23ee949e09f0f5a7858fcc3542/torchdata/datapipes/utils/pin_memory.py#L30

Versions

main branch

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions