Skip to content

[XPU][MaskedSelect] Fix masked_select_grad true_count and empty-out h… - #76906

Merged
QingshuChen merged 1 commit into
PaddlePaddle:developfrom
bigwhite37:fix/xpu-masked-select-grad-true-count
Dec 16, 2025
Merged

QingshuChen merged 1 commit into
PaddlePaddle:developfrom
bigwhite37:fix/xpu-masked-select-grad-true-count

Conversation

@bigwhite37

@bigwhite37 bigwhite37 commented Dec 14, 2025 •

Copy link
Copy Markdown
Contributor

PR Category

Custom Device

PR Types

Bug fixes

Description

  • Fix XPU masked_select_grad to pass the correct true_count (out_grad.numel()) to the underlying XDNN API instead of a constant.
  • Add an early return for empty out_grad (e.g. all-false mask) by filling x_grad with zeros to avoid XDNN invalid-parameter errors.
  • Add XPU unit tests in paddle/test/xpu/test_masked_select_op_xpu.py covering Tensor.getitem bool-mask int64 grad for both non-empty and empty output cases.

@paddle-bot

paddle-bot Bot commented Dec 14, 2025

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the XPU label Dec 14, 2025
@bigwhite37 bigwhite37 closed this Dec 14, 2025
@bigwhite37 bigwhite37 reopened this Dec 14, 2025
@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-cancelled

@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

return;
}
// If out_grad is empty (e.g. mask all false), x_grad should be all zeros.
if (out_grad.numel() == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里会有nullptr风险,写法和GPU对齐吧
参考:#76905 #73180

@bigwhite37
bigwhite37 force-pushed the fix/xpu-masked-select-grad-true-count branch from 29da1ea to e3ddabc Compare December 14, 2025 12:54

@cqulilujia cqulilujia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-cancelled

@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

2 similar comments
@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

DenseTensor* x_grad) {
using XPUType = typename XPUTypeTrait<T>::Type;
dev_ctx.template Alloc<T>(x_grad);
if (x_grad->numel() == 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

参考下一个写法, 如果x_grad有可能为null, x_grad->numel调用就有问题.

@bigwhite37
bigwhite37 force-pushed the fix/xpu-masked-select-grad-true-count branch from e3ddabc to f9257db Compare December 15, 2025 09:21
@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

1 similar comment
@bigwhite37

Copy link
Copy Markdown
Contributor Author

/re-run all-failed

@QingshuChen
QingshuChen merged commit 4dcbd4e into PaddlePaddle:develop Dec 16, 2025
104 of 110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants