Skip to content

Commit

Permalink
Add ddp_find_unused_parameters=True and change accelerator to auto (N…
Browse files Browse the repository at this point in the history
…VIDIA#7623) (NVIDIA#7644)

* Add ddp_find_unused_parameters=True and change acclerator to auto



* Add ddp_find_unused_parameters True for normalization_as_tagging_train.py



---------

Signed-off-by: Abhishree <[email protected]>
Co-authored-by: Abhishree Thittenamane <[email protected]>
  • Loading branch information
github-actions[bot] and athitten authored Oct 5, 2023
1 parent 1f712b5 commit 25ecb34
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
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

0 comments on commit 25ecb34

Please sign in to comment.