Skip to content

[Accuracy diff No.72] Fix accuracy diff for trace API #73018

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

Merged
merged 2 commits into from
Jun 5, 2025
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
8 changes: 4 additions & 4 deletions paddle/phi/kernels/funcs/diagonal.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ DenseTensor Diagonal(const DeviceContext& context,
auto input_stride = common::stride(input_dims);
auto dim1_ = dim1 < 0 ? input_dims.size() + dim1 : dim1;
auto dim2_ = dim2 < 0 ? input_dims.size() + dim2 : dim2;
auto len1 = input_dims[std::min(dim1_, dim2_)];
auto len2 = input_dims[std::max(dim1_, dim2_)];
auto stride1 = input_stride[std::min(dim1_, dim2_)];
auto stride2 = input_stride[std::max(dim1_, dim2_)];
auto len1 = input_dims[dim1_];
auto len2 = input_dims[dim2_];
auto stride1 = input_stride[dim1_];
auto stride2 = input_stride[dim2_];

int offset_stride = 0;
if (offset >= 0) {
Expand Down
8 changes: 4 additions & 4 deletions paddle/phi/kernels/impl/trace_grad_kernel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ void TraceGradKernel(const Context& ctx,
auto dim2 = axis2;
auto dim1_ = dim1 < 0 ? input_dims.size() + dim1 : dim1;
auto dim2_ = dim2 < 0 ? input_dims.size() + dim2 : dim2;
auto len1 = input_dims[std::min(dim1_, dim2_)];
auto len2 = input_dims[std::max(dim1_, dim2_)];
auto stride1 = input_stride[std::min(dim1_, dim2_)];
auto stride2 = input_stride[std::max(dim1_, dim2_)];
auto len1 = input_dims[dim1_];
auto len2 = input_dims[dim2_];
auto stride1 = input_stride[dim1_];
auto stride2 = input_stride[dim2_];

int offset_stride = 0;
if (offset >= 0) {
Expand Down
13 changes: 13 additions & 0 deletions test/legacy_test/test_trace_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ def init_config(self):
)


class TestTraceOpCase4(TestTraceOp):
def init_config(self):
self.case = np.random.randn(2, 30, 3).astype('float64')
self.inputs = {'Input': self.case}
self.attrs = {'offset': -1, 'axis1': 2, 'axis2': -2}
self.target = np.trace(
self.inputs['Input'],
offset=self.attrs['offset'],
axis1=self.attrs['axis1'],
axis2=self.attrs['axis2'],
)


class TestTraceFP16Op1(TestTraceOp):
def init_config(self):
self.dtype = np.float16
Expand Down
Loading