Skip to content

Disable UserWarning for DataLoaders with num_workers=0 #10182

@marcm-ml

Description

@marcm-ml

Proposed refactoring or deprecation

Disable dataloader UserWarning for num_workers=0 since 0 disables multi-process loading (according to pytorch docs it loads in the main process whereas 1 would create a separate process)

Motivation

I understand the motivation behind utilising more processes for data loading but the warning should not appear if the user specifically requested to use the main process (by setting num_workers=0)

Pitch

Change

https://github.com/PyTorchLightning/pytorch-lightning/blob/c33df2639f19d49c5e7520294e3221efe402d684/pytorch_lightning/trainer/data_loading.py#L109-L115

to

elif 0 < dataloader.num_workers <= 2 < num_cpus and not using_spawn:
    rank_zero_warn( 
        f"The dataloader, {name}, does not have many workers which may be a bottleneck." 
        " Consider increasing the value of the `num_workers` argument`" 
        f" (try {num_cpus} which is the number of cpus on this machine)" 
        " in the `DataLoader` init to improve performance." 
    ) 

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionIn a discussion stagefeatureIs an improvement or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions