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

Add ddp_find_unused_parameters=True and change accelerator to auto #7644

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

@hydra_runner(config_path="conf", config_name="intent_slot_classification_config")
def main(cfg: DictConfig) -> None:
# PTL 2.0 has find_unused_parameters as False by default, so its required to set it to True
# when there are unused parameters like here
if cfg.trainer.strategy == 'ddp':
cfg.trainer.strategy = "ddp_find_unused_parameters_true"
logging.info(f'Config Params:\n {OmegaConf.to_yaml(cfg)}')
trainer = pl.Trainer(**cfg.trainer)
exp_manager(trainer, cfg.get("exp_manager", None))
Expand Down
5 changes: 4 additions & 1 deletion examples/nlp/question_answering/question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
@hydra_runner(config_path="conf", config_name="qa_conf")
def main(cfg: DictConfig) -> None:
pl.seed_everything(42)

# PTL 2.0 has find_unused_parameters as False by default, so its required to set it to True
# when there are unused parameters like here
if cfg.trainer.strategy == 'ddp':
cfg.trainer.strategy = "ddp_find_unused_parameters_true"
logging.info(f'Config: {OmegaConf.to_yaml(cfg)}')
trainer = pl.Trainer(**cfg.trainer)
exp_dir = exp_manager(trainer, cfg.get("exp_manager", None))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

@hydra_runner(config_path="conf", config_name="thutmose_tagger_itn_config")
def main(cfg: DictConfig) -> None:
# PTL 2.0 has find_unused_parameters as False by default, so its required to set it to True
# when there are unused parameters like here
if cfg.trainer.strategy == 'ddp':
cfg.trainer.strategy = "ddp_find_unused_parameters_true"
logging.info(f'Config Params: {OmegaConf.to_yaml(cfg)}')

# Train the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
@hydra_runner(config_path="conf", config_name="token_classification_config")
def main(cfg: DictConfig) -> None:
try:
strategy = NLPDDPStrategy()
strategy = NLPDDPStrategy(find_unused_parameters=True)
except (ImportError, ModuleNotFoundError):
strategy = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def validation_step(self, batch, batch_idx):
val_loss_tag = self.loss_fn(logits=tag_logits, labels=tag_labels, loss_mask=labels_mask)
val_loss_semiotic = self.loss_fn(logits=semiotic_logits, labels=semiotic_labels, loss_mask=labels_mask)
val_loss = val_loss_tag + val_loss_semiotic
self.validation_step_outputs.append(val_loss)
self.validation_step_outputs.append({'val_loss': val_loss})
return {'val_loss': val_loss}

def on_validation_epoch_end(self):
Expand Down
2 changes: 1 addition & 1 deletion tutorials/nlp/Entity_Linking_Medical.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"\n",
"# remove distributed training flags\n",
"cfg.trainer.strategy = 'auto'\n",
"cfg.trainer.accelerator = None"
"cfg.trainer.accelerator = 'auto'"
]
},
{
Expand Down