-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 checkpoint #945
Open
zhangsmallshark
wants to merge
1
commit into
microsoft:master
Choose a base branch
from
zhangsmallshark:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−14
Open
add checkpoint #945
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,16 @@ | |
|
||
import torch | ||
|
||
from megatron import update_num_microbatches | ||
from megatron.core import mpu, tensor_parallel | ||
from .global_vars import get_args | ||
from .utils import (unwrap_model, | ||
print_rank_0) | ||
# from megatron.core import mpu, tensor_parallel | ||
# from .global_vars import get_args | ||
# from .utils import (unwrap_model, | ||
# print_rank_0) | ||
|
||
# from megatron import update_num_microbatches | ||
import domino.parallel_state as mpu | ||
from domino.tensor_parallel.random import get_cuda_rng_tracker | ||
from domino.arguments import get_args | ||
from domino.utils import unwrap_model, print_rank_0 | ||
|
||
_CHECKPOINT_VERSION = None | ||
|
||
|
@@ -194,7 +198,7 @@ def get_rng_state(): | |
'np_rng_state': np.random.get_state(), | ||
'torch_rng_state': torch.get_rng_state(), | ||
'cuda_rng_state': torch.cuda.get_rng_state(), | ||
'rng_tracker_states': tensor_parallel.get_cuda_rng_tracker().get_states()} | ||
'rng_tracker_states': get_cuda_rng_tracker().get_states()} | ||
|
||
rng_state_list = None | ||
if torch.distributed.is_initialized() and \ | ||
|
@@ -218,6 +222,8 @@ def save_checkpoint(iteration, model, optimizer, opt_param_scheduler): | |
|
||
# Only rank zero of the data parallel writes to the disk. | ||
model = unwrap_model(model) | ||
model_module = model.module | ||
model = [model_module] | ||
|
||
print_rank_0('saving checkpoint at iteration {:7d} to {}'.format( | ||
iteration, args.save)) | ||
|
@@ -241,7 +247,7 @@ def save_checkpoint(iteration, model, optimizer, opt_param_scheduler): | |
|
||
# Arguments, iteration, and model. | ||
state_dict = {} | ||
state_dict['args'] = args | ||
# state_dict['args'] = args | ||
state_dict['checkpoint_version'] = 3.0 | ||
state_dict['iteration'] = iteration | ||
if len(model) == 1: | ||
|
@@ -503,6 +509,8 @@ def load_checkpoint(model, optimizer, opt_param_scheduler, load_arg='load', stri | |
load_dir = getattr(args, load_arg) | ||
|
||
model = unwrap_model(model) | ||
model_module = model.module | ||
model = [model_module] | ||
|
||
state_dict, checkpoint_name, release = _load_base_checkpoint(load_dir, rank0=False) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no
|
||
|
@@ -522,6 +530,7 @@ def load_checkpoint(model, optimizer, opt_param_scheduler, load_arg='load', stri | |
set_checkpoint_version(state_dict.get('checkpoint_version', 0)) | ||
|
||
# Set iteration. | ||
args.finetune = False | ||
if args.finetune or release: | ||
iteration = 0 | ||
else: | ||
|
@@ -544,7 +553,7 @@ def load_checkpoint(model, optimizer, opt_param_scheduler, load_arg='load', stri | |
check_checkpoint_args(checkpoint_args) | ||
args.consumed_train_samples = getattr(checkpoint_args, | ||
'consumed_train_samples', 0) | ||
update_num_microbatches(consumed_samples=args.consumed_train_samples) | ||
# update_num_microbatches(consumed_samples=args.consumed_train_samples) | ||
args.consumed_valid_samples = getattr(checkpoint_args, | ||
'consumed_valid_samples', 0) | ||
else: | ||
|
@@ -614,7 +623,7 @@ def load_checkpoint(model, optimizer, opt_param_scheduler, load_arg='load', stri | |
# Check for empty states array | ||
if not rng_state['rng_tracker_states']: | ||
raise KeyError | ||
tensor_parallel.get_cuda_rng_tracker().set_states( | ||
get_cuda_rng_tracker().set_states( | ||
rng_state['rng_tracker_states']) | ||
else: # backward compatability | ||
random.setstate(state_dict['random_rng_state']) | ||
|
@@ -624,7 +633,7 @@ def load_checkpoint(model, optimizer, opt_param_scheduler, load_arg='load', stri | |
# Check for empty states array | ||
if not state_dict['rng_tracker_states']: | ||
raise KeyError | ||
tensor_parallel.get_cuda_rng_tracker().set_states( | ||
get_cuda_rng_tracker().set_states( | ||
state_dict['rng_tracker_states']) | ||
except KeyError: | ||
print_rank_0('Unable to load rng state from checkpoint {}. ' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this line. Otherwise, the
args.iteration
is wrong if the checkpoint is successfully loaded.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do we need to change
args.train_iters
?args.iteration
may be larger thanargs.train_iters
if there is a checkpoint.