Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi gpu training; RuntimeError: [...] LightningModule has parameters that were not used in producing the loss returned by training_step. #8

Open
kunibald413 opened this issue Nov 22, 2023 · 4 comments

Comments

@kunibald413
Copy link

added devices="auto" in train.py to utilize multiple gpus

    trainer: Trainer = hydra.utils.instantiate(cfg.trainer,
                                               callbacks=callbacks,
                                               logger=logger,
                                               devices="auto")

Training terminates shortly after start with this error:

RuntimeError: It looks like your LightningModule has parameters that were not used in producing the loss returned by training_step. If this is intentional, you must enable the detection of unused parameters in DDP, either by setting the string value `strategy='ddp_find_unused_parameters_true'` or by setting the flag in the strategy with `strategy=DDPStrategy(find_unused_parameters=True)`.

adding
strategy='ddp_find_unused_parameters_true'
to the trainer instantiate fixes it (all gpus used):

    trainer: Trainer = hydra.utils.instantiate(cfg.trainer,
                                               callbacks=callbacks,
                                               logger=logger,
                                               devices="auto",
                                               # for multi device training
                                               strategy='ddp_find_unused_parameters_true'
                                               )

the batch_idx is not used when returning the loss by def training_step(self, batch: Any, batch_idx: int): in baselightingmodule.py
but i'm not sure about the consequences/effect on training/quality. making issue for visibility

@egorsmkv
Copy link

egorsmkv commented Jan 1, 2024

Having the same issue with multiple GPUs

@p0p4k
Copy link
Owner

p0p4k commented Jan 1, 2024

There is a ddp config in the config folder, which does the ddp strategy flag true to use multi gpu. About the consequences for unused parameters, I am not very well versed with that at the moment.

@skypro1111
Copy link

in file /configs/trainer/ddp.yaml set strategy: ddp_find_unused_parameters_true

defaults:
  - default

strategy: ddp_find_unused_parameters_true

accelerator: gpu
devices: [0,1,2]
num_nodes: 1
sync_batchnorm: True

in file /configs/train.yaml set trainer: ddp

# @package _global_

# specify here default configuration
# order of defaults determines the order in which configs override each other
defaults:
  - _self_
  - data: ljspeech
  - model: pflow
  - callbacks: default
  - logger: tensorboard # set logger here or use command line (e.g. `python train.py logger=tensorboard`)
  - trainer: ddp
  - paths: default
  - extras: default
  - hydra: default

@SAnsAN-9119
Copy link

в файле / configs/trainer/ddp.yaml установлена стратегия: ddp_find_unused_parameters_true

defaults:
  - default

strategy: ddp_find_unused_parameters_true

accelerator: gpu
devices: [0,1,2]
num_nodes: 1
sync_batchnorm: True

в файле / configs/train.yaml set trainer: ddp

# @package _global_

# specify here default configuration
# order of defaults determines the order in which configs override each other
defaults:
  - _self_
  - data: ljspeech
  - model: pflow
  - callbacks: default
  - logger: tensorboard # set logger here or use command line (e.g. `python train.py logger=tensorboard`)
  - trainer: ddp
  - paths: default
  - extras: default
  - hydra: default

This solution also helped me when running on multiple GPUs

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

No branches or pull requests

5 participants