Skip to content

Validate dataloader_kwargs against the worker count - #3555

Closed
lu123bing wants to merge 1 commit into
DeepLabCut:jaap/config-extra-kwargsfrom
lu123bing:config-extra-kwargs-followups
Closed

lu123bing wants to merge 1 commit into
DeepLabCut:jaap/config-extra-kwargsfrom
lu123bing:config-extra-kwargs-followups

Conversation

@lu123bing

Copy link
Copy Markdown
Contributor

Follow-up on your dataloader_kwargs proposal, as discussed in #3550. This branches off jaap/config-extra-kwargs so it can merge straight into #3554; close it if you would rather fold the change in yourself.

What it adds

dataloader_kwargs passes everything through to the training DataLoader, but persistent_workers and prefetch_factor only apply with worker processes. With dataloader_workers: 0, DataLoader raises for them:

ValueError: persistent_workers option needs num_workers > 0
ValueError: prefetch_factor option could only be specified in multiprocessing...

That happens once training starts and names neither dataloader_kwargs nor dataloader_workers, so a config that validates cleanly still fails later. Since the pass-through field is new, this seemed like the moment to catch it at config load, where the message can point at the field to change.

  • New reject_multiprocessing_only_kwargs next to reject_reserved_keys in core/config/validation.py.
  • Wired into TrainSettingsConfig with a model_validator(mode="after"), since the check needs both dataloader_kwargs and dataloader_workers.
  • One line in docs/pytorch/pytorch_config.md noting when the check happens.

The check only rejects values that ask for something. persistent_workers: false and prefetch_factor: null are the DataLoader defaults, so they still validate — matching what DataLoader itself accepts.

Tests

Four cases in tests/pose_estimation_pytorch/config/test_train_settings_config.py: rejected with no workers, accepted with workers, and the two no-op default values still passing. Without the change the first case is the reported failure (dataloader_workers: 0 plus persistent_workers: true validates, then breaks at training).

Verified: pytest tests/pose_estimation_pytorch/config/ tests/core/config/ → 302 passed, 5 xfailed. ruff check and ruff format --check clean. Not run: the full suite, and no end-to-end training run.

I have left the wandb_kwargs simplification you mentioned in #3554 alone — happy to do it here or in a separate PR, whichever you prefer.

`dataloader_kwargs` passes anything through to the training `DataLoader`, but
`persistent_workers` and `prefetch_factor` only apply with worker processes, and
DataLoader raises for them when `dataloader_workers` is 0. That error surfaced
deep in training startup and named neither the option nor the config field.

Checking it while the config loads keeps the failure where the user can fix it.
Only values that ask for something are rejected: `persistent_workers: false`
and `prefetch_factor: null` are the DataLoader defaults and still pass.
@deruyter92

deruyter92 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks @lu123bing for your active contributions!

I agree with what @Ayskin mentioned here:

I would keep the design argument-agnostic for dataloader_kwargs with the cost of failure at training time. What do you think ?

In principle, I would prefer dataloader_kwargs to contain just a pass-trough to PyTorch, who owns the validation. I understand that in some cases early-stage validation can really help the user, but in this case I don't think the benefits are justifying a re-do of the validation inside DeepLabCut: PyTorch validates the dataloader kwargs in DataLoader.__init__ so before the actual training loop. The PyTorch validation happens right after the config validation, so the practical benefit would be a few seconds at best. The message is clear and actionable.

@lu123bing

Copy link
Copy Markdown
Contributor Author

Got it — pure passthrough to PyTorch it is. Closing this since the validation approach here isn't wanted; the kwargs design in #3550 stands.

@lu123bing lu123bing closed this Oct 19, 2026
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.

2 participants