Skip to content

Conversation

@co63oc
Copy link
Contributor

@co63oc co63oc commented Jun 21, 2025

PR Category

Execute Infrastructure

PR Types

Improvements

Description

index_add

paddle/phi/infermeta/binary.cc 取消检查,symbolic 推导没有对应代码

out 维度和x 维度相同,反向时 value填充0,torch不支持x, value不同shape,反向时value为0-size

import torch
x = torch.randn([3, 0])
value = torch.randn([3, 1])
x.requires_grad=True
value.requires_grad=True
out = torch.index_add(x, 0, torch.randn([3]).type(torch.int32), value)
out.sum().backward()
print(x.grad)
print(value.grad)

RuntimeError: source tensor shape must match self tensor shape, excluding the specified dimension. Got self.shape = [3, 0] source.shape = [3, 1]

PaddleAPITest中有index 为0-size测试,但是torch index_add并不支持
image

import torch
torch.index_add(torch.randn([101, 3]), 0, torch.randn([0]).type(torch.int32), torch.randn([3, 3]))

RuntimeError: index_add_(): Number of indices (0) should be equal to source.size(dim): (3), for dim: 0

PaddleAPITest 使用的是其他组合计算
image

paddle组合实现代码,当前代码没有支持value的反向,没有增加index 为0-size 的单测

import torch
x = torch.randn([10, 3])
index = torch.randn([0]).type(torch.int64)
axis = 0
value = torch.randn([10, 3])
x.requires_grad = True
value.requires_grad = True

for i in range(len(index)):
    if index[i].item() >= x.size(axis):
        continue
    tmp = x.select(dim=axis, index=index[i].item())
    tmp += value.select(dim=axis, index=i)
result = x
result.sum().backward()

print(value.grad)

None

PaddleAPITest测试通过,错误为numpy error
image

@paddle-bot
Copy link

paddle-bot bot commented Jun 21, 2025

你的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 contributor External developers label Jun 21, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Please upload report for BASE (develop@3c5a95c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
paddle/phi/kernels/cpu/index_add_grad_kernel.cc 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #73517   +/-   ##
==========================================
  Coverage           ?    0.00%           
==========================================
  Files              ?        1           
  Lines              ?        5           
  Branches           ?        0           
==========================================
  Hits               ?        0           
  Misses             ?        5           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@co63oc
Copy link
Contributor Author

co63oc commented Jun 21, 2025

/re-run all-failed

@co63oc co63oc changed the title CI测试不review index_add [0-size Tensor No.36] Add 0-size Tensor support for index_add Jun 22, 2025
@co63oc co63oc changed the title [0-size Tensor No.36] Add 0-size Tensor support for index_add [0-size Tensor Job2 No.36] Add 0-size Tensor support for index_add Jun 22, 2025
@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Jun 23, 2025
Copy link
Contributor

@DanielSun11 DanielSun11 left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit e6cae37 into PaddlePaddle:develop Jun 24, 2025
88 of 93 checks passed
@co63oc co63oc deleted the f34 branch June 30, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 skip-ci: approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants