lightly-ai / lightly-ai/lightly

Speed up benchmarks by disabling find_unused_parameters

Open
#1,434 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
3.8k
Forks
367
Avg merge
3d 22h
Merged PRs (30d)
5

Description

We use the ddp_find_unused_parameters_true strategy when running benchmarks:
https://github.com/lightly-ai/lightly/blob/caf72c5df39b8a9868676d76a8ce0de5a10701d4/benchmarks/imagenet/resnet50/main.py#L230

This flag can slow down training considerably. We enabled it because some models have parameters that are not used during all training steps, for example, DINO freezes the projection head during the first epoch. But in principle we should be able to disable the flag for most models.

One special case are models with frozen backbones (EMA backbones) where the backbone parameters remain frozen during all training steps. For those models it should be possible to disable the flag but only if we disable gradients in the model __init__ method (according to this issue: https://github.com/Lightning-AI/lightning/issues/17212). Currently we use torch.no_grad() to disable gradients, disabling them with module.requires_grads_(False) should allow us to disable the flag.

For some models it should also be possible to set static_graph=True (https://lightning.ai/docs/pytorch/latest/advanced/ddp_optimizations.html#ddp-static-graph) for further speedups.

Todo

  • Set ddp_find_unused_parameters_false in benchmarks/imagenet/resnet50/main.py and check which models work with it
  • Check which models we can easily fix to support disabling the flag
  • [ ] For models that do not support disabling the flag, we can add a "strategy" entry to the METHODS dict at the top of main.py and then use this one to set the training argument
  • Check if we get a speedup
  • [ ] Check if we can set static_graph=True for some models

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in benchmarks/imagenet/resnet50/main.py, especially the strategy setting around line 230 and the METHODS dict. Try the ddp_find_unused_parameters_false strategy across the listed models, then inspect models with frozen or intermittently unused parameters and the Lightning DDP static_graph guidance. Done means compatible models use the faster strategy, exceptions are configured explicitly, and benchmark speedups are measured.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems, machine-learning, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.