Skip to content

Commit

Permalink
Perfect unitests (#16)
Browse files Browse the repository at this point in the history
* perfect unittest

* update license
  • Loading branch information
YuanRisheng authored Oct 18, 2021
1 parent d3ab655 commit ddc7de8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
3 changes: 2 additions & 1 deletion paddle/fluid/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ cc_library(save_load_util SRCS save_load_util.cc DEPS tensor scope layer)
cc_test(save_load_util_test SRCS save_load_util_test.cc DEPS save_load_util tensor scope layer)
cc_library(generator SRCS generator.cc DEPS enforce place)

cc_library(tcmpt_utils SRCS tcmpt_utils.cc DEPS lod_tensor selected_rows place tcmpt)
cc_library(tcmpt_utils SRCS tcmpt_utils.cc DEPS lod_tensor selected_rows place tcmpt var_type_traits)

# Get the current working branch
execute_process(
Expand Down Expand Up @@ -454,3 +454,4 @@ if(WITH_TESTING AND TEST selected_rows_test)
endif()

cc_test(scope_guard_test SRCS scope_guard_test.cc)
cc_test(tcmpt_utils_test SRCS tcmpt_utils_test.cc DEPS tcmpt_utils)
14 changes: 0 additions & 14 deletions paddle/fluid/framework/tcmpt_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ std::shared_ptr<pt::DenseTensor> MakeTensorImpl<pt::DenseTensor>(
pt::TransToPtLayout(tensor.layout()));
}

template <>
void ShareTensorImpl<pt::DenseTensor>(pt::DenseTensor* tensor_impl,
LoDTensor* out) {
out->ResetHolderWithType(tensor_impl->allocation(),
pt::TransToProtoVarType(tensor_impl->type()));
}

template <>
void ShareTensorImpl<pt::DenseTensor>(pt::DenseTensor* tensor_impl,
Tensor* out) {
out->ResetHolderWithType(tensor_impl->allocation(),
pt::TransToProtoVarType(tensor_impl->type()));
}

std::shared_ptr<pt::TensorInterface> InputVariableToPtTensor(
const framework::Variable& variable, const pt::TensorArgDef& arg_def) {
auto expected_place = pt::TransToFluidPlace(arg_def.backend);
Expand Down
6 changes: 0 additions & 6 deletions paddle/fluid/framework/tcmpt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ std::shared_ptr<PtTensorImplT> MakeTensorImpl(const Tensor& tensor,
const platform::Place& place,
proto::VarType::Type type);

template <typename PtTensorImplT>
void ShareTensorImpl(PtTensorImplT* tensor_impl, LoDTensor* out);

template <typename PtTensorImplT>
void ShareTensorImpl(PtTensorImplT* tensor_impl, Tensor* out);

std::shared_ptr<pt::TensorInterface> InputVariableToPtTensor(
const framework::Variable& variable, const pt::TensorArgDef& arg_def);
std::shared_ptr<pt::TensorInterface> OutputVariableToPtTensor(
Expand Down
62 changes: 62 additions & 0 deletions paddle/fluid/framework/tcmpt_utils_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/framework/tcmpt_utils.h"
#include "gtest/gtest.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/selected_rows.h"
#include "paddle/fluid/framework/variable.h"

namespace paddle {
namespace framework {

TEST(TcmptUtils, MakeTensor) {
// 1. create tensor
LoDTensor x;
Tensor x2;
x.Resize({2});
x.mutable_data<float>(platform::CPUPlace());
x.data<float>()[0] = 0.2;
x.data<float>()[1] = 0.5;

// 2. test API
auto dense_x = MakeTensorImpl<pt::DenseTensor>(x, x.place(), x.type());

// 3. check result
std::vector<float> expect_value = {0.2, 0.5};
ASSERT_EQ(dense_x->data<float>()[0], expect_value[0]);
ASSERT_EQ(dense_x->data<float>()[1], expect_value[1]);
ASSERT_EQ(dense_x->backend(), pt::Backend::kCPU);
ASSERT_EQ(dense_x->type(), pt::DataType::kFLOAT32);
}

TEST(TcmptUtils, VarToPtTensor) {
// 1. create Variable
Variable v;
auto selected_rows = v.GetMutable<SelectedRows>();
Tensor* value = selected_rows->mutable_value();
auto* data =
value->mutable_data<int>(make_ddim({1, 1}), paddle::platform::CPUPlace());
data[0] = 123;
auto tensor_def = pt::TensorArgDef(pt::Backend::kCUDA, pt::DataLayout::kNCHW,
pt::DataType::kINT32);
// 2. test API
auto tensor_x = InputVariableToPtTensor(v, tensor_def);
// 3. check result
ASSERT_EQ(tensor_x->backend(), pt::Backend::kCUDA);
ASSERT_EQ(tensor_x->type(), pt::DataType::kINT32);
}

} // namespace framework
} // namespace paddle

1 comment on commit ddc7de8

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on ddc7de8 Oct 18, 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: #16 Commit ID: ddc7de8 contains failed CI.

🔹 Failed: PR-CI-APPROVAL

approve_failed
2021-10-18 12:00:26 正在保存至: “bk.txt”
2021-10-18 12:00:26 0K 100% 1.75M=0s
2021-10-18 12:00:26 2021-10-18 12:00:26 (1.75 MB/s) - 已保存 “bk.txt” [5/5])
2021-10-18 12:00:34 ****************
2021-10-18 12:00:34 0. You must have one RD (lanxianghit (Recommend), phlrain or luotao1) approval for changing the FLAGS, which manages the environment variables.
2021-10-18 12:00:34 1. You must have Dianhai approval for change 20+ files or add than 1000+ lines of content.
2021-10-18 12:00:34 2. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for paddle/fluid/framework/operator.h, which manages the underlying code for fluid.
2021-10-18 12:00:34 3. You must have one RD (zhiqiu (Recommend) , phlrain) approval for the changes of paddle/fluid/pybind/op_function_generator.cc, which manages the logic of automatic generating op functions for dygraph.
2021-10-18 12:00:34 4. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for the usage of const_cast.
2021-10-18 12:00:34 5. You must have one RD (Avin0323(Recommend) or zhouwei25 or wanghuancoder or luotao1) approval for modifying unity_build_rule.cmake which the rules of Unity Build.
2021-10-18 12:00:34 There are 6 approved errors.
2021-10-18 12:00:34 ****************
2021-10-18 12:00:34 + EXCODE=6
2021-10-18 12:00:34 + echo 'EXCODE: 6'
2021-10-18 12:00:34 EXCODE: 6
2021-10-18 12:00:34 + echo 'ipipe_log_param_EXCODE: 6'
2021-10-18 12:00:34 ipipe_log_param_EXCODE: 6
2021-10-18 12:00:34 + exit 6

🔹 Failed: PR-CI-NPU

Unknown Failed
{"status":"INTERNAL_SERVER_ERROR","message":"服务异常!","data":null}

🔹 Failed: PR-CE-Framework

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-Mac-Python3

test_failed
2021-10-18 12:53:55 The following tests FAILED:
2021-10-18 12:53:55 73 - tcmpt_utils_test (Failed)
2021-10-18 12:53:55 + EXCODE=8
2021-10-18 12:53:55 + echo 'EXCODE: 8'
2021-10-18 12:53:55 EXCODE: 8
2021-10-18 12:53:55 + echo 'ipipe_log_param_EXCODE: 8'
2021-10-18 12:53:55 ipipe_log_param_EXCODE: 8
2021-10-18 12:53:55 + '[' 8 -eq 0 ']'
2021-10-18 12:53:55 + set +x
2021-10-18 12:53:55 Sorry, some tests failed.
2021-10-18 12:53:55 + exit 8

🔹 Failed: PR-CI-OP-benchmark

Unknown Failed
2021-10-18 13:31:46 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.'
2021-10-18 13:31:46 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.
2021-10-18 13:31:46 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-18 13:31:46 + '[' -z '' ']'
2021-10-18 13:31:46 + exit_code=8
2021-10-18 13:31:46 + LOG '[ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-18 13:31:46 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-18 13:31:46 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.
2021-10-18 13:31:46 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-18 13:31:46 + '[' -z matmul,matmul,matmul.json,True ']'
2021-10-18 13:31:46 + '[' 8 -ne 0 ']'
2021-10-18 13:31:46 + LOG '[INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-18 13:31:46 + echo '[tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-18 13:31:46 [tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.
2021-10-18 13:31:46 + LOG '[INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-18 13:31:46 + echo '[tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-18 13:31:46 [tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.
2021-10-18 13:31:46 + exit 8
2021-10-18 13:31:46 {build code state=8}

🔹 Failed: PR-CI-Coverage

coverage_failed
2021-10-18 14:38:43 + CURL_OPTS='-s --connect-timeout 600 --retry 10 --retry-delay 10'
2021-10-18 14:38:43 ++ uuid
2021-10-18 14:38:43 ++ curl -s --connect-timeout 600 --retry 10 --retry-delay 10 -u paddle:915eedab953b6f51151f50eb https://xly.bce.baidu.com/ipipe/ipipe-report/uuid
2021-10-18 14:38:43 + UPLOAD_FILE=/tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz
2021-10-18 14:38:43 + echo Archiving
2021-10-18 14:38:43 Archiving
2021-10-18 14:38:43 + tar -czvf /tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz .
2021-10-18 14:38:43 ./
2021-10-18 14:38:43 + du -hs /tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz
2021-10-18 14:38:43 4.0K /tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz
2021-10-18 14:38:43 + curl -s --connect-timeout 600 --retry 10 --retry-delay 10 -u paddle:915eedab953b6f51151f50eb -F buildId=8418394 -F path=python-coverage -F file=@/tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz https://xly.bce.baidu.com/ipipe/ipipe-report/upload
2021-10-18 14:38:43 + rm -f /tmp/upload-8253e6ab-d0f0-4d22-9e6a-6e32ea6901ad.tar.gz
2021-10-18 14:38:43 report uploaded
2021-10-18 14:38:43 9
2021-10-18 14:38:43 ipipe_log_param_EXCODE: 9
2021-10-18 14:38:43 Sorry, coverage check failed.
2021-10-18 14:38:43 + exit 9
2021-10-18 14:38:43 {build code state=9}
2021-10-18 14:38:53 kill agent BUILD_CODE_FAIL

Please sign in to comment.