Skip to content

Commit

Permalink
Merge pull request #1475 from chenyuwuxin/master
Browse files Browse the repository at this point in the history
FIX: fix compatibility issues for dataloader.dataset
  • Loading branch information
Sherry-XLL authored Oct 4, 2022
2 parents edaa2a8 + 82175b3 commit 5d7df69
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions recbole/data/dataloader/abstract_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from recbole.utils import InputType, FeatureType, FeatureSource
from recbole.data.transform import construct_transform

start_iter = False


class AbstractDataLoader(torch.utils.data.DataLoader):
""":class:`AbstractDataLoader` is an abstract object which would return a batch of data which is loaded by
Expand Down Expand Up @@ -96,6 +98,19 @@ def collate_fn(self):
"""Collect the sampled index, and apply neg_sampling or other methods to get the final data."""
raise NotImplementedError("Method [collate_fn] must be implemented.")

def __iter__(self):
global start_iter
start_iter = True
res = super().__iter__()
start_iter = False
return res

def __getattribute__(self, __name: str):
global start_iter
if not start_iter and __name == "dataset":
__name = "_dataset"
return super().__getattribute__(__name)


class NegSampleDataLoader(AbstractDataLoader):
""":class:`NegSampleDataLoader` is an abstract class which can sample negative examples by ratio.
Expand Down

0 comments on commit 5d7df69

Please sign in to comment.