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

Load rng state #990

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions ppfleetx/configs/nlp/gpt/pretrain_gpt_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Engine:
save_epoch: 1
output_dir: ./output
ckpt_dir:
load_meta_state: True


Model:
Expand Down
16 changes: 11 additions & 5 deletions ppfleetx/core/engine/eager_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def configure_optimizers(self):

self._output_dir = self._configs['save_load']['output_dir']
self._ckpt_dir = self._configs['save_load']['ckpt_dir']
self._load_meta_state = self._configs['save_load'].get("load_meta_state", True)

self._compress_configs = None
self.prune_configs = None
Expand Down Expand Up @@ -393,8 +394,12 @@ def fit(self, epoch=1, train_data_loader=None, valid_data_loader=None):

start_epoch = self._load_recovery['epoch']
if self._load_recovery['rng_state'] != -1:
paddle.set_cuda_rng_state(self._load_recovery['rng_state'])

try:
paddle.set_cuda_rng_state(self._load_recovery['rng_state'])
except:
raise ValueError("Set rng state failed. This may be caused by that the current device resources are different with the"
" model's you are loading now. Please Check the cuda device count and specify same CUDA_VISIBLE_DEVICES with the model to load the rng states correctly. ")

for epoch_index in range(start_epoch, epoch):
train_epoch_start = get_timestamp()
self._train_one_epoch(epoch_index, train_data_loader,
Expand Down Expand Up @@ -745,16 +750,17 @@ def load(self):
raise ValueError(
"No optimizer checkpoint file found in %s." % opt_path)

if os.path.exists(meta_path):
if os.path.exists(meta_path) and self._load_meta_state:
meta_dict = paddle.load(meta_path)
self._load_recovery = {
'step': meta_dict['step'],
'epoch': meta_dict['epoch'],
'rng_state': meta_dict['cuda_rng_state']
}
else:
raise ValueError("No meta checkpoint file found in %s." %
meta_path)
if self._load_meta_state:
raise ValueError("No meta checkpoint file found in %s." %
meta_path)

logger.info("successfully load checkpoints")
else:
Expand Down