@ptrblck  Sure, I actually thought of reading the hdf5 file outside the Dataset class, here it is:
train_hf = File('train_images_labels.h5', 'r')

class IterableDataset(pt.utils.data.IterableDataset):
    def __init__(self, train_images_file):
        super().__init__()
        self.hf = train_images_file

    def __iter__(self):
        return self
    
    def __next__(self):
        idx = np.random.randint(0, len(self.hf['images'])) # random for testing purposes
        return ( self.hf['images'][idx], self.hf['labels'][idx] )
    
batch_size = 2 # takes about 1 second for each sample, i.e. batch_size = 64 => ~64 secs... same for next calls

train_dataset = IterableDataset(train_hf)
print('done1')
train_loader = pt.utils.data.DataLoader(train_dataset, batch_size=batch_size)
print('done2')

iterator = iter(train_loader)

next(iterator).shape
print('done3')
next(iterator).shape
print('done4')

train_hf.__bool__()
train_hf.close()
train_hf.__bool__()

Note: my hdf5 dataset is a bunch of images converted to numpy arrays.