-
Notifications
You must be signed in to change notification settings - Fork 198
Avoid save_to_memory running too fast then causing save_to_storage to fail. #1585
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,8 +204,16 @@ def __init__( | |
| name=CheckpointSharedObjPrefix.SAVE_STEP_QNAME + str(0), | ||
| create=False, | ||
| ) | ||
| self._notify_queue = SharedQueue( | ||
| name=CheckpointSharedObjPrefix.SAVE_STEP_QNAME | ||
|
Collaborator
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. implement this magic concatenation as a method of |
||
| + str(0) | ||
| + "_notify", | ||
| create=False, | ||
| ) | ||
| else: | ||
| self._event_queue = None # type: ignore | ||
| self._notify_queue = None # type: ignore | ||
| self._checkpoint_event_step = -1 | ||
| self._update_saver_config() | ||
|
|
||
| # lock for shared memory | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,6 +487,11 @@ def save_to_memory(self, step, state_dict, paths: Dict[str, str]): | |
| if self._local_rank != self.local_shard_id: | ||
| return False | ||
|
|
||
| if self._checkpoint_event_step > 0: | ||
|
Collaborator
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. move this part into parent class(engine) |
||
| notify_event = self._notify_queue.get() | ||
| assert notify_event.step == self._checkpoint_event_step | ||
| self._checkpoint_event_step = -1 | ||
|
|
||
| acquired = self._shm_lock.acquire(blocking=False) | ||
| all_rank_ready = check_all_rank_ready(self._saver_group, acquired) | ||
| if not all_rank_ready: | ||
|
|
@@ -548,6 +553,7 @@ def save_to_storage(self, step, state_dict, paths: Dict[str, str]): | |
| ) | ||
| event = CheckpointEvent(type=CheckpointEventType.SAVE, step=step) | ||
| self._event_queue.put(event) | ||
| self._checkpoint_event_step = step | ||
| if success: | ||
| self.latest_step = step | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,10 @@ def save_to_memory(self, step, state_dict, paths: Dict[str, str]): | |
| ["model_states", "optim_states"] of the state dict and | ||
| the value is the path of storage to save. | ||
| """ | ||
| if self._checkpoint_event_step > 0: | ||
| notify_event = self._notify_queue.get() | ||
| assert notify_event.step == self._checkpoint_event_step | ||
|
Collaborator
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. what's ur intention if assert is false? |
||
| self._checkpoint_event_step = -1 | ||
| conf = CheckpointConfig(step=step, paths=paths) | ||
| return self.save_state_dict_to_memory(state_dict, conf) | ||
|
|
||
|
|
@@ -140,6 +144,7 @@ def save_to_storage(self, step, state_dict, paths): | |
| if success and self._rank == 0: | ||
| event = CheckpointEvent(type=CheckpointEventType.SAVE, step=step) | ||
| self._event_queue.put(event) | ||
| self._checkpoint_event_step = step | ||
| if success: | ||
| self.latest_step = step | ||
| return success | ||
|
|
||
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.
All ranks should expect a notify to drain their local shard queue