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

[XPU] support unified ckpt function #9312

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions paddlenlp/trainer/plugins/unified_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@
else:
local_resume = False
local_resume = paddle.to_tensor([local_resume])
dist.all_reduce(local_resume, op=dist.ReduceOp.PROD)
dist.all_reduce(local_resume, op=dist.ReduceOp.MIN)

Check warning on line 1310 in paddlenlp/trainer/plugins/unified_checkpoint.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/plugins/unified_checkpoint.py#L1310

Added line #L1310 was not covered by tests
local_resume = local_resume.item()
return local_resume

Expand Down Expand Up @@ -1425,7 +1425,7 @@
else:
local_resume = False
local_resume = paddle.to_tensor([local_resume])
dist.all_reduce(local_resume, op=dist.ReduceOp.PROD)
dist.all_reduce(local_resume, op=dist.ReduceOp.MIN)

Check warning on line 1428 in paddlenlp/trainer/plugins/unified_checkpoint.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/plugins/unified_checkpoint.py#L1428

Added line #L1428 was not covered by tests
return local_resume.item()

# check whether the optimizer checkpoint files are complete.
Expand Down
6 changes: 6 additions & 0 deletions paddlenlp/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,12 @@
for i in range(core.get_cuda_device_count()):
core.default_cuda_generator(i).set_state(checkpoint_rng_state["cuda"][i])

if core.is_compiled_with_xpu():
if not len(checkpoint_rng_state["cuda"]) == core.get_xpu_device_count():
raise ValueError("Length of xpu state list shoule be equal to the xpu device count")
for i in range(core.get_xpu_device_count()):
core.default_xpu_generator(i).set_state(checkpoint_rng_state["cuda"][i])

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

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/trainer.py#L1796-L1800

Added lines #L1796 - L1800 were not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 xpu 很下面 custom device 处理会有不同吗?更适合框架测修改吧。

Copy link
Contributor Author

@cqulilujia cqulilujia Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在框架侧的device上XPU和GPU、CPU是同一级别的,custom device(如海光、昇腾等)是放在一起的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


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:
Expand Down
Loading