Skip to content

Commit

Permalink
torch-loader(example): use prefetch and try to run example in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Dec 11, 2024
1 parent 6ca3c98 commit 59c7aa6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 5 additions & 2 deletions examples/get_started/torch-loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import multiprocessing
import os
from posixpath import basename

Expand Down Expand Up @@ -54,6 +55,7 @@ def forward(self, x):
if __name__ == "__main__":
ds = (
DataChain.from_storage(STORAGE, type="image")
.settings(cache=True, prefetch=25)
.filter(C("file.path").glob("*.jpg"))
.map(
label=lambda path: label_to_int(basename(path)[:3], CLASSES),
Expand All @@ -64,8 +66,9 @@ def forward(self, x):

train_loader = DataLoader(
ds.to_pytorch(transform=transform),
batch_size=16,
num_workers=2,
batch_size=25,
num_workers=4,
multiprocessing_context=multiprocessing.get_context("spawn"),
)

model = CNN()
Expand Down
9 changes: 1 addition & 8 deletions tests/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@

import pytest

get_started_examples = sorted(
[
filename
for filename in glob.glob("examples/get_started/**/*.py", recursive=True)
# torch-loader will not finish within an hour on Linux runner
if "torch" not in filename or os.environ.get("RUNNER_OS") != "Linux"
]
)
get_started_examples = sorted(glob.glob("examples/get_started/**/*.py", recursive=True))

llm_and_nlp_examples = sorted(glob.glob("examples/llm_and_nlp/**/*.py", recursive=True))

Expand Down

0 comments on commit 59c7aa6

Please sign in to comment.