-
Notifications
You must be signed in to change notification settings - Fork 1
Check devices matching during load random seed for device. #48
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |||||
| import torch | ||||||
| import tyro | ||||||
| from .model_dict import model_dict, ModelProto, NetworkProto | ||||||
| from .random_engine import load_random_engine_state | ||||||
| from .random_engine import dump_random_engine_state, load_random_engine_state | ||||||
|
|
||||||
|
|
||||||
| @dataclasses.dataclass | ||||||
|
|
@@ -77,6 +77,7 @@ def save(self, data: typing.Any, step: int) -> None: | |||||
| """ | ||||||
| Save data to checkpoint. | ||||||
| """ | ||||||
| data["random"] = {"host": torch.get_rng_state(), "device": dump_random_engine_state(self.device), "device_type": self.device.type} | ||||||
| data_pth = self.folder() / "data.pth" | ||||||
| local_data_pth = self.folder() / f"data.{step}.pth" | ||||||
| torch.save(data, local_data_pth) | ||||||
|
|
@@ -151,7 +152,10 @@ def main(self, *, model_param: typing.Any = None, network_param: typing.Any = No | |||||
| elif "random" in data: | ||||||
| logging.info("Loading random seed from the checkpoint") | ||||||
| torch.set_rng_state(data["random"]["host"]) | ||||||
| load_random_engine_state(data["random"]["device"], self.device) | ||||||
| if data["random"]["device_type"] == self.device.type: | ||||||
|
||||||
| if data["random"]["device_type"] == self.device.type: | |
| if data["random"]["device"] == str(self.device): |
Copilot
AI
Jun 18, 2025
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.
[nitpick] This skip notice might warrant a logging.warning (or a lower debug level) instead of info, to better surface potential misconfiguration.
| logging.info("Skipping loading random engine state for device since the device type does not match") | |
| logging.warning("Skipping loading random engine state for device since the device type does not match") |
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.
Storing only the device type may lead to mismatches on multi-GPU setups (e.g., cuda:0 vs cuda:1). Consider saving the full device spec (such as
str(self.device)or the device index) to ensure the random state is loaded onto the correct device.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.
多GPU情况下会出现问题吗?我怎么觉得不会?