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

[Trainer] Saving rng state not seed. #8185

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
10 changes: 5 additions & 5 deletions paddlenlp/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,20 +1614,20 @@

core = paddle.framework.core

core.default_cpu_generator().manual_seed(checkpoint_rng_state["cpu"])
core.default_cpu_generator().set_state(checkpoint_rng_state["cpu"])
if core.is_compiled_with_cuda():
if not len(checkpoint_rng_state["cuda"]) == core.get_cuda_device_count():
raise ValueError("Length of gpu state list shoule be equal to the gpu device count")
for i in range(core.get_cuda_device_count()):
core.default_cuda_generator(i).manual_seed(checkpoint_rng_state["cuda"][i])
core.default_cuda_generator(i).set_state(checkpoint_rng_state["cuda"][i])

Check warning on line 1622 in paddlenlp/trainer/trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/trainer.py#L1622

Added line #L1622 was not covered by tests

if paddle.device.get_all_custom_device_type() is not None:
custom_device_type = paddle.device.get_all_custom_device_type()
for device in custom_device_type:
if not len(checkpoint_rng_state["cuda"]) == core.get_custom_device_count(device):
raise ValueError("Length of custom device state list shoule be equal to the custom device count")
for i in range(core.get_custom_device_count(device)):
core.default_custom_device_generator(paddle.CustomPlace(device, i)).manual_seed(
core.default_custom_device_generator(paddle.CustomPlace(device, i)).set_state(

Check warning on line 1630 in paddlenlp/trainer/trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/trainer.py#L1630

Added line #L1630 was not covered by tests
checkpoint_rng_state["cuda"][i]
)

Expand Down Expand Up @@ -2203,8 +2203,8 @@
rng_states = {
"python": random.getstate(),
"numpy": np.random.get_state(),
"cuda": [k.current_seed() for k in paddle.get_rng_state()],
"cpu": paddle.framework.core.default_cpu_generator().get_state().current_seed(),
"cuda": paddle.get_rng_state(),
"cpu": paddle.framework.core.default_cpu_generator().get_state(),
}
if self.args.use_hybrid_parallel:
rng_states[
Expand Down
Loading