fixes test issues on ddp (#1017)

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs

* updated checkpoint docs
This commit is contained in:
William Falcon
2020-03-02 21:50:38 -05:00
committed by GitHub
parent 5458d05cd8
commit 6dae5698ef
6 changed files with 72 additions and 1 deletions
@@ -145,6 +145,7 @@ class TrainerDDPMixin(ABC):
use_amp: bool
amp_level: str
use_tpu: bool
default_save_path: str
@property
@abstractmethod
@@ -340,6 +341,35 @@ class TrainerDDPMixin(ABC):
# continue training routine
self.run_pretrain_routine(model)
# when ddp ends, we save the model
self.save_spawn_weights(model)
def save_spawn_weights(self, model):
"""
Dump a temporary checkpoint after ddp ends to get weights out of the process
:param model:
:return:
"""
path = os.path.join(self.default_save_path, '__temp_weight_ddp_end.ckpt')
self.save_checkpoint(path)
def load_spawn_weights(self, original_model):
"""
Load the temp weights saved in the process
To recover the trained model from the ddp process we load the saved weights
:param model:
:return:
"""
# load weights saved in ddp
path = os.path.join(self.default_save_path, '__temp_weight_ddp_end.ckpt')
loaded_model = original_model.__class__.load_from_checkpoint(path)
# copy loaded weights to old model
original_model.load_state_dict(loaded_model.state_dict())
# remove ddp weights
os.remove(path)
def resolve_root_node_address(self, root_node):
if '[' in root_node:
name = root_node.split('[')[0]