Skip to content

Commit

Permalink
Merge pull request #28 from jim19930609/merge
Browse files Browse the repository at this point in the history
Fixed python-c api
  • Loading branch information
JiabinYang authored Nov 19, 2021
2 parents 7273a4f + 8001ef3 commit 93eaa45
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ if(WITH_PYTHON)

cc_library(paddle_eager
SRCS eager.cc eager_functions.cc eager_method.cc eager_properties.cc eager_utils.cc
DEPS eager_api autograd_meta backward grad_node_info pten)
DEPS eager_api accumulation_node autograd_meta backward grad_node_info pten)
list(APPEND PYBIND_DEPS paddle_eager)

cc_library(paddle_pybind SHARED
Expand Down
8 changes: 8 additions & 0 deletions paddle/fluid/pybind/eager_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License. */
#include <string>
#include <vector>

#include "paddle/fluid/eager/accumulation/accumulation_node.h"
#include "paddle/fluid/eager/api/all.h"
#include "paddle/fluid/eager/autograd_meta.h"
#include "paddle/fluid/eager/backward.h"
Expand All @@ -30,6 +31,7 @@ limitations under the License. */
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/pybind/eager.h"
#include "paddle/fluid/pybind/eager_utils.h"
#include "paddle/pten/api/lib/utils/allocator.h"
#include "paddle/pten/api/lib/utils/storage.h"
#include "paddle/pten/api/lib/utils/tensor_utils.h"
#include "paddle/pten/common/data_type.h"
Expand Down Expand Up @@ -155,6 +157,12 @@ static inline PyObject* eager_api_numpy_to_tensor(
v->eagertensor.set_name(egr::Controller::Instance().GenerateUniqueName());
auto meta = egr::EagerUtils::autograd_meta(&(v->eagertensor));
meta->SetStopGradient(stop_gradient);

// Created tensor will be leaf tensor
// So we append AccumulationNode to it.
auto accumulation_node = std::make_shared<egr::GradNodeAccumulation>();
meta->SetGradNode(accumulation_node);

// TODO(jiabin): Shall we increase ref cnt here to make python ref cnt num
// correctly?
} else {
Expand Down
11 changes: 11 additions & 0 deletions paddle/fluid/pybind/eager_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ static PyObject* eager_tensor_method_numpy(EagerTensorObject* self,
place, reinterpret_cast<void*>(
(reinterpret_cast<PyArrayObject_fields*>(array))->data),
place, dense_tensor->data(), sizeof_dtype * numel);
#if defined(PADDLE_WITH_CUDA)
} else if (self->eagertensor.is_cuda()) {
auto dense_tensor =
std::dynamic_pointer_cast<pten::DenseTensor>(self->eagertensor.impl());

paddle::platform::GpuMemcpySync(
(reinterpret_cast<PyArrayObject_fields*>(array))->data,
dense_tensor->data(),
pten::DataTypeSize(dense_tensor->dtype()) * dense_tensor->numel(),
cudaMemcpyDeviceToHost);
#endif
} else {
PADDLE_THROW(platform::errors::InvalidArgument(
"Tensor.numpy() only support cpu tensor."));
Expand Down
8 changes: 8 additions & 0 deletions paddle/fluid/pybind/eager_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ PyObject* eager_tensor_properties_get_stop_gradient(EagerTensorObject* self,
return ToPyObject(meta->StopGradient());
}

PyObject* eager_tensor_properties_get_grad(EagerTensorObject* self,
void* closure) {
auto meta = egr::EagerUtils::unsafe_autograd_meta(self->eagertensor);
return ToPyObject(meta->Grad());
}

int eager_tensor_properties_set_stop_gradient(EagerTensorObject* self,
PyObject* value, void* closure) {
auto meta = egr::EagerUtils::unsafe_autograd_meta(self->eagertensor);
Expand Down Expand Up @@ -116,6 +122,8 @@ PyObject* eager_tensor_properties_get_dtype(EagerTensorObject* self,
}

struct PyGetSetDef variable_properties[] = {
{"grad", (getter)eager_tensor_properties_get_grad, nullptr, nullptr,
nullptr},
{"name", (getter)eager_tensor_properties_get_name,
(setter)eager_tensor_properties_set_name, nullptr, nullptr},
{"stop_gradient", (getter)eager_tensor_properties_get_stop_gradient,
Expand Down

1 comment on commit 93eaa45

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 93eaa45 Nov 19, 2021

Choose a reason for hiding this comment

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

🕵️ CI failures summary

🔍 PR: #28 Commit ID: 93eaa45 contains failed CI.

🔹 Failed: PR-CI-ROCM-Compile

Unknown Failed
2021-11-19 18:24:20 + git pull upstream develop
2021-11-19 18:24:21 From https://github.com/PaddlePaddle/Paddle
2021-11-19 18:24:21 * branch develop -> FETCH_HEAD
2021-11-19 18:24:22 Auto-merging python/setup.py.in
2021-11-19 18:24:22 Auto-merging paddle/pten/api/include/tensor.h
2021-11-19 18:24:22 Auto-merging paddle/fluid/pybind/pybind.cc
2021-11-19 18:24:22 Auto-merging paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:24:22 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:24:22 Auto-merging paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:24:22 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:24:22 Auto-merging paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:24:22 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:24:22 Auto-merging paddle/fluid/eager/eager_tensor.h
2021-11-19 18:24:22 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/eager_tensor.h
2021-11-19 18:24:22 Auto-merging paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:24:22 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:24:22 Auto-merging paddle/fluid/CMakeLists.txt
2021-11-19 18:24:22 CONFLICT (content): Merge conflict in paddle/fluid/CMakeLists.txt
2021-11-19 18:24:22 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-Inference

failed in build-docker-image job
failed in build-docker-image job

🔹 Failed: PR-CI-GpuPS

failed in build-docker-image job
failed in build-docker-image job

🔹 Failed: PR-CI-iScan-C

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-musl

Unknown Failed
2021-11-19 18:29:47 + git config --global user.name PaddleCI
2021-11-19 18:29:47 + git config --global user.email paddle_ci@example.com
2021-11-19 18:29:47 + git merge --no-edit develop
2021-11-19 18:29:48 Auto-merging python/setup.py.in
2021-11-19 18:29:48 Auto-merging paddle/pten/api/include/tensor.h
2021-11-19 18:29:48 Auto-merging paddle/fluid/pybind/pybind.cc
2021-11-19 18:29:48 Auto-merging paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:29:48 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:29:48 Auto-merging paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:29:48 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:29:48 Auto-merging paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:29:48 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:29:48 Auto-merging paddle/fluid/eager/eager_tensor.h
2021-11-19 18:29:48 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/eager_tensor.h
2021-11-19 18:29:48 Auto-merging paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:29:48 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:29:48 Auto-merging paddle/fluid/CMakeLists.txt
2021-11-19 18:29:48 CONFLICT (content): Merge conflict in paddle/fluid/CMakeLists.txt
2021-11-19 18:29:48 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-Windows

Unknown Failed
2021-11-19 18:39:24 C:\Users\Administrator\Downloads\workspace\1e74a057-ea2c-4b91-a466-d9b799077722\Paddle>if 0 NEQ 0 exit /b 1
2021-11-19 18:39:24 C:\Users\Administrator\Downloads\workspace\1e74a057-ea2c-4b91-a466-d9b799077722\Paddle>git merge --no-edit develop
2021-11-19 18:39:25 Auto-merging python/setup.py.in
2021-11-19 18:39:25 Auto-merging paddle/pten/api/include/tensor.h
2021-11-19 18:39:25 Auto-merging paddle/fluid/pybind/pybind.cc
2021-11-19 18:39:25 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:39:25 Auto-merging paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:39:25 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:39:25 Auto-merging paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:39:25 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:39:25 Auto-merging paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:39:25 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/eager_tensor.h
2021-11-19 18:39:25 Auto-merging paddle/fluid/eager/eager_tensor.h
2021-11-19 18:39:25 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:39:25 Auto-merging paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:39:25 Auto-merging paddle/fluid/CMakeLists.txt
2021-11-19 18:39:25 CONFLICT (content): Merge conflict in paddle/fluid/CMakeLists.txt
2021-11-19 18:39:25 Automatic merge failed; fix conflicts and then commit the result.
2021-11-19 18:39:25 C:\Users\Administrator\Downloads\workspace\1e74a057-ea2c-4b91-a466-d9b799077722\Paddle>if 1 NEQ 0 exit /b 1

🔹 Failed: PR-CI-Windows-Inference

Unknown Failed
2021-11-19 18:46:32 C:\Users\Administrator\Downloads\workspace\3d95563e-c53d-4ba7-92f8-487db538a129\Paddle>if 0 NEQ 0 exit /b 1
2021-11-19 18:46:32 C:\Users\Administrator\Downloads\workspace\3d95563e-c53d-4ba7-92f8-487db538a129\Paddle>git merge --no-edit develop
2021-11-19 18:46:32 Auto-merging python/setup.py.in
2021-11-19 18:46:32 Auto-merging paddle/pten/api/include/tensor.h
2021-11-19 18:46:32 Auto-merging paddle/fluid/pybind/pybind.cc
2021-11-19 18:46:32 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:46:32 Auto-merging paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:46:32 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:46:32 Auto-merging paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:46:32 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:46:32 Auto-merging paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:46:32 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/eager_tensor.h
2021-11-19 18:46:32 Auto-merging paddle/fluid/eager/eager_tensor.h
2021-11-19 18:46:32 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:46:32 Auto-merging paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:46:32 Auto-merging paddle/fluid/CMakeLists.txt
2021-11-19 18:46:32 CONFLICT (content): Merge conflict in paddle/fluid/CMakeLists.txt
2021-11-19 18:46:32 Automatic merge failed; fix conflicts and then commit the result.
2021-11-19 18:46:32 C:\Users\Administrator\Downloads\workspace\3d95563e-c53d-4ba7-92f8-487db538a129\Paddle>if 1 NEQ 0 exit /b 1

🔹 Failed: PR-CI-APPROVAL

Unknown Failed
2021-11-19 18:54:37 切换到一个新分支 'test_pr'
2021-11-19 18:54:37 分支 'test_pr' 设置为跟踪来自 'upstream' 的远程分支 'develop'。
2021-11-19 18:54:37 + git merge --no-edit origin_pr
2021-11-19 18:54:37 自动合并 python/setup.py.in
2021-11-19 18:54:37 自动合并 paddle/pten/api/include/tensor.h
2021-11-19 18:54:37 自动合并 paddle/fluid/pybind/pybind.cc
2021-11-19 18:54:37 冲突(add/add):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:54:37 自动合并 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 18:54:37 冲突(add/add):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:54:37 自动合并 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 18:54:37 冲突(add/add):合并冲突于 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:54:37 自动合并 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 18:54:37 冲突(add/add):合并冲突于 paddle/fluid/eager/eager_tensor.h
2021-11-19 18:54:37 自动合并 paddle/fluid/eager/eager_tensor.h
2021-11-19 18:54:37 冲突(add/add):合并冲突于 paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:54:37 自动合并 paddle/fluid/eager/CMakeLists.txt
2021-11-19 18:54:37 自动合并 paddle/fluid/CMakeLists.txt
2021-11-19 18:54:37 冲突(内容):合并冲突于 paddle/fluid/CMakeLists.txt
2021-11-19 18:54:37 自动合并失败,修正冲突然后提交修正的结果。

🔹 Failed: PR-CI-iScan-Python

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-NPU

Unknown Failed
2021-11-19 19:00:12 + git pull upstream develop
2021-11-19 19:00:17 From https://github.com/PaddlePaddle/Paddle
2021-11-19 19:00:17 * branch develop -> FETCH_HEAD
2021-11-19 19:00:19 Auto-merging python/setup.py.in
2021-11-19 19:00:19 Auto-merging paddle/pten/api/include/tensor.h
2021-11-19 19:00:19 Auto-merging paddle/fluid/pybind/pybind.cc
2021-11-19 19:00:19 Auto-merging paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 19:00:19 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 19:00:19 Auto-merging paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 19:00:19 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 19:00:19 Auto-merging paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 19:00:19 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 19:00:19 Auto-merging paddle/fluid/eager/eager_tensor.h
2021-11-19 19:00:19 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/eager_tensor.h
2021-11-19 19:00:19 Auto-merging paddle/fluid/eager/CMakeLists.txt
2021-11-19 19:00:19 CONFLICT (add/add): Merge conflict in paddle/fluid/eager/CMakeLists.txt
2021-11-19 19:00:19 Auto-merging paddle/fluid/CMakeLists.txt
2021-11-19 19:00:19 CONFLICT (content): Merge conflict in paddle/fluid/CMakeLists.txt
2021-11-19 19:00:19 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-Coverage

failed in build-docker-image job
failed in build-docker-image job

🔹 Failed: PR-CI-Mac-Python3

Unknown Failed
2021-11-19 19:25:05 来自 https://github.com/PaddlePaddle/Paddle
2021-11-19 19:25:05 * branch develop -> FETCH_HEAD
2021-11-19 19:25:05 * [新分支] develop -> upstream/develop
2021-11-19 19:25:06 自动合并 python/setup.py.in
2021-11-19 19:25:06 自动合并 paddle/pten/api/include/tensor.h
2021-11-19 19:25:06 自动合并 paddle/fluid/pybind/pybind.cc
2021-11-19 19:25:06 自动合并 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 19:25:06 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 19:25:06 自动合并 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 19:25:06 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 19:25:06 自动合并 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 19:25:06 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 19:25:06 自动合并 paddle/fluid/eager/eager_tensor.h
2021-11-19 19:25:06 冲突(添加/添加):合并冲突于 paddle/fluid/eager/eager_tensor.h
2021-11-19 19:25:06 自动合并 paddle/fluid/eager/CMakeLists.txt
2021-11-19 19:25:06 冲突(添加/添加):合并冲突于 paddle/fluid/eager/CMakeLists.txt
2021-11-19 19:25:06 自动合并 paddle/fluid/CMakeLists.txt
2021-11-19 19:25:06 冲突(内容):合并冲突于 paddle/fluid/CMakeLists.txt
2021-11-19 19:25:06 自动合并失败,修正冲突然后提交修正的结果。

🔹 Failed: PR-CI-Kunlun

Unknown Failed
2021-11-19 20:03:37 来自 https://github.com/PaddlePaddle/Paddle
2021-11-19 20:03:37 * branch develop -> FETCH_HEAD
2021-11-19 20:03:37 * [新分支] develop -> upstream/develop
2021-11-19 20:03:37 自动合并 python/setup.py.in
2021-11-19 20:03:37 自动合并 paddle/pten/api/include/tensor.h
2021-11-19 20:03:37 自动合并 paddle/fluid/pybind/pybind.cc
2021-11-19 20:03:37 自动合并 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 20:03:37 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/eager_tensor_test.cc
2021-11-19 20:03:37 自动合并 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 20:03:37 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/data_structure_tests/CMakeLists.txt
2021-11-19 20:03:37 自动合并 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 20:03:37 冲突(添加/添加):合并冲突于 paddle/fluid/eager/tests/CMakeLists.txt
2021-11-19 20:03:37 自动合并 paddle/fluid/eager/eager_tensor.h
2021-11-19 20:03:37 冲突(添加/添加):合并冲突于 paddle/fluid/eager/eager_tensor.h
2021-11-19 20:03:37 自动合并 paddle/fluid/eager/CMakeLists.txt
2021-11-19 20:03:37 冲突(添加/添加):合并冲突于 paddle/fluid/eager/CMakeLists.txt
2021-11-19 20:03:37 自动合并 paddle/fluid/CMakeLists.txt
2021-11-19 20:03:37 冲突(内容):合并冲突于 paddle/fluid/CMakeLists.txt
2021-11-19 20:03:37 自动合并失败,修正冲突然后提交修正的结果。

Please sign in to comment.