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 37403b9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 2 additions & 1 deletion examples/get_started/torch-loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def forward(self, x):
if __name__ == "__main__":
ds = (
DataChain.from_storage(STORAGE, type="image")
.settings(prefetch=25, cache=True)
.filter(C("file.path").glob("*.jpg"))
.map(
label=lambda path: label_to_int(basename(path)[:3], CLASSES),
Expand All @@ -64,7 +65,7 @@ def forward(self, x):

train_loader = DataLoader(
ds.to_pytorch(transform=transform),
batch_size=16,
batch_size=25,
num_workers=2,
)

Expand Down
2 changes: 1 addition & 1 deletion src/datachain/asyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ async def _break_iteration(self) -> None:

def iterate(self, timeout=None) -> Generator[ResultT, None, None]:
init = asyncio.run_coroutine_threadsafe(self.init(), self.loop)
init.result(timeout=1)
init.result()
async_run = asyncio.run_coroutine_threadsafe(self.run(), self.loop)
try:
while True:
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 37403b9

Please sign in to comment.