Skip to content

fix(reproduce): scale default dataloader workers to CPU count, not OS - #181

Open
skywalker-lt wants to merge 1 commit into
Tencent:mainfrom
skywalker-lt:fix/windows-dataloader-workers
Open

fix(reproduce): scale default dataloader workers to CPU count, not OS#181
skywalker-lt wants to merge 1 commit into
Tencent:mainfrom
skywalker-lt:fix/windows-dataloader-workers

Conversation

@skywalker-lt

Copy link
Copy Markdown
Contributor

Issue

PR #174 made --workers default to 0 whenever the host is Windows with the intention to avoid I/O deadlocks. However, build_dataloader computes nw = min(os.cpu_count() // nd, workers), so 0 stays 0 and every batch is decoded and augmented inline on the training process. The augmentation no longer overlap the GPU step, hence Windows users get materially slower epochs even with powerful CPUs.

🛠️ Fix

Replace the OS-branch with default_workers(), sized to the machine:

CPU cores 2 4 8 16 32 64
workers 1 2 4 8 16 16

Now worker cost tracks core count and memory rather than the operating system.

📁 file changed

scripts/reproduce/_reproduce_common.py

…st OS

eff7e3e set --workers to 0 whenever the host is Windows. That disables the
worker pool outright: build_dataloader computes nw = min(cpu_count // nd,
workers), so 0 stays 0 and every batch is decoded and augmented inline on the
training process. Mosaic/resize no longer overlap the GPU step, so Windows users
silently get materially slower epochs with no warning -- the only hint is a help
string.

The stated reason was multiprocessing deadlocks, but the usual cause on Windows
is a missing entry-point guard for spawn, and all three reproduce scripts
already have 'if __name__ == "__main__":'.

Replace the OS branch with default_workers(), which scales to the machine:
half the visible cores, capped at 16, floored at 1. Worker cost tracks cores and
memory rather than platform, so this also drops the 'import platform' the branch
introduced; hard-coded per-OS constants go stale as machines change.

  cores    1   2   4   8  16  32  64
  workers  1   1   2   4   8  16  16

A >=32-core Linux host still gets 16, matching the previous default, so existing
reproduction runs are unaffected. Windows now gets a real pool sized to the
laptop instead of 0. --workers 0 remains available for any box that genuinely
stalls, and the help text says so.
@skywalker-lt
skywalker-lt marked this pull request as draft July 28, 2026 15:08
@skywalker-lt
skywalker-lt marked this pull request as ready for review July 28, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant