Skip to content

Commit

Permalink
Restore support for passing device in CPU-only environment (#107)
Browse files Browse the repository at this point in the history
Add test for passing device to check this works on CPU
  • Loading branch information
oliverholworthy committed Mar 13, 2023
1 parent 3c11b59 commit 226ad69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions merlin/dataloader/loader_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ def __init__(
self.global_rank = global_rank or 0
self.drop_last = drop_last

if device:
self.device = device
else:
self.device = "cpu" if not HAS_GPU or dataset.cpu else 0
device = device or 0
self.device = "cpu" if not HAS_GPU or dataset.cpu else device

if self.device == "cpu":
self._array_lib = np
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/dataloader/test_tf_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def test_simple_model():
_ = model.evaluate(loader)


def test_with_device():
dataset = Dataset(make_df({"a": [1]}))
tf_dataloader.Loader(dataset, batch_size=1, device=1).peek()


def test_nested_list():
num_rows = 100
batch_size = 12
Expand Down

0 comments on commit 226ad69

Please sign in to comment.