Thanks, this is just what I was after.
A follow-up: my dataloader uses a custom data type, Data. Data has a function pin_memory(self), which returns another object of custom type Data but in pinned memory. However, when I set pin_memory=True in my dataloader, suddenly my iterable yields objects of type dict instead of Data. Any idea what might be going on?