Skip to content

Conversation

@DanielSun11
Copy link
Contributor

PR Category

Execute Infrastructure

PR Types

Improvements

Description

使得DenseTensor::Slice支持begin_index和end_index相等,即切分完为0-size Tensor。
holder_没有使用原来的,而是创建了一个没有实际数据的holder

测试代码:

paddle/fluid/pybind/eager_functions.cc 中添加:

PyObject* eager__for_test_dense_tensor_slice(PyObject* self, PyObject* args, PyObject* kwargs) { EAGER_TRY auto input_tensor = CastPyArg2Tensor(PyTuple_GET_ITEM(args, 0), 0); auto tensor = paddle::Tensor(); auto dense_tensor = std::dynamic_pointer_cast<phi::DenseTensor>(input_tensor.impl()); int64_t begin_index = 0; int64_t end_index = 0; auto res = dense_tensor->Slice(begin_index, end_index); tensor.set_impl(std::make_shared<phi::DenseTensor>(res)); return ToPyObject(tensor); EAGER_CATCH_AND_THROW_RETURN_NULL }

编写python文件调用eager测试代码:

import paddle shape = [2, 3, 4] x = paddle.randn(shape) sliced = paddle.base.core.eager.__for_test_dense_tensor_slice(x) print("sliced: ",sliced) res = sliced.sum(axis = -1) print("res: ",res)

输出结果:
07678c16ed7260055b09332856c26682

pcard-67164

@paddle-bot
Copy link

paddle-bot bot commented Jun 16, 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.

@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 10 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@1cfac00). Learn more about missing BASE report.

Files with missing lines Patch % Lines
paddle/phi/core/dense_tensor_impl.cc 16.66% 10 Missing ⚠️

❌ Your patch status has failed because the patch coverage (16.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@ Coverage Diff @@ ## develop #73377 +/- ## ========================================== Coverage ? 16.66% ========================================== Files ? 1 Lines ? 12 Branches ? 0 ========================================== Hits ? 2 Misses ? 10 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.
@luotao1 luotao1 merged commit a269d77 into PaddlePaddle:develop Jun 17, 2025
47 of 50 checks passed
@DanielSun11 DanielSun11 deleted the fix_slice branch September 18, 2025 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants