forked from pytorch/xla
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
54 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
class ExecState: | ||
def __init__(self): | ||
self._index_to_fsdp_module = {} | ||
self._fsdp_module_to_index = {} | ||
self._iter = 0 | ||
self._current_index = 0 | ||
|
||
@property | ||
def is_first_iter(self) -> bool: | ||
return self._iter == 0 | ||
|
||
def record_forward(self, fsdp_module): | ||
if self.is_first_iter: | ||
assert fsdp_module not in self._fsdp_module_to_index | ||
self._index_to_fsdp_module[self._current_index] = fsdp_module | ||
self._fsdp_module_to_index[fsdp_module] = self._current_index | ||
self._current_index += 1 | ||
else: | ||
assert fsdp_module in self._fsdp_module_to_index | ||
assert self._fsdp_module_to_index[fsdp_module] == self._current_index, \ | ||
"FSDP module is not in the same execution order as first iteration." | ||
self._current_index += 1 | ||
|
||
|
||
def get_prefetch_module(self): | ||
if self.is_first_iter: | ||
return None | ||
if self._current_index >= len(self._index_to_fsdp_module): | ||
return None | ||
return self._index_to_fsdp_module[self._current_index] | ||
def __init__(self): | ||
self._index_to_fsdp_module = {} | ||
self._fsdp_module_to_index = {} | ||
self._iter = 0 | ||
self._current_index = 0 | ||
|
||
@property | ||
def is_first_iter(self) -> bool: | ||
return self._iter == 0 | ||
|
||
def next_iter(self): | ||
self._iter += 1 | ||
self._current_index = 0 | ||
def record_forward(self, fsdp_module): | ||
if self.is_first_iter: | ||
assert fsdp_module not in self._fsdp_module_to_index | ||
self._index_to_fsdp_module[self._current_index] = fsdp_module | ||
self._fsdp_module_to_index[fsdp_module] = self._current_index | ||
self._current_index += 1 | ||
else: | ||
assert fsdp_module in self._fsdp_module_to_index | ||
assert self._fsdp_module_to_index[fsdp_module] == self._current_index, \ | ||
"FSDP module is not in the same execution order as first iteration." | ||
self._current_index += 1 | ||
|
||
def get_prefetch_module(self): | ||
if self.is_first_iter: | ||
return None | ||
if self._current_index >= len(self._index_to_fsdp_module): | ||
return None | ||
return self._index_to_fsdp_module[self._current_index] | ||
|
||
def next_iter(self): | ||
self._iter += 1 | ||
self._current_index = 0 |
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