提交 5fd2ff0a 编写于 作者: Y yangqingyou

add crypto api for python, test=develop

...@@ -88,7 +88,7 @@ option(WITH_DGC "Use DGC(Deep Gradient Compression) or not" ${WITH_DISTRIBUTE} ...@@ -88,7 +88,7 @@ option(WITH_DGC "Use DGC(Deep Gradient Compression) or not" ${WITH_DISTRIBUTE}
option(SANITIZER_TYPE "Choose the type of sanitizer, options are: Address, Leak, Memory, Thread, Undefined" OFF) option(SANITIZER_TYPE "Choose the type of sanitizer, options are: Address, Leak, Memory, Thread, Undefined" OFF)
option(WITH_LITE "Compile Paddle Fluid with Lite Engine" OFF) option(WITH_LITE "Compile Paddle Fluid with Lite Engine" OFF)
option(WITH_NCCL "Compile PaddlePaddle with NCCL support" ON) option(WITH_NCCL "Compile PaddlePaddle with NCCL support" ON)
option(WITH_CRYPTO "Compile PaddlePaddle with crypto support" ON) option(WITH_CRYPTO "Compile PaddlePaddle with paddle_crypto lib" ON)
# PY_VERSION # PY_VERSION
if(NOT PY_VERSION) if(NOT PY_VERSION)
......
...@@ -148,6 +148,7 @@ cc_library(proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc ...@@ -148,6 +148,7 @@ cc_library(proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc
cc_library(op_registry SRCS op_registry.cc DEPS op_proto_maker op_info operator glog proto_desc) cc_library(op_registry SRCS op_registry.cc DEPS op_proto_maker op_info operator glog proto_desc)
cc_library(op_call_stack SRCS op_call_stack.cc DEPS op_proto_maker enforce) cc_library(op_call_stack SRCS op_call_stack.cc DEPS op_proto_maker enforce)
cc_test(op_call_stack_test SRCS op_call_stack_test.cc DEPS op_call_stack)
nv_test(op_registry_test SRCS op_registry_test.cc DEPS op_registry) nv_test(op_registry_test SRCS op_registry_test.cc DEPS op_registry)
......
...@@ -18,7 +18,9 @@ limitations under the License. */ ...@@ -18,7 +18,9 @@ limitations under the License. */
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <utility>
#include <vector> #include <vector>
#include "paddle/fluid/framework/op_call_stack.h"
#include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/operator.h" #include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/imperative/dygraph_grad_maker.h" #include "paddle/fluid/imperative/dygraph_grad_maker.h"
...@@ -195,7 +197,14 @@ class SingleGradOpMaker<OpDesc> : public GradOpDescMakerBase { ...@@ -195,7 +197,14 @@ class SingleGradOpMaker<OpDesc> : public GradOpDescMakerBase {
std::vector<std::unique_ptr<OpDesc>> operator()() const final { std::vector<std::unique_ptr<OpDesc>> operator()() const final {
std::vector<std::unique_ptr<OpDesc>> retv; std::vector<std::unique_ptr<OpDesc>> retv;
retv.emplace_back(new OpDesc()); retv.emplace_back(new OpDesc());
this->Apply(retv.front().get()); try {
this->Apply(retv.front().get());
} catch (platform::EnforceNotMet& exception) {
framework::AppendErrorOpHint(retv.front().get()->Type(), &exception);
throw std::move(exception);
} catch (...) {
std::rethrow_exception(std::current_exception());
}
return retv; return retv;
} }
...@@ -213,7 +222,14 @@ class SingleGradOpMaker<imperative::OpBase> ...@@ -213,7 +222,14 @@ class SingleGradOpMaker<imperative::OpBase>
auto node = this->NewGradNode(); auto node = this->NewGradNode();
{ {
imperative::TracedGradOp traced_grad_op(node); imperative::TracedGradOp traced_grad_op(node);
this->Apply(&traced_grad_op); try {
this->Apply(&traced_grad_op);
} catch (platform::EnforceNotMet& exception) {
framework::AppendErrorOpHint(traced_grad_op.Type(), &exception);
throw std::move(exception);
} catch (...) {
std::rethrow_exception(std::current_exception());
}
} }
return node->empty() ? nullptr : node; return node->empty() ? nullptr : node;
} }
......
...@@ -56,9 +56,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs, ...@@ -56,9 +56,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
} }
// Step 3. Construct final call stack & append error op name // Step 3. Construct final call stack & append error op name
sout << exception->err_str_; sout << exception->err_str_;
if (callstack) { sout << " [operator < " << type << " > error]";
sout << " [operator < " << type << " > error]"; exception->err_str_ = sout.str();
} }
void AppendErrorOpHint(const std::string &type,
platform::EnforceNotMet *exception) {
std::ostringstream sout;
sout << exception->err_str_;
sout << " [operator < " << type << " > error]";
exception->err_str_ = sout.str(); exception->err_str_ = sout.str();
} }
......
...@@ -20,7 +20,14 @@ limitations under the License. */ ...@@ -20,7 +20,14 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace framework { namespace framework {
// insert python call stack & append error op for exception message
void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs, void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
platform::EnforceNotMet *exception); platform::EnforceNotMet *exception);
// only append error op for exception message
void AppendErrorOpHint(const std::string &type,
platform::EnforceNotMet *exception);
} // namespace framework } // namespace framework
} // namespace paddle } // namespace paddle
/* Copyright (c) 2020 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/op_call_stack.h"
#include <string>
#include <vector>
#include "gtest/gtest.h"
namespace paddle {
namespace framework {
namespace details {
static void ThrowEnforceNotMet() {
PADDLE_THROW(platform::errors::InvalidArgument(
"\n----------------------\nError Message "
"Summary:\n----------------------\n"
"Created error."));
}
} // namespace details
} // namespace framework
} // namespace paddle
TEST(OpCallStack, InsertCallStackInfo) {
try {
paddle::framework::details::ThrowEnforceNotMet();
} catch (paddle::platform::EnforceNotMet &exception) {
paddle::framework::AttributeMap attr_map;
std::string stack_test_str = "test for op callstack";
std::vector<std::string> stack_test_vec;
stack_test_vec.emplace_back(stack_test_str);
attr_map["op_callstack"] = stack_test_vec;
paddle::framework::InsertCallStackInfo("test", attr_map, &exception);
std::string ex_msg = exception.what();
EXPECT_TRUE(ex_msg.find(stack_test_str) != std::string::npos);
EXPECT_TRUE(ex_msg.find("[operator < test > error]") != std::string::npos);
}
}
TEST(OpCallStack, AppendErrorOpHint) {
try {
paddle::framework::details::ThrowEnforceNotMet();
} catch (paddle::platform::EnforceNotMet &exception) {
paddle::framework::AppendErrorOpHint("test", &exception);
std::string ex_msg = exception.what();
EXPECT_TRUE(ex_msg.find("[operator < test > error]") != std::string::npos);
}
}
...@@ -258,6 +258,8 @@ class TracedGradOp { ...@@ -258,6 +258,8 @@ class TracedGradOp {
} }
} }
std::string Type() const { return op_->Type(); }
void SetType(const std::string& type) { op_->SetType(type); } void SetType(const std::string& type) { op_->SetType(type); }
void SetAttrMap(const framework::AttributeMap& attrs) { void SetAttrMap(const framework::AttributeMap& attrs) {
......
...@@ -25,7 +25,7 @@ class HardSigmoidOpConverter : public OpConverter { ...@@ -25,7 +25,7 @@ class HardSigmoidOpConverter : public OpConverter {
public: public:
void operator()(const framework::proto::OpDesc& op, void operator()(const framework::proto::OpDesc& op,
const framework::Scope& scope, bool test_mode) override { const framework::Scope& scope, bool test_mode) override {
#if IS_TRT_VERSION_GE(5000) #if IS_TRT_VERSION_GE(5130)
VLOG(3) << "convert a fluid HardSigmoid op to tensorrt IActivationLayer " VLOG(3) << "convert a fluid HardSigmoid op to tensorrt IActivationLayer "
"layer without bias"; "layer without bias";
framework::OpDesc op_desc(op, nullptr); framework::OpDesc op_desc(op, nullptr);
......
...@@ -822,10 +822,10 @@ class SquareDoubleGradMaker : public ::paddle::framework::SingleGradOpMaker<T> { ...@@ -822,10 +822,10 @@ class SquareDoubleGradMaker : public ::paddle::framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_INPLACE_OP_INFERER(ActivationGradOpInplaceInference, DECLARE_INPLACE_OP_INFERER(ActivationGradOpInplaceInferer,
{framework::GradVarName("Out"), {framework::GradVarName("Out"),
framework::GradVarName("X")}); framework::GradVarName("X")});
DECLARE_INPLACE_OP_INFERER(ActivationDoubleGradOpInplaceInference, DECLARE_INPLACE_OP_INFERER(ActivationDoubleGradOpInplaceInferer,
{"DDX", "DDOut"}); {"DDX", "DDOut"});
template <typename T> template <typename T>
...@@ -913,7 +913,7 @@ namespace plat = paddle::platform; ...@@ -913,7 +913,7 @@ namespace plat = paddle::platform;
std::conditional<ops::CanInplaceAct<ops::grad_functor<float>>(), \ std::conditional<ops::CanInplaceAct<ops::grad_functor<float>>(), \
ops::ActFwdInplaceInferer, void>::type); \ ops::ActFwdInplaceInferer, void>::type); \
REGISTER_OPERATOR(KERNEL_TYPE##_grad, ops::ActivationOpGrad, \ REGISTER_OPERATOR(KERNEL_TYPE##_grad, ops::ActivationOpGrad, \
ops::ActivationGradOpInplaceInference); ops::ActivationGradOpInplaceInferer);
#define REGISTER_ACTIVATION_CPU_KERNEL(act_type, op_name, functor, \ #define REGISTER_ACTIVATION_CPU_KERNEL(act_type, op_name, functor, \
grad_functor) \ grad_functor) \
...@@ -941,13 +941,13 @@ REGISTER_OPERATOR( ...@@ -941,13 +941,13 @@ REGISTER_OPERATOR(
paddle::imperative::OpBase>, paddle::imperative::OpBase>,
ops::ActFwdInplaceInferer); ops::ActFwdInplaceInferer);
REGISTER_OPERATOR(relu_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(relu_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference, ops::ActivationGradOpInplaceInferer,
ops::ReluDoubleGradMaker<paddle::framework::OpDesc>, ops::ReluDoubleGradMaker<paddle::framework::OpDesc>,
ops::ReluDoubleGradMaker<paddle::imperative::OpBase>); ops::ReluDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR( REGISTER_OPERATOR(
relu_grad_grad, relu_grad_grad,
ops::ActivationOpDoubleGrad2<ops::ReluGradFunctor<float>::FwdDeps()>, ops::ActivationOpDoubleGrad2<ops::ReluGradFunctor<float>::FwdDeps()>,
ops::ActivationDoubleGradOpInplaceInference); ops::ActivationDoubleGradOpInplaceInferer);
REGISTER_ACTIVATION_CPU_KERNEL(relu, Relu, ReluFunctor, ReluGradFunctor); REGISTER_ACTIVATION_CPU_KERNEL(relu, Relu, ReluFunctor, ReluGradFunctor);
...@@ -971,13 +971,13 @@ REGISTER_OPERATOR( ...@@ -971,13 +971,13 @@ REGISTER_OPERATOR(
paddle::imperative::OpBase>, paddle::imperative::OpBase>,
ops::ActFwdInplaceInferer); ops::ActFwdInplaceInferer);
REGISTER_OPERATOR(leaky_relu_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(leaky_relu_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference, ops::ActivationGradOpInplaceInferer,
ops::LeakyReluDoubleGradMaker<paddle::framework::OpDesc>, ops::LeakyReluDoubleGradMaker<paddle::framework::OpDesc>,
ops::LeakyReluDoubleGradMaker<paddle::imperative::OpBase>); ops::LeakyReluDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR( REGISTER_OPERATOR(
leaky_relu_grad_grad, leaky_relu_grad_grad,
ops::ActivationOpDoubleGrad2<ops::LeakyReluGradFunctor<float>::FwdDeps()>, ops::ActivationOpDoubleGrad2<ops::LeakyReluGradFunctor<float>::FwdDeps()>,
ops::ActivationDoubleGradOpInplaceInference); ops::ActivationDoubleGradOpInplaceInferer);
REGISTER_ACTIVATION_CPU_KERNEL(leaky_relu, LeakyRelu, LeakyReluFunctor, REGISTER_ACTIVATION_CPU_KERNEL(leaky_relu, LeakyRelu, LeakyReluFunctor,
LeakyReluGradFunctor); LeakyReluGradFunctor);
...@@ -1000,13 +1000,13 @@ REGISTER_OPERATOR( ...@@ -1000,13 +1000,13 @@ REGISTER_OPERATOR(
paddle::imperative::OpBase>, paddle::imperative::OpBase>,
ops::ActFwdInplaceInferer); ops::ActFwdInplaceInferer);
REGISTER_OPERATOR(elu_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(elu_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference, ops::ActivationGradOpInplaceInferer,
ops::ELUDoubleGradMaker<paddle::framework::OpDesc>, ops::ELUDoubleGradMaker<paddle::framework::OpDesc>,
ops::ELUDoubleGradMaker<paddle::imperative::OpBase>); ops::ELUDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR( REGISTER_OPERATOR(
elu_grad_grad, elu_grad_grad,
ops::ActivationOpDoubleGrad<ops::ELUGradFunctor<float>::FwdDeps()>, ops::ActivationOpDoubleGrad<ops::ELUGradFunctor<float>::FwdDeps()>,
ops::ActivationDoubleGradOpInplaceInference); ops::ActivationDoubleGradOpInplaceInferer);
REGISTER_ACTIVATION_CPU_KERNEL(elu, ELU, ELUFunctor, ELUGradFunctor); REGISTER_ACTIVATION_CPU_KERNEL(elu, ELU, ELUFunctor, ELUGradFunctor);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
...@@ -1028,13 +1028,13 @@ REGISTER_OPERATOR( ...@@ -1028,13 +1028,13 @@ REGISTER_OPERATOR(
paddle::imperative::OpBase>, paddle::imperative::OpBase>,
ops::ActFwdInplaceInferer); ops::ActFwdInplaceInferer);
REGISTER_OPERATOR(sqrt_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(sqrt_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference, ops::ActivationGradOpInplaceInferer,
ops::SqrtDoubleGradMaker<paddle::framework::OpDesc>, ops::SqrtDoubleGradMaker<paddle::framework::OpDesc>,
ops::SqrtDoubleGradMaker<paddle::imperative::OpBase>); ops::SqrtDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR( REGISTER_OPERATOR(
sqrt_grad_grad, sqrt_grad_grad,
ops::ActivationOpDoubleGrad<ops::SqrtGradGradFunctor<float>::FwdDeps()>, ops::ActivationOpDoubleGrad<ops::SqrtGradGradFunctor<float>::FwdDeps()>,
ops::ActivationDoubleGradOpInplaceInference); ops::ActivationDoubleGradOpInplaceInferer);
REGISTER_ACTIVATION_CPU_KERNEL(sqrt, Sqrt, SqrtFunctor, SqrtGradFunctor); REGISTER_ACTIVATION_CPU_KERNEL(sqrt, Sqrt, SqrtFunctor, SqrtGradFunctor);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
...@@ -1056,13 +1056,13 @@ REGISTER_OPERATOR( ...@@ -1056,13 +1056,13 @@ REGISTER_OPERATOR(
paddle::imperative::OpBase>, paddle::imperative::OpBase>,
ops::ActFwdInplaceInferer); ops::ActFwdInplaceInferer);
REGISTER_OPERATOR(square_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(square_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference, ops::ActivationGradOpInplaceInferer,
ops::SquareDoubleGradMaker<paddle::framework::OpDesc>, ops::SquareDoubleGradMaker<paddle::framework::OpDesc>,
ops::SquareDoubleGradMaker<paddle::imperative::OpBase>); ops::SquareDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR( REGISTER_OPERATOR(
square_grad_grad, square_grad_grad,
ops::ActivationOpDoubleGrad<ops::SquareGradGradFunctor<float>::FwdDeps()>, ops::ActivationOpDoubleGrad<ops::SquareGradGradFunctor<float>::FwdDeps()>,
ops::ActivationDoubleGradOpInplaceInference); ops::ActivationDoubleGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL(square, REGISTER_OP_CPU_KERNEL(square,
ops::ActivationKernel<paddle::platform::CPUDeviceContext, ops::ActivationKernel<paddle::platform::CPUDeviceContext,
...@@ -1106,7 +1106,7 @@ REGISTER_OPERATOR( ...@@ -1106,7 +1106,7 @@ REGISTER_OPERATOR(
std::conditional<ops::CanInplaceAct<ops::PowGradFunctor<float>>(), std::conditional<ops::CanInplaceAct<ops::PowGradFunctor<float>>(),
ops::ActFwdInplaceInferer, void>::type); ops::ActFwdInplaceInferer, void>::type);
REGISTER_OPERATOR(pow_grad, ops::PowOpGrad, REGISTER_OPERATOR(pow_grad, ops::PowOpGrad,
ops::ActivationGradOpInplaceInference); ops::ActivationGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
pow, ops::PowKernel<plat::CPUDeviceContext, ops::PowFunctor<float>>, pow, ops::PowKernel<plat::CPUDeviceContext, ops::PowFunctor<float>>,
...@@ -1131,7 +1131,7 @@ REGISTER_OPERATOR( ...@@ -1131,7 +1131,7 @@ REGISTER_OPERATOR(
std::conditional<ops::CanInplaceAct<ops::ExpGradFunctor<float>>(), std::conditional<ops::CanInplaceAct<ops::ExpGradFunctor<float>>(),
ops::ActFwdInplaceInferer, void>::type); ops::ActFwdInplaceInferer, void>::type);
REGISTER_OPERATOR(exp_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(exp_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference); ops::ActivationGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL(exp, REGISTER_OP_CPU_KERNEL(exp,
ops::ActivationKernel<paddle::platform::CPUDeviceContext, ops::ActivationKernel<paddle::platform::CPUDeviceContext,
...@@ -1163,7 +1163,7 @@ REGISTER_OPERATOR( ...@@ -1163,7 +1163,7 @@ REGISTER_OPERATOR(
std::conditional<ops::CanInplaceAct<ops::AbsGradFunctor<float>>(), std::conditional<ops::CanInplaceAct<ops::AbsGradFunctor<float>>(),
ops::ActFwdInplaceInferer, void>::type); ops::ActFwdInplaceInferer, void>::type);
REGISTER_OPERATOR(abs_grad, ops::ActivationOpGrad, REGISTER_OPERATOR(abs_grad, ops::ActivationOpGrad,
ops::ActivationGradOpInplaceInference); ops::ActivationGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL(abs, REGISTER_OP_CPU_KERNEL(abs,
ops::ActivationKernel<paddle::platform::CPUDeviceContext, ops::ActivationKernel<paddle::platform::CPUDeviceContext,
......
...@@ -116,7 +116,7 @@ class ArgsortGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -116,7 +116,7 @@ class ArgsortGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ArgsortGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(ArgsortGradNoNeedBufferVarsInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -126,7 +126,7 @@ REGISTER_OPERATOR(argsort, ops::ArgsortOp, ops::ArgsortOpMaker, ...@@ -126,7 +126,7 @@ REGISTER_OPERATOR(argsort, ops::ArgsortOp, ops::ArgsortOpMaker,
ops::ArgsortGradOpMaker<paddle::framework::OpDesc>, ops::ArgsortGradOpMaker<paddle::framework::OpDesc>,
ops::ArgsortGradOpMaker<paddle::imperative::OpBase>); ops::ArgsortGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(argsort_grad, ops::ArgsortGradOp, REGISTER_OPERATOR(argsort_grad, ops::ArgsortGradOp,
ops::ArgsortGradNoNeedBufferVarInference); ops::ArgsortGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL(argsort, REGISTER_OP_CPU_KERNEL(argsort,
ops::ArgsortKernel<paddle::platform::CPUPlace, float>, ops::ArgsortKernel<paddle::platform::CPUPlace, float>,
ops::ArgsortKernel<paddle::platform::CPUPlace, double>, ops::ArgsortKernel<paddle::platform::CPUPlace, double>,
......
...@@ -136,7 +136,7 @@ class BatchFCGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -136,7 +136,7 @@ class BatchFCGradOpMaker : public framework::SingleGradOpMaker<T> {
op->SetAttrMap(this->Attrs()); op->SetAttrMap(this->Attrs());
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(BatchFCGradOpNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(BatchFCGradOpNoNeedBufferVarsInferer,
"Bias"); "Bias");
} // namespace operators } // namespace operators
...@@ -148,7 +148,7 @@ REGISTER_OPERATOR(batch_fc, ops::BatchFCOp, ops::BatchFCOpMaker, ...@@ -148,7 +148,7 @@ REGISTER_OPERATOR(batch_fc, ops::BatchFCOp, ops::BatchFCOpMaker,
ops::BatchFCGradOpMaker<paddle::imperative::OpBase>); ops::BatchFCGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(batch_fc_grad, ops::BatchFCGradOp, REGISTER_OPERATOR(batch_fc_grad, ops::BatchFCGradOp,
ops::BatchFCGradOpNoNeedBufferVarsInference); ops::BatchFCGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
batch_fc, ops::BatchFCKernel<paddle::platform::CPUDeviceContext, float>, batch_fc, ops::BatchFCKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -74,7 +74,7 @@ class BatchSizeLikeOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -74,7 +74,7 @@ class BatchSizeLikeOpMaker : public framework::OpProtoAndCheckerMaker {
virtual void Apply() = 0; virtual void Apply() = 0;
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(BatchSizeLikeNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(BatchSizeLikeNoNeedBufferVarsInferer,
"Input"); "Input");
} // namespace operators } // namespace operators
......
...@@ -175,7 +175,7 @@ class ConcatOpGrad : public framework::OperatorWithKernel { ...@@ -175,7 +175,7 @@ class ConcatOpGrad : public framework::OperatorWithKernel {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ConcatOpGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(ConcatOpGradNoNeedBufferVarInferer, "X");
template <typename T> template <typename T>
class ConcatGradOpMaker : public framework::SingleGradOpMaker<T> { class ConcatGradOpMaker : public framework::SingleGradOpMaker<T> {
...@@ -203,7 +203,7 @@ REGISTER_OPERATOR(concat, ops::ConcatOp, ops::ConcatOpMaker, ...@@ -203,7 +203,7 @@ REGISTER_OPERATOR(concat, ops::ConcatOp, ops::ConcatOpMaker,
ops::ConcatGradOpMaker<paddle::framework::OpDesc>, ops::ConcatGradOpMaker<paddle::framework::OpDesc>,
ops::ConcatGradOpMaker<paddle::imperative::OpBase>); ops::ConcatGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(concat_grad, ops::ConcatOpGrad, REGISTER_OPERATOR(concat_grad, ops::ConcatOpGrad,
ops::ConcatOpGradNoNeedBufferVarInference); ops::ConcatOpGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
concat, ops::ConcatKernel<paddle::platform::CPUDeviceContext, double>, concat, ops::ConcatKernel<paddle::platform::CPUDeviceContext, double>,
ops::ConcatKernel<paddle::platform::CPUDeviceContext, float>, ops::ConcatKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -148,7 +148,7 @@ struct SearchAlgorithm<cudnnConvolutionFwdAlgoPerf_t> { ...@@ -148,7 +148,7 @@ struct SearchAlgorithm<cudnnConvolutionFwdAlgoPerf_t> {
} }
#endif #endif
if (!exhaustive) { if (!exhaustive && !deterministic) {
#if CUDNN_VERSION >= 7001 #if CUDNN_VERSION >= 7001
int perf_count; int perf_count;
int best_algo_idx = 0; int best_algo_idx = 0;
...@@ -185,6 +185,8 @@ struct SearchAlgorithm<cudnnConvolutionFwdAlgoPerf_t> { ...@@ -185,6 +185,8 @@ struct SearchAlgorithm<cudnnConvolutionFwdAlgoPerf_t> {
workspace_size_limit, &algo)); workspace_size_limit, &algo));
#endif #endif
VLOG(3) << "choose algo " << algo; VLOG(3) << "choose algo " << algo;
} else if (deterministic) {
algo = static_cast<cudnnConvolutionFwdAlgo_t>(1);
} else { } else {
auto& dev_ctx = auto& dev_ctx =
ctx.template device_context<platform::CUDADeviceContext>(); ctx.template device_context<platform::CUDADeviceContext>();
......
...@@ -245,7 +245,8 @@ class CUDNNConvTransposeOpKernel : public framework::OpKernel<T> { ...@@ -245,7 +245,8 @@ class CUDNNConvTransposeOpKernel : public framework::OpKernel<T> {
int output_offset = int output_offset =
transformed_output.numel() / transformed_output.dims()[0] / groups; transformed_output.numel() / transformed_output.dims()[0] / groups;
int filter_offset = filter->numel() / groups; int filter_offset = filter->numel() / groups;
T alpha = static_cast<T>(1.0), beta = static_cast<T>(0.0); ScalingParamType<T> alpha = 1.0f;
ScalingParamType<T> beta = 0.0f;
auto workspace_handle = dev_ctx.cudnn_workspace_handle(); auto workspace_handle = dev_ctx.cudnn_workspace_handle();
for (int g = 0; g < groups; g++) { for (int g = 0; g < groups; g++) {
auto cudnn_func = [&](void* cudnn_workspace) { auto cudnn_func = [&](void* cudnn_workspace) {
...@@ -493,7 +494,8 @@ class CUDNNConvTransposeGradOpKernel : public framework::OpKernel<T> { ...@@ -493,7 +494,8 @@ class CUDNNConvTransposeGradOpKernel : public framework::OpKernel<T> {
int output_grad_offset = transformed_output_grad.numel() / int output_grad_offset = transformed_output_grad.numel() /
transformed_output_grad.dims()[0] / groups; transformed_output_grad.dims()[0] / groups;
int filter_offset = filter->numel() / groups; int filter_offset = filter->numel() / groups;
T alpha = static_cast<T>(1.0), beta = static_cast<T>(0.0); ScalingParamType<T> alpha = 1.0f;
ScalingParamType<T> beta = 0.0f;
auto workspace_handle = dev_ctx.cudnn_workspace_handle(); auto workspace_handle = dev_ctx.cudnn_workspace_handle();
if (input_grad) { if (input_grad) {
// Because beta is zero, it is unnecessary to reset input_grad. // Because beta is zero, it is unnecessary to reset input_grad.
......
...@@ -203,7 +203,7 @@ class CropGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -203,7 +203,7 @@ class CropGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(GropNoNeedBufferVarInference, "Y"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(GropNoNeedBufferVarInferer, "Y");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -212,7 +212,7 @@ namespace ops = paddle::operators; ...@@ -212,7 +212,7 @@ namespace ops = paddle::operators;
REGISTER_OPERATOR(crop, ops::CropOp, ops::CropOpMaker, REGISTER_OPERATOR(crop, ops::CropOp, ops::CropOpMaker,
ops::CropGradOpMaker<paddle::framework::OpDesc>, ops::CropGradOpMaker<paddle::framework::OpDesc>,
ops::CropGradOpMaker<paddle::imperative::OpBase>, ops::CropGradOpMaker<paddle::imperative::OpBase>,
ops::GropNoNeedBufferVarInference); ops::GropNoNeedBufferVarInferer);
REGISTER_OPERATOR(crop_grad, ops::CropOpGrad); REGISTER_OPERATOR(crop_grad, ops::CropOpGrad);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
crop, ops::CropKernel<paddle::platform::CPUDeviceContext, float>, crop, ops::CropKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -153,8 +153,8 @@ class CVMGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -153,8 +153,8 @@ class CVMGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(CVMNoNeedBufferVarInference, "CVM"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(CVMNoNeedBufferVarInferer, "CVM");
DECLARE_NO_NEED_BUFFER_VARS_INFERER(CVMGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(CVMGradNoNeedBufferVarInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -163,10 +163,10 @@ namespace ops = paddle::operators; ...@@ -163,10 +163,10 @@ namespace ops = paddle::operators;
REGISTER_OPERATOR(cvm, ops::CVMOp, ops::CVMOpMaker, REGISTER_OPERATOR(cvm, ops::CVMOp, ops::CVMOpMaker,
ops::CVMGradOpMaker<paddle::framework::OpDesc>, ops::CVMGradOpMaker<paddle::framework::OpDesc>,
ops::CVMGradOpMaker<paddle::imperative::OpBase>, ops::CVMGradOpMaker<paddle::imperative::OpBase>,
ops::CVMNoNeedBufferVarInference); ops::CVMNoNeedBufferVarInferer);
REGISTER_OPERATOR(cvm_grad, ops::CVMGradientOp, REGISTER_OPERATOR(cvm_grad, ops::CVMGradientOp,
ops::CVMGradNoNeedBufferVarInference); ops::CVMGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL(cvm, ops::CVMOpKernel<float>, ops::CVMOpKernel<double>); REGISTER_OP_CPU_KERNEL(cvm, ops::CVMOpKernel<float>, ops::CVMOpKernel<double>);
......
...@@ -97,15 +97,15 @@ REGISTER_ELEMWISE_EXPLICIT_OP_WITHOUT_GRAD(elementwise_add, Add); ...@@ -97,15 +97,15 @@ REGISTER_ELEMWISE_EXPLICIT_OP_WITHOUT_GRAD(elementwise_add, Add);
namespace ops = paddle::operators; namespace ops = paddle::operators;
REGISTER_OPERATOR( REGISTER_OPERATOR(
elementwise_add_grad, ops::ElementwiseOpGrad, ops::ElementwiseGradOpInplace, elementwise_add_grad, ops::ElementwiseOpGrad,
ops::ElementwiseGradNoBufVarsInference, ops::ElementwiseGradOpInplaceInferer, ops::ElementwiseGradNoBufVarsInferer,
ops::ElementwiseAddDoubleGradMaker<paddle::framework::OpDesc>, ops::ElementwiseAddDoubleGradMaker<paddle::framework::OpDesc>,
ops::ElementwiseAddDoubleGradMaker<paddle::imperative::OpBase>); ops::ElementwiseAddDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(elementwise_add_grad_grad, REGISTER_OPERATOR(elementwise_add_grad_grad,
ops::ElementwiseOpDoubleGradWithoutDXDY, ops::ElementwiseOpDoubleGradWithoutDXDY,
ops::ElementwiseDoubleGradOpInplace, ops::ElementwiseDoubleGradOpInplaceInferer,
ops::ElementwiseDoubleGradNoBufVarsInference); ops::ElementwiseDoubleGradNoBufVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
elementwise_add, elementwise_add,
......
...@@ -123,7 +123,7 @@ REGISTER_OPERATOR( ...@@ -123,7 +123,7 @@ REGISTER_OPERATOR(
ops::ElementwiseDivDoubleGradMaker<paddle::imperative::OpBase>); ops::ElementwiseDivDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(elementwise_div_grad_grad, ops::ElementwiseDivOpDoubleGrad, REGISTER_OPERATOR(elementwise_div_grad_grad, ops::ElementwiseDivOpDoubleGrad,
ops::ElementwiseDoubleGradOpInplace); ops::ElementwiseDoubleGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
elementwise_div, elementwise_div,
......
...@@ -123,7 +123,7 @@ REGISTER_OPERATOR( ...@@ -123,7 +123,7 @@ REGISTER_OPERATOR(
ops::ElementwiseMulDoubleGradMaker<paddle::imperative::OpBase>); ops::ElementwiseMulDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(elementwise_mul_grad_grad, ops::ElementwiseOpDoubleGrad, REGISTER_OPERATOR(elementwise_mul_grad_grad, ops::ElementwiseOpDoubleGrad,
ops::ElementwiseDoubleGradOpInplace); ops::ElementwiseDoubleGradOpInplaceInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
elementwise_mul, elementwise_mul,
......
...@@ -348,16 +348,16 @@ class ElemwiseGradKernel : public framework::OpKernel<T> { ...@@ -348,16 +348,16 @@ class ElemwiseGradKernel : public framework::OpKernel<T> {
} }
}; };
DECLARE_INPLACE_OP_INFERER(ElementwiseOpInplace, {"X", "Out"}); DECLARE_INPLACE_OP_INFERER(ElementwiseOpInplaceInferer, {"X", "Out"});
DECLARE_INPLACE_OP_INFERER(ElementwiseGradOpInplace, DECLARE_INPLACE_OP_INFERER(ElementwiseGradOpInplaceInferer,
{framework::GradVarName("Out"), {framework::GradVarName("Out"),
framework::GradVarName("X")}); framework::GradVarName("X")});
DECLARE_INPLACE_OP_INFERER(ElementwiseDoubleGradOpInplace, {"DDX", "DDOut"}); DECLARE_INPLACE_OP_INFERER(ElementwiseDoubleGradOpInplaceInferer,
{"DDX", "DDOut"});
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseGradNoBufVarsInference, "X", DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseGradNoBufVarsInferer, "X", "Y");
"Y"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseDoubleGradNoBufVarsInferer, "Y",
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseDoubleGradNoBufVarsInference, "DOut");
"Y", "DOut");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -389,4 +389,4 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseDoubleGradNoBufVarsInference, ...@@ -389,4 +389,4 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERER(ElementwiseDoubleGradNoBufVarsInference,
::paddle::operators::ElementwiseOpInferVarType, \ ::paddle::operators::ElementwiseOpInferVarType, \
op_type##GradMaker<::paddle::framework::OpDesc>, \ op_type##GradMaker<::paddle::framework::OpDesc>, \
op_type##GradMaker<::paddle::imperative::OpBase>, \ op_type##GradMaker<::paddle::imperative::OpBase>, \
::paddle::operators::ElementwiseOpInplace); ::paddle::operators::ElementwiseOpInplaceInferer);
...@@ -97,14 +97,14 @@ REGISTER_ELEMWISE_EXPLICIT_OP_WITHOUT_GRAD(elementwise_sub, Sub); ...@@ -97,14 +97,14 @@ REGISTER_ELEMWISE_EXPLICIT_OP_WITHOUT_GRAD(elementwise_sub, Sub);
namespace ops = paddle::operators; namespace ops = paddle::operators;
REGISTER_OPERATOR( REGISTER_OPERATOR(
elementwise_sub_grad, ops::ElementwiseOpGrad, ops::ElementwiseGradOpInplace, elementwise_sub_grad, ops::ElementwiseOpGrad,
ops::ElementwiseGradNoBufVarsInference, ops::ElementwiseGradOpInplaceInferer, ops::ElementwiseGradNoBufVarsInferer,
ops::ElementwiseSubDoubleGradMaker<paddle::framework::OpDesc>, ops::ElementwiseSubDoubleGradMaker<paddle::framework::OpDesc>,
ops::ElementwiseSubDoubleGradMaker<paddle::imperative::OpBase>); ops::ElementwiseSubDoubleGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(elementwise_sub_grad_grad, REGISTER_OPERATOR(elementwise_sub_grad_grad,
ops::ElementwiseOpDoubleGradWithoutDXDY, ops::ElementwiseOpDoubleGradWithoutDXDY,
ops::ElementwiseDoubleGradOpInplace, ops::ElementwiseDoubleGradOpInplaceInferer,
ops::ElementwiseDoubleGradNoBufVarsInference); ops::ElementwiseDoubleGradNoBufVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
elementwise_sub, elementwise_sub,
......
...@@ -63,7 +63,7 @@ REGISTER_OPERATOR( ...@@ -63,7 +63,7 @@ REGISTER_OPERATOR(
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>,
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>, paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>,
ops::FillConstantBatchSizeLikeOpMaker, ops::FillConstantBatchSizeLikeOpMaker,
ops::BatchSizeLikeNoNeedBufferVarsInference); ops::BatchSizeLikeNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
fill_constant_batch_size_like, fill_constant_batch_size_like,
ops::FillConstantBatchSizeLikeOpKernel<paddle::platform::CPUDeviceContext, ops::FillConstantBatchSizeLikeOpKernel<paddle::platform::CPUDeviceContext,
......
...@@ -71,7 +71,7 @@ class FillZerosLikeOp2Maker : public FillZerosLikeOpMaker { ...@@ -71,7 +71,7 @@ class FillZerosLikeOp2Maker : public FillZerosLikeOpMaker {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(FillZerosLikeOp2NoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(FillZerosLikeOp2NoNeedBufferVarsInferer,
"X"); "X");
} // namespace operators } // namespace operators
...@@ -83,7 +83,7 @@ REGISTER_OP_WITHOUT_GRADIENT(fill_zeros_like, ops::FillZerosLikeOp, ...@@ -83,7 +83,7 @@ REGISTER_OP_WITHOUT_GRADIENT(fill_zeros_like, ops::FillZerosLikeOp,
REGISTER_OPERATOR( REGISTER_OPERATOR(
fill_zeros_like2, ops::FillZerosLikeOp2, ops::FillZerosLikeOp2Maker, fill_zeros_like2, ops::FillZerosLikeOp2, ops::FillZerosLikeOp2Maker,
ops::FillZerosLikeOp2NoNeedBufferVarsInference, ops::FillZerosLikeOp2NoNeedBufferVarsInferer,
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>,
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>); paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>);
......
...@@ -241,11 +241,11 @@ class Flatten2GradOp : public framework::OperatorWithKernel { ...@@ -241,11 +241,11 @@ class Flatten2GradOp : public framework::OperatorWithKernel {
} }
}; };
DECLARE_INPLACE_OP_INFERER(FlattenOpInplaceInToOut, {"X", "Out"}); DECLARE_INPLACE_OP_INFERER(FlattenOpInplaceInferer, {"X", "Out"});
DECLARE_INPLACE_OP_INFERER(FlattenGradInplaceinToOut, DECLARE_INPLACE_OP_INFERER(FlattenGradInplaceInferer,
{framework::GradVarName("Out"), {framework::GradVarName("Out"),
framework::GradVarName("X")}); framework::GradVarName("X")});
DECLARE_NO_NEED_BUFFER_VARS_INFERER(FlattenGradNoNeedBufferVarsInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(FlattenGradNoNeedBufferVarsInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -254,17 +254,17 @@ namespace ops = paddle::operators; ...@@ -254,17 +254,17 @@ namespace ops = paddle::operators;
REGISTER_OPERATOR(flatten, ops::FlattenOp, ops::FlattenOpMaker, REGISTER_OPERATOR(flatten, ops::FlattenOp, ops::FlattenOpMaker,
ops::FlattenGradOpMaker<paddle::framework::OpDesc>, ops::FlattenGradOpMaker<paddle::framework::OpDesc>,
ops::FlattenGradOpMaker<paddle::imperative::OpBase>, ops::FlattenGradOpMaker<paddle::imperative::OpBase>,
ops::FlattenOpInplaceInToOut); ops::FlattenOpInplaceInferer);
REGISTER_OPERATOR(flatten_grad, ops::FlattenGradOp, REGISTER_OPERATOR(flatten_grad, ops::FlattenGradOp,
ops::FlattenGradInplaceinToOut, ops::FlattenGradInplaceInferer,
ops::FlattenGradNoNeedBufferVarsInference); ops::FlattenGradNoNeedBufferVarsInferer);
REGISTER_OPERATOR(flatten2, ops::Flatten2Op, ops::Flatten2OpMaker, REGISTER_OPERATOR(flatten2, ops::Flatten2Op, ops::Flatten2OpMaker,
ops::Flatten2GradOpMaker<paddle::framework::OpDesc>, ops::Flatten2GradOpMaker<paddle::framework::OpDesc>,
ops::Flatten2GradOpMaker<paddle::imperative::OpBase>, ops::Flatten2GradOpMaker<paddle::imperative::OpBase>,
ops::FlattenOpInplaceInToOut); ops::FlattenOpInplaceInferer);
REGISTER_OPERATOR(flatten2_grad, ops::Flatten2GradOp, REGISTER_OPERATOR(flatten2_grad, ops::Flatten2GradOp,
ops::FlattenGradInplaceinToOut); ops::FlattenGradInplaceInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
flatten, ops::FlattenKernel<paddle::platform::CPUDeviceContext, float>, flatten, ops::FlattenKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -166,7 +166,7 @@ class GatherNdGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -166,7 +166,7 @@ class GatherNdGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(GatherNdGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(GatherNdGradNoNeedBufferVarInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -178,7 +178,7 @@ REGISTER_OPERATOR(gather_nd, ops::GatherNdOp, ops::GatherNdOpMaker, ...@@ -178,7 +178,7 @@ REGISTER_OPERATOR(gather_nd, ops::GatherNdOp, ops::GatherNdOpMaker,
ops::GatherNdGradOpMaker<paddle::imperative::OpBase>); ops::GatherNdGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(gather_nd_grad, ops::GatherNdGradOp, REGISTER_OPERATOR(gather_nd_grad, ops::GatherNdGradOp,
ops::GatherNdGradNoNeedBufferVarInference); ops::GatherNdGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL(gather_nd, ops::GatherNdOpKernel<float>, REGISTER_OP_CPU_KERNEL(gather_nd, ops::GatherNdOpKernel<float>,
ops::GatherNdOpKernel<double>, ops::GatherNdOpKernel<double>,
......
...@@ -127,7 +127,7 @@ class GatherGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -127,7 +127,7 @@ class GatherGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(GatherGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(GatherGradNoNeedBufferVarInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -137,7 +137,7 @@ REGISTER_OPERATOR(gather, ops::GatherOp, ops::GatherOpMaker, ...@@ -137,7 +137,7 @@ REGISTER_OPERATOR(gather, ops::GatherOp, ops::GatherOpMaker,
ops::GatherGradOpMaker<paddle::framework::OpDesc>, ops::GatherGradOpMaker<paddle::framework::OpDesc>,
ops::GatherGradOpMaker<paddle::imperative::OpBase>); ops::GatherGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(gather_grad, ops::GatherGradOp, REGISTER_OPERATOR(gather_grad, ops::GatherGradOp,
ops::GatherGradNoNeedBufferVarInference); ops::GatherGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL(gather, ops::GatherOpKernel<float>, REGISTER_OP_CPU_KERNEL(gather, ops::GatherOpKernel<float>,
ops::GatherOpKernel<double>, ops::GatherOpKernel<int>, ops::GatherOpKernel<double>, ops::GatherOpKernel<int>,
ops::GatherOpKernel<uint8_t>, ops::GatherOpKernel<uint8_t>,
......
...@@ -74,6 +74,6 @@ REGISTER_OPERATOR( ...@@ -74,6 +74,6 @@ REGISTER_OPERATOR(
paddle::operators::GaussianRandomBatchSizeLikeOpMaker, paddle::operators::GaussianRandomBatchSizeLikeOpMaker,
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>,
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>, paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>,
paddle::operators::BatchSizeLikeNoNeedBufferVarsInference); paddle::operators::BatchSizeLikeNoNeedBufferVarsInferer);
// Kernels are registered in gaussian_random_op.cc and gaussian_random_op.cu // Kernels are registered in gaussian_random_op.cc and gaussian_random_op.cu
...@@ -216,8 +216,8 @@ class GroupNormGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -216,8 +216,8 @@ class GroupNormGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_INPLACE_OP_INFERER(GroupNormInplaceInToOut, {"X", "Y"}); DECLARE_INPLACE_OP_INFERER(GroupNormInplaceInferer, {"X", "Y"});
DECLARE_INPLACE_OP_INFERER(GroupNormGradInplaceInToOut, DECLARE_INPLACE_OP_INFERER(GroupNormGradInplaceInferer,
{framework::GradVarName("Y"), {framework::GradVarName("Y"),
framework::GradVarName("X")}); framework::GradVarName("X")});
...@@ -239,9 +239,9 @@ REGISTER_OPERATOR(group_norm, ops::GroupNormOp, ops::GroupNormOpMaker, ...@@ -239,9 +239,9 @@ REGISTER_OPERATOR(group_norm, ops::GroupNormOp, ops::GroupNormOpMaker,
ops::GroupNormOpInferVarType, ops::GroupNormOpInferVarType,
ops::GroupNormGradMaker<paddle::framework::OpDesc>, ops::GroupNormGradMaker<paddle::framework::OpDesc>,
ops::GroupNormGradMaker<paddle::imperative::OpBase>, ops::GroupNormGradMaker<paddle::imperative::OpBase>,
ops::GroupNormInplaceInToOut); ops::GroupNormInplaceInferer);
REGISTER_OPERATOR(group_norm_grad, ops::GroupNormGradOp, REGISTER_OPERATOR(group_norm_grad, ops::GroupNormGradOp,
ops::GroupNormGradInplaceInToOut); ops::GroupNormGradInplaceInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
group_norm, ops::GroupNormKernel<paddle::platform::CPUDeviceContext, float>, group_norm, ops::GroupNormKernel<paddle::platform::CPUDeviceContext, float>,
ops::GroupNormKernel<paddle::platform::CPUDeviceContext, double>); ops::GroupNormKernel<paddle::platform::CPUDeviceContext, double>);
......
...@@ -456,7 +456,7 @@ class GRUGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -456,7 +456,7 @@ class GRUGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(GRUGradOpNoNeedBufferVarInference, "Input", DECLARE_NO_NEED_BUFFER_VARS_INFERER(GRUGradOpNoNeedBufferVarInferer, "Input",
"Bias"); "Bias");
} // namespace operators } // namespace operators
...@@ -467,7 +467,7 @@ REGISTER_OPERATOR(gru, ops::GRUOp, ops::GRUOpMaker, ...@@ -467,7 +467,7 @@ REGISTER_OPERATOR(gru, ops::GRUOp, ops::GRUOpMaker,
ops::GRUGradOpMaker<paddle::framework::OpDesc>, ops::GRUGradOpMaker<paddle::framework::OpDesc>,
ops::GRUGradOpMaker<paddle::imperative::OpBase>); ops::GRUGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(gru_grad, ops::GRUGradOp, REGISTER_OPERATOR(gru_grad, ops::GRUGradOp,
ops::GRUGradOpNoNeedBufferVarInference); ops::GRUGradOpNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL(gru, ops::GRUCPUKernel<float>, REGISTER_OP_CPU_KERNEL(gru, ops::GRUCPUKernel<float>,
ops::GRUCPUKernel<double>); ops::GRUCPUKernel<double>);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
......
...@@ -234,7 +234,7 @@ class GRUUnitGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -234,7 +234,7 @@ class GRUUnitGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(GRUUnitGradOpNoNeedBufferVarInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(GRUUnitGradOpNoNeedBufferVarInferer,
"Bias"); "Bias");
} // namespace operators } // namespace operators
...@@ -246,7 +246,7 @@ REGISTER_OPERATOR(gru_unit, ops::GRUUnitOp, ops::GRUUnitOpMaker, ...@@ -246,7 +246,7 @@ REGISTER_OPERATOR(gru_unit, ops::GRUUnitOp, ops::GRUUnitOpMaker,
ops::GRUUnitGradOpMaker<paddle::framework::OpDesc>, ops::GRUUnitGradOpMaker<paddle::framework::OpDesc>,
ops::GRUUnitGradOpMaker<paddle::imperative::OpBase>); ops::GRUUnitGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(gru_unit_grad, ops::GRUUnitGradOp, REGISTER_OPERATOR(gru_unit_grad, ops::GRUUnitGradOp,
ops::GRUUnitGradOpNoNeedBufferVarInference); ops::GRUUnitGradOpNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
gru_unit, ops::GRUUnitKernel<paddle::platform::CPUDeviceContext, float>, gru_unit, ops::GRUUnitKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -82,8 +82,7 @@ class ReduceMeanDoubleGradOpBaseMaker : public imperative::GradOpBaseMakerBase { ...@@ -82,8 +82,7 @@ class ReduceMeanDoubleGradOpBaseMaker : public imperative::GradOpBaseMakerBase {
} }
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ReduceMeanGradNoNeedBufferVarInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(ReduceMeanGradNoNeedBufferVarInferer, "X");
"X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -99,7 +98,7 @@ REGISTER_OPERATOR(reduce_mean, ops::ReduceOp, __reduce_meanMaker__, ...@@ -99,7 +98,7 @@ REGISTER_OPERATOR(reduce_mean, ops::ReduceOp, __reduce_meanMaker__,
REGISTER_OPERATOR(reduce_mean_grad, ops::ReduceGradOp, REGISTER_OPERATOR(reduce_mean_grad, ops::ReduceGradOp,
ops::ReduceMeanDoubleGradDescMaker, ops::ReduceMeanDoubleGradDescMaker,
ops::ReduceMeanDoubleGradOpBaseMaker, ops::ReduceMeanDoubleGradOpBaseMaker,
ops::ReduceMeanGradNoNeedBufferVarInference); ops::ReduceMeanGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL(reduce_mean, REGISTER_OP_CPU_KERNEL(reduce_mean,
ops::ReduceKernel<paddle::platform::CPUDeviceContext, ops::ReduceKernel<paddle::platform::CPUDeviceContext,
float, ops::MeanFunctor>, float, ops::MeanFunctor>,
......
...@@ -51,7 +51,7 @@ class ReduceSumOpGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -51,7 +51,7 @@ class ReduceSumOpGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ReduceSumGradNoNeedBufferVarInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(ReduceSumGradNoNeedBufferVarInferer, "X");
class ReduceSumVarTypeInference : public paddle::framework::VarTypeInference { class ReduceSumVarTypeInference : public paddle::framework::VarTypeInference {
public: public:
void operator()(paddle::framework::InferVarTypeContext* ctx) const override { void operator()(paddle::framework::InferVarTypeContext* ctx) const override {
...@@ -77,7 +77,7 @@ REGISTER_OPERATOR(reduce_sum, ops::ReduceOp, ReduceSumOpMaker, ...@@ -77,7 +77,7 @@ REGISTER_OPERATOR(reduce_sum, ops::ReduceOp, ReduceSumOpMaker,
ops::ReduceSumOpGradMaker<paddle::framework::OpDesc>, ops::ReduceSumOpGradMaker<paddle::framework::OpDesc>,
ops::ReduceSumOpGradMaker<paddle::imperative::OpBase>); ops::ReduceSumOpGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(reduce_sum_grad, ops::ReduceGradOp, REGISTER_OPERATOR(reduce_sum_grad, ops::ReduceGradOp,
ops::ReduceSumGradNoNeedBufferVarInference); ops::ReduceSumGradNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
reduce_sum, ops::ReduceKernel<paddle::platform::CPUDeviceContext, float, reduce_sum, ops::ReduceKernel<paddle::platform::CPUDeviceContext, float,
......
...@@ -121,7 +121,7 @@ class RollGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -121,7 +121,7 @@ class RollGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(RollGradNoNeedBufferVarsInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(RollGradNoNeedBufferVarsInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -130,7 +130,7 @@ REGISTER_OPERATOR(roll, ops::RollOp, ops::RollOpMaker, ...@@ -130,7 +130,7 @@ REGISTER_OPERATOR(roll, ops::RollOp, ops::RollOpMaker,
ops::RollGradMaker<paddle::framework::OpDesc>, ops::RollGradMaker<paddle::framework::OpDesc>,
ops::RollGradMaker<paddle::imperative::OpBase>); ops::RollGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(roll_grad, ops::RollGradOp, REGISTER_OPERATOR(roll_grad, ops::RollGradOp,
ops::RollGradNoNeedBufferVarsInference); ops::RollGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
roll, ops::RollKernel<paddle::platform::CPUDeviceContext, float>, roll, ops::RollKernel<paddle::platform::CPUDeviceContext, float>,
ops::RollKernel<paddle::platform::CPUDeviceContext, double>, ops::RollKernel<paddle::platform::CPUDeviceContext, double>,
......
...@@ -170,7 +170,7 @@ class ScatterNdAddGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -170,7 +170,7 @@ class ScatterNdAddGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ScatterNdAddGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(ScatterNdAddGradNoNeedBufferVarsInferer,
"Updates"); "Updates");
} // namespace operators } // namespace operators
...@@ -183,7 +183,7 @@ REGISTER_OPERATOR(scatter_nd_add, ops::ScatterNdAddOp, ops::ScatterNdAddOpMaker, ...@@ -183,7 +183,7 @@ REGISTER_OPERATOR(scatter_nd_add, ops::ScatterNdAddOp, ops::ScatterNdAddOpMaker,
ops::ScatterNdAddGradMaker<paddle::imperative::OpBase>); ops::ScatterNdAddGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(scatter_nd_add_grad, ops::ScatterNdAddGradOp, REGISTER_OPERATOR(scatter_nd_add_grad, ops::ScatterNdAddGradOp,
ops::ScatterNdAddGradNoNeedBufferVarsInference); ops::ScatterNdAddGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL(scatter_nd_add, ops::ScatterNdAddOpKernel<float>, REGISTER_OP_CPU_KERNEL(scatter_nd_add, ops::ScatterNdAddOpKernel<float>,
ops::ScatterNdAddOpKernel<double>, ops::ScatterNdAddOpKernel<double>,
......
...@@ -134,7 +134,7 @@ class ScatterGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -134,7 +134,7 @@ class ScatterGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(ScatterGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(ScatterGradNoNeedBufferVarsInferer,
"Updates"); "Updates");
DECLARE_INPLACE_OP_INFERER(ScatterInplaceInferer, {"X", "Out"}); DECLARE_INPLACE_OP_INFERER(ScatterInplaceInferer, {"X", "Out"});
...@@ -151,7 +151,7 @@ REGISTER_OPERATOR(scatter, ops::ScatterOp, ops::ScatterOpMaker, ...@@ -151,7 +151,7 @@ REGISTER_OPERATOR(scatter, ops::ScatterOp, ops::ScatterOpMaker,
ops::ScatterGradMaker<paddle::imperative::OpBase>, ops::ScatterGradMaker<paddle::imperative::OpBase>,
ops::ScatterInplaceInferer); ops::ScatterInplaceInferer);
REGISTER_OPERATOR(scatter_grad, ops::ScatterGradOp, REGISTER_OPERATOR(scatter_grad, ops::ScatterGradOp,
ops::ScatterGradNoNeedBufferVarsInference, ops::ScatterGradNoNeedBufferVarsInferer,
ops::ScatterGradInplaceInferer); ops::ScatterGradInplaceInferer);
REGISTER_OP_CPU_KERNEL(scatter, ops::ScatterOpKernel<float>, REGISTER_OP_CPU_KERNEL(scatter, ops::ScatterOpKernel<float>,
ops::ScatterOpKernel<double>, ops::ScatterOpKernel<int>, ops::ScatterOpKernel<double>, ops::ScatterOpKernel<int>,
......
...@@ -123,8 +123,7 @@ class SeqConcatGradOp : public framework::OperatorWithKernel { ...@@ -123,8 +123,7 @@ class SeqConcatGradOp : public framework::OperatorWithKernel {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SeqConcatGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SeqConcatGradNoNeedBufferVarsInferer, "X");
"X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -140,7 +139,7 @@ REGISTER_OP_CPU_KERNEL(sequence_concat, Kernel<float>, Kernel<double>, ...@@ -140,7 +139,7 @@ REGISTER_OP_CPU_KERNEL(sequence_concat, Kernel<float>, Kernel<double>,
Kernel<int>, Kernel<int64_t>); Kernel<int>, Kernel<int64_t>);
REGISTER_OPERATOR(sequence_concat_grad, op::SeqConcatGradOp, REGISTER_OPERATOR(sequence_concat_grad, op::SeqConcatGradOp,
op::SeqConcatGradNoNeedBufferVarsInference); op::SeqConcatGradNoNeedBufferVarsInferer);
template <typename T> template <typename T>
using GradKernel = using GradKernel =
op::SeqConcatGradKernel<paddle::platform::CPUDeviceContext, T>; op::SeqConcatGradKernel<paddle::platform::CPUDeviceContext, T>;
......
...@@ -181,10 +181,10 @@ class SequenceExpandAsOpGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -181,10 +181,10 @@ class SequenceExpandAsOpGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceExpandAsOpNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceExpandAsOpNoNeedBufferVarsInferer,
"Y"); "Y");
DECLARE_NO_NEED_BUFFER_VARS_INFERER( DECLARE_NO_NEED_BUFFER_VARS_INFERER(
SequenceExpandAsGradOpNoNeedBufferVarsInference, "X", "Y"); SequenceExpandAsGradOpNoNeedBufferVarsInferer, "X", "Y");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -194,9 +194,9 @@ REGISTER_OPERATOR( ...@@ -194,9 +194,9 @@ REGISTER_OPERATOR(
sequence_expand_as, ops::SequenceExpandAsOp, ops::SequenceExpandAsOpMaker, sequence_expand_as, ops::SequenceExpandAsOp, ops::SequenceExpandAsOpMaker,
ops::SequenceExpandAsOpGradOpMaker<paddle::framework::OpDesc>, ops::SequenceExpandAsOpGradOpMaker<paddle::framework::OpDesc>,
ops::SequenceExpandAsOpGradOpMaker<paddle::imperative::OpBase>, ops::SequenceExpandAsOpGradOpMaker<paddle::imperative::OpBase>,
ops::SequenceExpandAsOpNoNeedBufferVarsInference); ops::SequenceExpandAsOpNoNeedBufferVarsInferer);
REGISTER_OPERATOR(sequence_expand_as_grad, ops::SequenceExpandAsOpGrad, REGISTER_OPERATOR(sequence_expand_as_grad, ops::SequenceExpandAsOpGrad,
ops::SequenceExpandAsGradOpNoNeedBufferVarsInference); ops::SequenceExpandAsGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_expand_as, sequence_expand_as,
ops::SequenceExpandAsKernel<paddle::platform::CPUDeviceContext, float>, ops::SequenceExpandAsKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -247,10 +247,10 @@ class SequenceExpandOpGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -247,10 +247,10 @@ class SequenceExpandOpGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceExpandOpNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceExpandOpNoNeedBufferVarsInferer,
"Y"); "Y");
DECLARE_NO_NEED_BUFFER_VARS_INFERER( DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceExpandGradOpNoNeedBufferVarsInferer,
SequenceExpandGradOpNoNeedBufferVarsInference, "X", "Y"); "X", "Y");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -260,9 +260,9 @@ REGISTER_OPERATOR(sequence_expand, ops::SequenceExpandOp, ...@@ -260,9 +260,9 @@ REGISTER_OPERATOR(sequence_expand, ops::SequenceExpandOp,
ops::SequenceExpandOpMaker, ops::SequenceExpandOpMaker,
ops::SequenceExpandOpGradMaker<paddle::framework::OpDesc>, ops::SequenceExpandOpGradMaker<paddle::framework::OpDesc>,
ops::SequenceExpandOpGradMaker<paddle::imperative::OpBase>, ops::SequenceExpandOpGradMaker<paddle::imperative::OpBase>,
ops::SequenceExpandOpNoNeedBufferVarsInference); ops::SequenceExpandOpNoNeedBufferVarsInferer);
REGISTER_OPERATOR(sequence_expand_grad, ops::SequenceExpandOpGrad, REGISTER_OPERATOR(sequence_expand_grad, ops::SequenceExpandOpGrad,
ops::SequenceExpandGradOpNoNeedBufferVarsInference); ops::SequenceExpandGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_expand, sequence_expand,
ops::SequenceExpandKernel<paddle::platform::CPUDeviceContext, float>, ops::SequenceExpandKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -251,7 +251,7 @@ class SequencePadGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -251,7 +251,7 @@ class SequencePadGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequencePadGradOpNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequencePadGradOpNoNeedBufferVarsInferer,
"X"); "X");
} // namespace operators } // namespace operators
...@@ -262,7 +262,7 @@ REGISTER_OPERATOR(sequence_pad, ops::SequencePadOp, ops::SequencePadOpMaker, ...@@ -262,7 +262,7 @@ REGISTER_OPERATOR(sequence_pad, ops::SequencePadOp, ops::SequencePadOpMaker,
ops::SequencePadGradOpMaker<paddle::framework::OpDesc>, ops::SequencePadGradOpMaker<paddle::framework::OpDesc>,
ops::SequencePadGradOpMaker<paddle::imperative::OpBase>); ops::SequencePadGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_pad_grad, ops::SequencePadGradOp, REGISTER_OPERATOR(sequence_pad_grad, ops::SequencePadGradOp,
ops::SequencePadGradOpNoNeedBufferVarsInference); ops::SequencePadGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_pad, sequence_pad,
ops::SequencePadOpKernel<paddle::platform::CPUDeviceContext, float>, ops::SequencePadOpKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -166,7 +166,7 @@ class SequencePoolGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -166,7 +166,7 @@ class SequencePoolGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequencePoolGradOpNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequencePoolGradOpNoNeedBufferVarsInferer,
"X"); "X");
} // namespace operators } // namespace operators
...@@ -177,7 +177,7 @@ REGISTER_OPERATOR(sequence_pool, ops::SequencePoolOp, ops::SequencePoolOpMaker, ...@@ -177,7 +177,7 @@ REGISTER_OPERATOR(sequence_pool, ops::SequencePoolOp, ops::SequencePoolOpMaker,
ops::SequencePoolGradOpMaker<paddle::framework::OpDesc>, ops::SequencePoolGradOpMaker<paddle::framework::OpDesc>,
ops::SequencePoolGradOpMaker<paddle::imperative::OpBase>); ops::SequencePoolGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_pool_grad, ops::SequencePoolGradOp, REGISTER_OPERATOR(sequence_pool_grad, ops::SequencePoolGradOp,
ops::SequencePoolGradOpNoNeedBufferVarsInference); ops::SequencePoolGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_pool, sequence_pool,
ops::SequencePoolKernel<paddle::platform::CPUDeviceContext, float>); ops::SequencePoolKernel<paddle::platform::CPUDeviceContext, float>);
......
...@@ -168,8 +168,8 @@ class SequenceScatterGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -168,8 +168,8 @@ class SequenceScatterGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER( DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceScatterGradNoNeedBufferVarsInferer,
SequenceScatterGradNoNeedBufferVarsInference, "Updates"); "Updates");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -180,7 +180,7 @@ REGISTER_OPERATOR(sequence_scatter, ops::SequenceScatterOp, ...@@ -180,7 +180,7 @@ REGISTER_OPERATOR(sequence_scatter, ops::SequenceScatterOp,
ops::SequenceScatterGradMaker<paddle::framework::OpDesc>, ops::SequenceScatterGradMaker<paddle::framework::OpDesc>,
ops::SequenceScatterGradMaker<paddle::imperative::OpBase>); ops::SequenceScatterGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_scatter_grad, ops::SequenceScatterGradOp, REGISTER_OPERATOR(sequence_scatter_grad, ops::SequenceScatterGradOp,
ops::SequenceScatterGradNoNeedBufferVarsInference); ops::SequenceScatterGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL(sequence_scatter, ops::SequenceScatterOpKernel<float>, REGISTER_OP_CPU_KERNEL(sequence_scatter, ops::SequenceScatterOpKernel<float>,
ops::SequenceScatterOpKernel<double>, ops::SequenceScatterOpKernel<double>,
ops::SequenceScatterOpKernel<int>, ops::SequenceScatterOpKernel<int>,
......
...@@ -137,7 +137,7 @@ class SequenceSliceGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -137,7 +137,7 @@ class SequenceSliceGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceSliceGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceSliceGradNoNeedBufferVarsInferer,
"X"); "X");
} // namespace operators } // namespace operators
...@@ -149,7 +149,7 @@ REGISTER_OPERATOR(sequence_slice, ops::SequenceSliceOp, ...@@ -149,7 +149,7 @@ REGISTER_OPERATOR(sequence_slice, ops::SequenceSliceOp,
ops::SequenceSliceGradOpMaker<paddle::framework::OpDesc>, ops::SequenceSliceGradOpMaker<paddle::framework::OpDesc>,
ops::SequenceSliceGradOpMaker<paddle::imperative::OpBase>); ops::SequenceSliceGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_slice_grad, ops::SequenceSliceGradOp, REGISTER_OPERATOR(sequence_slice_grad, ops::SequenceSliceGradOp,
ops::SequenceSliceGradNoNeedBufferVarsInference); ops::SequenceSliceGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_slice, sequence_slice,
ops::SequenceSliceOpKernel<paddle::platform::CPUDeviceContext, float>, ops::SequenceSliceOpKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -33,12 +33,17 @@ class SequenceSoftmaxCUDNNKernel : public framework::OpKernel<T> { ...@@ -33,12 +33,17 @@ class SequenceSoftmaxCUDNNKernel : public framework::OpKernel<T> {
auto& dims = x->dims(); auto& dims = x->dims();
const size_t level = lod.size() - 1; const size_t level = lod.size() - 1;
PADDLE_ENFORCE_EQ(dims[0], static_cast<int64_t>(lod[level].back()), PADDLE_ENFORCE_EQ(
"The first dimension of Input(X) should be equal to the " dims[0], static_cast<int64_t>(lod[level].back()),
"sum of all sequences' lengths."); platform::errors::InvalidArgument(
"The first dimension of Input(X) should be equal to the sum of all "
"sequences' lengths. But received first dimension of Input(X) is "
"%d, the sum of all sequences' lengths is %d.",
dims[0], static_cast<int64_t>(lod[level].back())));
PADDLE_ENFORCE_EQ(dims[0], x->numel(), PADDLE_ENFORCE_EQ(dims[0], x->numel(),
"The width of each timestep in Input(X) of " platform::errors::InvalidArgument(
"SequenceSoftmaxOp should be 1."); "The width of each timestep in Input(X) of "
"SequenceSoftmaxOp should be 1."));
out->mutable_data<T>(ctx.GetPlace()); out->mutable_data<T>(ctx.GetPlace());
for (int i = 0; i < static_cast<int>(lod[level].size()) - 1; ++i) { for (int i = 0; i < static_cast<int>(lod[level].size()) - 1; ++i) {
......
...@@ -169,8 +169,8 @@ class SequenceUnpadGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -169,8 +169,8 @@ class SequenceUnpadGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER( DECLARE_NO_NEED_BUFFER_VARS_INFERER(SequenceUnpadGradOpNoNeedBufferVarsInferer,
SequenceUnpadGradOpNoNeedBufferVarsInference, "X"); "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -181,7 +181,7 @@ REGISTER_OPERATOR(sequence_unpad, ops::SequenceUnpadOp, ...@@ -181,7 +181,7 @@ REGISTER_OPERATOR(sequence_unpad, ops::SequenceUnpadOp,
ops::SequenceUnpadGradOpMaker<paddle::framework::OpDesc>, ops::SequenceUnpadGradOpMaker<paddle::framework::OpDesc>,
ops::SequenceUnpadGradOpMaker<paddle::imperative::OpBase>); ops::SequenceUnpadGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(sequence_unpad_grad, ops::SequenceUnpadGradOp, REGISTER_OPERATOR(sequence_unpad_grad, ops::SequenceUnpadGradOp,
ops::SequenceUnpadGradOpNoNeedBufferVarsInference); ops::SequenceUnpadGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
sequence_unpad, sequence_unpad,
ops::SequenceUnpadOpKernel<paddle::platform::CPUDeviceContext, float>, ops::SequenceUnpadOpKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -377,7 +377,7 @@ class SliceDoubleOpGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -377,7 +377,7 @@ class SliceDoubleOpGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SliceOpGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(SliceOpGradNoNeedBufferVarsInferer,
"Input"); "Input");
} // namespace operators } // namespace operators
...@@ -391,7 +391,7 @@ REGISTER_OPERATOR(slice, ops::SliceOp, ops::SliceOpMaker, ...@@ -391,7 +391,7 @@ REGISTER_OPERATOR(slice, ops::SliceOp, ops::SliceOpMaker,
REGISTER_OPERATOR(slice_grad, ops::SliceOpGrad, REGISTER_OPERATOR(slice_grad, ops::SliceOpGrad,
ops::SliceDoubleOpGradMaker<paddle::framework::OpDesc>, ops::SliceDoubleOpGradMaker<paddle::framework::OpDesc>,
ops::SliceDoubleOpGradMaker<paddle::imperative::OpBase>, ops::SliceDoubleOpGradMaker<paddle::imperative::OpBase>,
ops::SliceOpGradNoNeedBufferVarsInference, ops::SliceOpGradNoNeedBufferVarsInferer,
ops::SliceOpGradVarTypeInference); ops::SliceOpGradVarTypeInference);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
......
...@@ -131,7 +131,7 @@ class SpaceToDepthOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -131,7 +131,7 @@ class SpaceToDepthOpMaker : public framework::OpProtoAndCheckerMaker {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SpaceToDepthGradOpNoBuffer, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(SpaceToDepthGradOpNoBufferVarsInferer, "X");
template <typename T> template <typename T>
class SpaceToDepthGradOpMaker : public framework::SingleGradOpMaker<T> { class SpaceToDepthGradOpMaker : public framework::SingleGradOpMaker<T> {
...@@ -179,7 +179,7 @@ REGISTER_OPERATOR(space_to_depth, ops::SpaceToDepthOp, ops::SpaceToDepthOpMaker, ...@@ -179,7 +179,7 @@ REGISTER_OPERATOR(space_to_depth, ops::SpaceToDepthOp, ops::SpaceToDepthOpMaker,
ops::SpaceToDepthGradOpMaker<paddle::framework::OpDesc>, ops::SpaceToDepthGradOpMaker<paddle::framework::OpDesc>,
ops::SpaceToDepthGradOpMaker<paddle::imperative::OpBase>); ops::SpaceToDepthGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(space_to_depth_grad, ops::SpaceToDepthGradOp, REGISTER_OPERATOR(space_to_depth_grad, ops::SpaceToDepthGradOp,
ops::SpaceToDepthGradOpNoBuffer); ops::SpaceToDepthGradOpNoBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
space_to_depth, space_to_depth,
ops::SpaceToDepthKernel<paddle::platform::CPUDeviceContext, float>, ops::SpaceToDepthKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -88,7 +88,8 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel { ...@@ -88,7 +88,8 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SquaredL2DistanceGradOpNoBuffer, "X", "Y"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(SquaredL2DistanceGradOpNoBufferVarsInferer,
"X", "Y");
template <typename T> template <typename T>
class SquaredL2DistanceGradOpMaker : public framework::SingleGradOpMaker<T> { class SquaredL2DistanceGradOpMaker : public framework::SingleGradOpMaker<T> {
...@@ -192,7 +193,7 @@ REGISTER_OPERATOR( ...@@ -192,7 +193,7 @@ REGISTER_OPERATOR(
ops::SquaredL2DistanceGradOpMaker<paddle::framework::OpDesc>, ops::SquaredL2DistanceGradOpMaker<paddle::framework::OpDesc>,
ops::SquaredL2DistanceGradOpMaker<paddle::imperative::OpBase>); ops::SquaredL2DistanceGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(squared_l2_distance_grad, ops::SquaredL2DistanceGradOp, REGISTER_OPERATOR(squared_l2_distance_grad, ops::SquaredL2DistanceGradOp,
ops::SquaredL2DistanceGradOpNoBuffer); ops::SquaredL2DistanceGradOpNoBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
squared_l2_distance, squared_l2_distance,
ops::SquaredL2DistanceKernel<paddle::platform::CPUDeviceContext, float>); ops::SquaredL2DistanceKernel<paddle::platform::CPUDeviceContext, float>);
......
...@@ -275,7 +275,7 @@ DECLARE_INPLACE_OP_INFERER(SequeezeInplaceInferer, {"X", "Out"}); ...@@ -275,7 +275,7 @@ DECLARE_INPLACE_OP_INFERER(SequeezeInplaceInferer, {"X", "Out"});
DECLARE_INPLACE_OP_INFERER(SequeezeGradInplaceInferer, DECLARE_INPLACE_OP_INFERER(SequeezeGradInplaceInferer,
{framework::GradVarName("Out"), {framework::GradVarName("Out"),
framework::GradVarName("X")}); framework::GradVarName("X")});
DECLARE_NO_NEED_BUFFER_VARS_INFERER(SqueezeGradNoNeedBufferVarsInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(SqueezeGradNoNeedBufferVarsInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -284,7 +284,7 @@ REGISTER_OPERATOR(squeeze, ops::SqueezeOp, ops::SqueezeOpMaker, ...@@ -284,7 +284,7 @@ REGISTER_OPERATOR(squeeze, ops::SqueezeOp, ops::SqueezeOpMaker,
ops::SqueezeGradOpMaker<paddle::framework::OpDesc>, ops::SqueezeGradOpMaker<paddle::framework::OpDesc>,
ops::SqueezeGradOpMaker<paddle::imperative::OpBase>); ops::SqueezeGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(squeeze_grad, ops::SqueezeGradOp, REGISTER_OPERATOR(squeeze_grad, ops::SqueezeGradOp,
ops::SqueezeGradNoNeedBufferVarsInference); ops::SqueezeGradNoNeedBufferVarsInferer);
REGISTER_OPERATOR(squeeze2, ops::Squeeze2Op, ops::Squeeze2OpMaker, REGISTER_OPERATOR(squeeze2, ops::Squeeze2Op, ops::Squeeze2OpMaker,
ops::Squeeze2GradOpMaker<paddle::framework::OpDesc>, ops::Squeeze2GradOpMaker<paddle::framework::OpDesc>,
......
...@@ -304,7 +304,7 @@ class StridedSliceOpGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -304,7 +304,7 @@ class StridedSliceOpGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(StridedSliceOpGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(StridedSliceOpGradNoNeedBufferVarsInferer,
"Input"); "Input");
} // namespace operators } // namespace operators
...@@ -315,7 +315,7 @@ REGISTER_OPERATOR(strided_slice, ops::StridedSliceOp, ops::StridedSliceOpMaker, ...@@ -315,7 +315,7 @@ REGISTER_OPERATOR(strided_slice, ops::StridedSliceOp, ops::StridedSliceOpMaker,
ops::StridedSliceOpGradMaker<paddle::framework::OpDesc>, ops::StridedSliceOpGradMaker<paddle::framework::OpDesc>,
ops::StridedSliceOpGradMaker<paddle::imperative::OpBase>); ops::StridedSliceOpGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(strided_slice_grad, ops::StridedSliceOpGrad, REGISTER_OPERATOR(strided_slice_grad, ops::StridedSliceOpGrad,
ops::StridedSliceOpGradNoNeedBufferVarsInference); ops::StridedSliceOpGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
strided_slice, strided_slice,
......
...@@ -147,8 +147,7 @@ class TraceGradOpMaker : public framework::SingleGradOpMaker<T> { ...@@ -147,8 +147,7 @@ class TraceGradOpMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(TraceGradNoNeedBufferVarsInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(TraceGradNoNeedBufferVarsInferer, "Input");
"Input");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -159,7 +158,7 @@ REGISTER_OPERATOR(trace, ops::TraceOp, ops::TraceOpMaker, ...@@ -159,7 +158,7 @@ REGISTER_OPERATOR(trace, ops::TraceOp, ops::TraceOpMaker,
ops::TraceGradOpMaker<paddle::imperative::OpBase>); ops::TraceGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(trace_grad, ops::TraceOpGrad, REGISTER_OPERATOR(trace_grad, ops::TraceOpGrad,
ops::TraceGradNoNeedBufferVarsInference); ops::TraceGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
trace, ops::TraceKernel<paddle::platform::CPUDeviceContext, int>, trace, ops::TraceKernel<paddle::platform::CPUDeviceContext, int>,
ops::TraceKernel<paddle::platform::CPUDeviceContext, float>, ops::TraceKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -174,7 +174,7 @@ class UnfoldGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -174,7 +174,7 @@ class UnfoldGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(UnfoldGradOpNoNeedBufferVarsInference, "X"); DECLARE_NO_NEED_BUFFER_VARS_INFERER(UnfoldGradOpNoNeedBufferVarsInferer, "X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -184,7 +184,7 @@ REGISTER_OPERATOR(unfold, ops::UnfoldOp, ops::UnfoldOpMaker, ...@@ -184,7 +184,7 @@ REGISTER_OPERATOR(unfold, ops::UnfoldOp, ops::UnfoldOpMaker,
ops::UnfoldGradMaker<paddle::framework::OpDesc>, ops::UnfoldGradMaker<paddle::framework::OpDesc>,
ops::UnfoldGradMaker<paddle::imperative::OpBase>); ops::UnfoldGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(unfold_grad, ops::UnfoldGradOp, REGISTER_OPERATOR(unfold_grad, ops::UnfoldGradOp,
ops::UnfoldGradOpNoNeedBufferVarsInference); ops::UnfoldGradOpNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
unfold, ops::UnfoldOpKernel<paddle::platform::CPUDeviceContext, float>, unfold, ops::UnfoldOpKernel<paddle::platform::CPUDeviceContext, float>,
......
...@@ -78,5 +78,5 @@ REGISTER_OPERATOR( ...@@ -78,5 +78,5 @@ REGISTER_OPERATOR(
paddle::operators::UniformRandomBatchSizeLikeOpMaker, paddle::operators::UniformRandomBatchSizeLikeOpMaker,
paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>, paddle::framework::EmptyGradOpMaker<paddle::framework::OpDesc>,
paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>, paddle::framework::EmptyGradOpMaker<paddle::imperative::OpBase>,
paddle::operators::BatchSizeLikeNoNeedBufferVarsInference); paddle::operators::BatchSizeLikeNoNeedBufferVarsInferer);
// Kernels are registered in uniform_random_op.cc and uniform_random_op.cu // Kernels are registered in uniform_random_op.cc and uniform_random_op.cu
...@@ -306,8 +306,7 @@ DECLARE_INPLACE_OP_INFERER(UnsqueezeInplaceInferer, {"X", "Out"}); ...@@ -306,8 +306,7 @@ DECLARE_INPLACE_OP_INFERER(UnsqueezeInplaceInferer, {"X", "Out"});
DECLARE_INPLACE_OP_INFERER(UnsqueezeGradInplaceInferer, DECLARE_INPLACE_OP_INFERER(UnsqueezeGradInplaceInferer,
{framework::GradVarName("Out"), {framework::GradVarName("Out"),
framework::GradVarName("X")}); framework::GradVarName("X")});
DECLARE_NO_NEED_BUFFER_VARS_INFERER(UnsqueezeGradOpNoNeedBufferVarInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(UnsqueezeGradOpNoNeedBufferVarInferer, "X");
"X");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -316,7 +315,7 @@ REGISTER_OPERATOR(unsqueeze, ops::UnsqueezeOp, ops::UnsqueezeOpMaker, ...@@ -316,7 +315,7 @@ REGISTER_OPERATOR(unsqueeze, ops::UnsqueezeOp, ops::UnsqueezeOpMaker,
ops::UnsqueezeGradOpMaker<paddle::framework::OpDesc>, ops::UnsqueezeGradOpMaker<paddle::framework::OpDesc>,
ops::UnsqueezeGradOpMaker<paddle::imperative::OpBase>); ops::UnsqueezeGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(unsqueeze_grad, ops::UnsqueezeGradOp, REGISTER_OPERATOR(unsqueeze_grad, ops::UnsqueezeGradOp,
ops::UnsqueezeGradOpNoNeedBufferVarInference); ops::UnsqueezeGradOpNoNeedBufferVarInferer);
REGISTER_OPERATOR(unsqueeze2, ops::Unsqueeze2Op, ops::Unsqueeze2OpMaker, REGISTER_OPERATOR(unsqueeze2, ops::Unsqueeze2Op, ops::Unsqueeze2OpMaker,
ops::Unsqueeze2GradOpMaker<paddle::framework::OpDesc>, ops::Unsqueeze2GradOpMaker<paddle::framework::OpDesc>,
......
...@@ -184,7 +184,7 @@ class WarpCTCGradOp : public framework::OperatorWithKernel { ...@@ -184,7 +184,7 @@ class WarpCTCGradOp : public framework::OperatorWithKernel {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(WarpCTCGradOpNoNeedBufferVarInference, DECLARE_NO_NEED_BUFFER_VARS_INFERER(WarpCTCGradOpNoNeedBufferVarInferer,
"Logits"); "Logits");
} // namespace operators } // namespace operators
...@@ -195,7 +195,7 @@ REGISTER_OPERATOR(warpctc, ops::WarpCTCOp, ops::WarpCTCOpMaker, ...@@ -195,7 +195,7 @@ REGISTER_OPERATOR(warpctc, ops::WarpCTCOp, ops::WarpCTCOpMaker,
ops::WarpCTCGradOpMaker<paddle::framework::OpDesc>, ops::WarpCTCGradOpMaker<paddle::framework::OpDesc>,
ops::WarpCTCGradOpMaker<paddle::imperative::OpBase>); ops::WarpCTCGradOpMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(warpctc_grad, ops::WarpCTCGradOp, REGISTER_OPERATOR(warpctc_grad, ops::WarpCTCGradOp,
ops::WarpCTCGradOpNoNeedBufferVarInference); ops::WarpCTCGradOpNoNeedBufferVarInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
warpctc, ops::WarpCTCKernel<paddle::platform::CPUDeviceContext, float>); warpctc, ops::WarpCTCKernel<paddle::platform::CPUDeviceContext, float>);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
......
...@@ -135,8 +135,7 @@ class WhereOpGradMaker : public framework::SingleGradOpMaker<T> { ...@@ -135,8 +135,7 @@ class WhereOpGradMaker : public framework::SingleGradOpMaker<T> {
} }
}; };
DECLARE_NO_NEED_BUFFER_VARS_INFERER(WhereGradNoNeedBufferVarsInference, "X", DECLARE_NO_NEED_BUFFER_VARS_INFERER(WhereGradNoNeedBufferVarsInferer, "X", "Y");
"Y");
} // namespace operators } // namespace operators
} // namespace paddle } // namespace paddle
...@@ -146,7 +145,7 @@ REGISTER_OPERATOR(where, ops::WhereOp, ops::WhereOpMaker, ...@@ -146,7 +145,7 @@ REGISTER_OPERATOR(where, ops::WhereOp, ops::WhereOpMaker,
ops::WhereOpGradMaker<paddle::imperative::OpBase>); ops::WhereOpGradMaker<paddle::imperative::OpBase>);
REGISTER_OPERATOR(where_grad, ops::WhereGradOp, REGISTER_OPERATOR(where_grad, ops::WhereGradOp,
ops::WhereGradNoNeedBufferVarsInference); ops::WhereGradNoNeedBufferVarsInferer);
REGISTER_OP_CPU_KERNEL( REGISTER_OP_CPU_KERNEL(
where, ops::WhereKernel<paddle::platform::CPUDeviceContext, float>, where, ops::WhereKernel<paddle::platform::CPUDeviceContext, float>,
ops::WhereKernel<paddle::platform::CPUDeviceContext, double>, ops::WhereKernel<paddle::platform::CPUDeviceContext, double>,
......
...@@ -641,22 +641,24 @@ DeviceTracer *GetDeviceTracer() { ...@@ -641,22 +641,24 @@ DeviceTracer *GetDeviceTracer() {
return tracer; return tracer;
} }
std::string SetCurAnnotation(Event *event) { // In order to record PE time, we add main_thread_annotation_stack
// for all event between PE run, we treat it as PE's child Event,
// so when event is not in same thread of PE event, we need add
// father event(PE::run event) for this event
void SetCurAnnotation(Event *event) {
std::string ret; std::string ret;
if (!annotation_stack.empty() && event->role() != EventRole::kSpecial) { if (!annotation_stack.empty()) {
event->set_parent(annotation_stack.back()); event->set_parent(annotation_stack.back());
event->set_name(annotation_stack.back()->name() + "/" + event->name()); event->set_name(annotation_stack.back()->name() + "/" + event->name());
} }
if (annotation_stack.empty() && !main_thread_annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() != event->thread_id()) {
event->set_parent(main_thread_annotation_stack.back());
event->set_name(main_thread_annotation_stack.back()->name() + "/" +
event->name());
}
annotation_stack.push_back(event); annotation_stack.push_back(event);
if (!main_thread_annotation_stack_name.empty() && !annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() !=
annotation_stack.back()->thread_id()) {
ret = main_thread_annotation_stack_name.back() + "/" + event->name();
} else {
ret = event->name();
}
if (event->role() == EventRole::kSpecial) { if (event->role() == EventRole::kSpecial) {
std::string name = event->name(); std::string name = event->name();
if (!main_thread_annotation_stack_name.empty()) { if (!main_thread_annotation_stack_name.empty()) {
...@@ -665,22 +667,23 @@ std::string SetCurAnnotation(Event *event) { ...@@ -665,22 +667,23 @@ std::string SetCurAnnotation(Event *event) {
main_thread_annotation_stack_name.push_back(name); main_thread_annotation_stack_name.push_back(name);
main_thread_annotation_stack.push_back(event); main_thread_annotation_stack.push_back(event);
} }
return ret;
} }
void ClearCurAnnotation() { void ClearCurAnnotation() {
if (!main_thread_annotation_stack_name.empty() && !annotation_stack.empty() &&
main_thread_annotation_stack.back()->thread_id() !=
annotation_stack.back()->thread_id()) {
annotation_stack.back()->set_name(main_thread_annotation_stack_name.back() +
"/" + annotation_stack.back()->name());
}
if (!main_thread_annotation_stack.empty() && if (!main_thread_annotation_stack.empty() &&
main_thread_annotation_stack.back()->name() == main_thread_annotation_stack.back()->name() ==
annotation_stack.back()->name()) { annotation_stack.back()->name()) {
main_thread_annotation_stack_name.pop_back(); std::string name = annotation_stack.back()->name();
main_thread_annotation_stack.pop_back(); std::string main_name = main_thread_annotation_stack.back()->name();
int main_name_len = main_name.length();
int name_len = name.length();
int prefix_len = main_name_len - name_len;
if (prefix_len >= 0 && main_name.at(prefix_len) == '/' &&
name == main_name.substr(prefix_len, name_len)) {
main_thread_annotation_stack_name.pop_back();
main_thread_annotation_stack.pop_back();
}
} }
annotation_stack.pop_back(); annotation_stack.pop_back();
} }
......
...@@ -137,7 +137,7 @@ class DeviceTracer { ...@@ -137,7 +137,7 @@ class DeviceTracer {
DeviceTracer* GetDeviceTracer(); DeviceTracer* GetDeviceTracer();
// Set a name for the cuda kernel operation being launched by the thread. // Set a name for the cuda kernel operation being launched by the thread.
std::string SetCurAnnotation(Event* event); void SetCurAnnotation(Event* event);
// Clear the name after the operation is done. // Clear the name after the operation is done.
void ClearCurAnnotation(); void ClearCurAnnotation();
// Current name of the operation being run in the thread. // Current name of the operation being run in the thread.
......
...@@ -73,7 +73,8 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) { ...@@ -73,7 +73,8 @@ RecordEvent::RecordEvent(const std::string &name, const EventRole role) {
// lock is not needed, the code below is thread-safe // lock is not needed, the code below is thread-safe
Event *e = PushEvent(name, role); Event *e = PushEvent(name, role);
// Maybe need the same push/pop behavior. // Maybe need the same push/pop behavior.
name_ = SetCurAnnotation(e); SetCurAnnotation(e);
name_ = e->name();
} }
RecordEvent::~RecordEvent() { RecordEvent::~RecordEvent() {
......
...@@ -83,7 +83,7 @@ _op_real_in_out_name = { ...@@ -83,7 +83,7 @@ _op_real_in_out_name = {
"swish": [["X"], ["Out"]], "swish": [["X"], ["Out"]],
"dropout": [["X"], ["Out"]], "dropout": [["X"], ["Out"]],
"batch_norm": [["X"], ["Y"]], "batch_norm": [["X"], ["Y"]],
"sigmoid": [["X"], ["Y"]], "sigmoid": [["X"], ["Out"]],
} }
......
...@@ -550,6 +550,7 @@ class ProgramTranslator(object): ...@@ -550,6 +550,7 @@ class ProgramTranslator(object):
source_code = ast_to_source_code(root_wrapper.node) source_code = ast_to_source_code(root_wrapper.node)
return source_code return source_code
@switch_to_static_graph
def save_inference_model(self, dirname, feed=None, fetch=None): def save_inference_model(self, dirname, feed=None, fetch=None):
""" """
Saves current model as the inference model. It will prune the main_program Saves current model as the inference model. It will prune the main_program
......
...@@ -37,9 +37,6 @@ def monkey_patch_math_varbase(): ...@@ -37,9 +37,6 @@ def monkey_patch_math_varbase():
The difference is, in dygraph mode, use auto-generated op functions for better performance. The difference is, in dygraph mode, use auto-generated op functions for better performance.
""" """
def safe_get_dtype(var):
return var.dtype
@no_grad @no_grad
def create_tensor(value, dtype, shape): def create_tensor(value, dtype, shape):
out = _varbase_creator(dtype=dtype) out = _varbase_creator(dtype=dtype)
...@@ -96,8 +93,9 @@ def monkey_patch_math_varbase(): ...@@ -96,8 +93,9 @@ def monkey_patch_math_varbase():
print("new var's dtype is: {}, numpy dtype is {}".format(new_variable.dtype, new_variable.numpy().dtype)) print("new var's dtype is: {}, numpy dtype is {}".format(new_variable.dtype, new_variable.numpy().dtype))
""" """
return core.ops.cast(self, 'in_dtype', self.dtype, 'out_dtype', if not isinstance(dtype, core.VarDesc.VarType):
convert_np_dtype_to_dtype_(dtype)) dtype = convert_np_dtype_to_dtype_(dtype)
return core.ops.cast(self, 'in_dtype', self.dtype, 'out_dtype', dtype)
def _scalar_elementwise_op_(var, scale, bias): def _scalar_elementwise_op_(var, scale, bias):
return core.ops.scale(var, 'scale', scale, 'bias', bias) return core.ops.scale(var, 'scale', scale, 'bias', bias)
...@@ -175,7 +173,7 @@ def monkey_patch_math_varbase(): ...@@ -175,7 +173,7 @@ def monkey_patch_math_varbase():
elif isinstance(other_var, int): elif isinstance(other_var, int):
return scalar_method(self, float(other_var)) return scalar_method(self, float(other_var))
lhs_dtype = safe_get_dtype(self) lhs_dtype = self.dtype
if not isinstance(other_var, core.VarBase): if not isinstance(other_var, core.VarBase):
if reverse: if reverse:
...@@ -185,7 +183,7 @@ def monkey_patch_math_varbase(): ...@@ -185,7 +183,7 @@ def monkey_patch_math_varbase():
# add fill_op # add fill_op
other_var = create_scalar(value=other_var, dtype=lhs_dtype) other_var = create_scalar(value=other_var, dtype=lhs_dtype)
rhs_dtype = safe_get_dtype(other_var) rhs_dtype = other_var.dtype
if lhs_dtype != rhs_dtype: if lhs_dtype != rhs_dtype:
other_var = astype(other_var, lhs_dtype) other_var = astype(other_var, lhs_dtype)
if reverse: if reverse:
......
...@@ -200,7 +200,6 @@ class TestMNISTWithDeclarative(TestMNIST): ...@@ -200,7 +200,6 @@ class TestMNISTWithDeclarative(TestMNIST):
break break
return loss_data return loss_data
@switch_to_static_graph
def check_save_inference_model(self, inputs, prog_trans, to_static, gt_out): def check_save_inference_model(self, inputs, prog_trans, to_static, gt_out):
if to_static: if to_static:
infer_model_path = "./test_mnist_inference_model" infer_model_path = "./test_mnist_inference_model"
...@@ -208,6 +207,7 @@ class TestMNISTWithDeclarative(TestMNIST): ...@@ -208,6 +207,7 @@ class TestMNISTWithDeclarative(TestMNIST):
infer_out = self.load_and_run_inference(infer_model_path, inputs) infer_out = self.load_and_run_inference(infer_model_path, inputs)
self.assertTrue(np.allclose(gt_out.numpy(), infer_out)) self.assertTrue(np.allclose(gt_out.numpy(), infer_out))
@switch_to_static_graph
def load_and_run_inference(self, model_path, inputs): def load_and_run_inference(self, model_path, inputs):
exe = fluid.Executor(self.place) exe = fluid.Executor(self.place)
[inference_program, feed_target_names, [inference_program, feed_target_names,
......
...@@ -30,6 +30,7 @@ np.random.seed(SEED) ...@@ -30,6 +30,7 @@ np.random.seed(SEED)
place = fluid.CUDAPlace(0) if fluid.is_compiled_with_cuda() else fluid.CPUPlace( place = fluid.CUDAPlace(0) if fluid.is_compiled_with_cuda() else fluid.CPUPlace(
) )
program_translator = ProgramTranslator()
class SimpleFcLayer(fluid.dygraph.Layer): class SimpleFcLayer(fluid.dygraph.Layer):
...@@ -63,6 +64,10 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase): ...@@ -63,6 +64,10 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase):
loss.backward() loss.backward()
adam.minimize(loss) adam.minimize(loss)
layer.clear_gradients() layer.clear_gradients()
# test for saving model in dygraph.guard
infer_model_dir = "./test_dy2stat_save_inference_model"
program_translator.save_inference_model(
infer_model_dir, feed=[0], fetch=[1])
# Check the correctness of the inference # Check the correctness of the inference
dygraph_out, _ = layer(x) dygraph_out, _ = layer(x)
self.check_save_inference_model(layer, [x_data], dygraph_out.numpy()) self.check_save_inference_model(layer, [x_data], dygraph_out.numpy())
...@@ -77,7 +82,7 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase): ...@@ -77,7 +82,7 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase):
gt_out, gt_out,
feed=None, feed=None,
fetch=None): fetch=None):
program_translator = ProgramTranslator()
expected_persistable_vars = set([p.name for p in model.parameters()]) expected_persistable_vars = set([p.name for p in model.parameters()])
infer_model_dir = "./test_dy2stat_save_inference_model" infer_model_dir = "./test_dy2stat_save_inference_model"
......
...@@ -109,6 +109,7 @@ class TestConv2dTransposeOp(OpTest): ...@@ -109,6 +109,7 @@ class TestConv2dTransposeOp(OpTest):
def setUp(self): def setUp(self):
# init as conv transpose # init as conv transpose
self.dtype = np.float64 self.dtype = np.float64
self.need_check_grad = True
self.is_test = False self.is_test = False
self.use_cudnn = False self.use_cudnn = False
self.use_mkldnn = False self.use_mkldnn = False
...@@ -152,35 +153,40 @@ class TestConv2dTransposeOp(OpTest): ...@@ -152,35 +153,40 @@ class TestConv2dTransposeOp(OpTest):
self.check_output(check_dygraph=(self.use_mkldnn == False)) self.check_output(check_dygraph=(self.use_mkldnn == False))
def test_check_grad_no_input(self): def test_check_grad_no_input(self):
if self.use_cudnn: if self.need_check_grad:
place = core.CUDAPlace(0) if self.use_cudnn:
self.check_grad_with_place( place = core.CUDAPlace(0)
place, ['Filter'], self.check_grad_with_place(
'Output', place, ['Filter'],
max_relative_error=0.02, 'Output',
no_grad_set=set(['Input'])) max_relative_error=0.02,
else: no_grad_set=set(['Input']))
self.check_grad(['Filter'], 'Output', no_grad_set=set(['Input'])) else:
self.check_grad(
['Filter'], 'Output', no_grad_set=set(['Input']))
def test_check_grad_no_filter(self): def test_check_grad_no_filter(self):
if self.use_cudnn: if self.need_check_grad:
place = core.CUDAPlace(0) if self.use_cudnn:
self.check_grad_with_place( place = core.CUDAPlace(0)
place, ['Input'], 'Output', no_grad_set=set(['Filter'])) self.check_grad_with_place(
else: place, ['Input'], 'Output', no_grad_set=set(['Filter']))
self.check_grad(['Input'], 'Output', no_grad_set=set(['Filter'])) else:
self.check_grad(
['Input'], 'Output', no_grad_set=set(['Filter']))
def test_check_grad(self): def test_check_grad(self):
if self.use_cudnn: if self.need_check_grad:
place = core.CUDAPlace(0) if self.use_cudnn:
self.check_grad_with_place( place = core.CUDAPlace(0)
place, self.check_grad_with_place(
set(['Input', 'Filter']), place,
'Output', set(['Input', 'Filter']),
max_relative_error=0.02) 'Output',
else: max_relative_error=0.02)
self.check_grad( else:
set(['Input', 'Filter']), 'Output', max_relative_error=0.02) self.check_grad(
set(['Input', 'Filter']), 'Output', max_relative_error=0.02)
def init_test_case(self): def init_test_case(self):
self.pad = [0, 0] self.pad = [0, 0]
...@@ -708,6 +714,124 @@ class TestDepthwiseConvTransposeAsymmetricPad_NHWC(TestConv2dTransposeOp): ...@@ -708,6 +714,124 @@ class TestDepthwiseConvTransposeAsymmetricPad_NHWC(TestConv2dTransposeOp):
self.data_format = 'NHWC' self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNN_FP16(TestConv2dTransposeOp):
def init_test_case(self):
self.dtype = np.float16
self.pad = [1, 1]
self.stride = [1, 1]
self.groups = 1
self.dilations = [1, 1]
self.input_size = [2, 3, 5, 5] # NCHW
f_c = self.input_size[1]
self.filter_size = [f_c, 6, 3, 3]
def init_op_type(self):
self.need_check_grad = False
self.use_cudnn = True
self.op_type = "conv2d_transpose"
def test_check_output(self):
if self.use_cudnn:
place = core.CUDAPlace(0)
self.check_output_with_place(
place, atol=0.02, check_dygraph=(self.use_mkldnn == False))
else:
self.check_output(check_dygraph=(self.use_mkldnn == False))
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNN_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [0, 0]
self.stride = [1, 1]
self.dilations = [1, 1]
self.groups = 1
self.input_size = [2, 5, 5, 3] # NHWC
f_c = self.input_size[-1]
self.filter_size = [f_c, 6, 3, 3]
self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNNWithSymmetricPad_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [1, 1]
self.stride = [1, 1]
self.groups = 1
self.dilations = [1, 1]
self.input_size = [2, 5, 5, 3] # NHWC
f_c = self.input_size[-1]
self.filter_size = [f_c, 6, 3, 3]
self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNNWithAsymmetricPad_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [1, 0, 2, 3]
self.stride = [2, 2]
self.groups = 1
self.dilations = [1, 1]
self.input_size = [2, 5, 5, 3] # NHWC
f_c = self.input_size[-1]
self.filter_size = [f_c, 6, 3, 3]
self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNNWithStride_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [1, 1]
self.stride = [2, 2]
self.groups = 1
self.dilations = [1, 1]
self.input_size = [2, 5, 5, 3] # NHWC
f_c = self.input_size[-1]
self.filter_size = [f_c, 6, 3, 3]
self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNNWithGroups_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [1, 1]
self.stride = [1, 1]
self.dilations = [1, 1]
self.groups = 2
self.input_size = [2, 5, 5, 4] # NCHW
f_c = self.input_size[-1]
self.filter_size = [f_c, 3, 3, 3]
self.data_format = 'NHWC'
@unittest.skipIf(not core.is_compiled_with_cuda(),
"core is not compiled with CUDA")
class TestCUDNNWithEvenUpsample_NHWC_FP16(TestCUDNN_FP16):
def init_test_case(self):
self.dtype = np.float16
self.pad = [2, 2]
self.stride = [2, 2]
self.groups = 1
self.dilations = [1, 1]
self.output_size = [14, 14]
self.input_size = [2, 7, 7, 3] # NHWC
f_c = self.input_size[-1]
self.filter_size = [f_c, 6, 5, 5]
self.data_format = 'NHWC'
class TestConv2dTransposeAPI(unittest.TestCase): class TestConv2dTransposeAPI(unittest.TestCase):
def test_case1(self): def test_case1(self):
data1 = fluid.layers.data( data1 = fluid.layers.data(
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
from __future__ import print_function from __future__ import print_function
import unittest import unittest
from decorator_helper import prog_scope
import paddle.fluid as fluid import paddle.fluid as fluid
import numpy as np import numpy as np
import six import six
...@@ -23,7 +22,7 @@ import six ...@@ -23,7 +22,7 @@ import six
class TestMathOpPatchesVarBase(unittest.TestCase): class TestMathOpPatchesVarBase(unittest.TestCase):
def setUp(self): def setUp(self):
self.shape = [10, 10] self.shape = [10, 1024]
self.dtype = np.float32 self.dtype = np.float32
def test_add(self): def test_add(self):
...@@ -251,6 +250,29 @@ class TestMathOpPatchesVarBase(unittest.TestCase): ...@@ -251,6 +250,29 @@ class TestMathOpPatchesVarBase(unittest.TestCase):
rtol=1e-05, rtol=1e-05,
atol=0.0)) atol=0.0))
def test_add_different_dtype(self):
a_np = np.random.random(self.shape).astype(np.float32)
b_np = np.random.random(self.shape).astype(np.float16)
with fluid.dygraph.guard():
a = fluid.dygraph.to_variable(a_np)
b = fluid.dygraph.to_variable(b_np)
res = a + b
self.assertTrue(np.array_equal(res.numpy(), a_np + b_np))
def test_astype(self):
a_np = np.random.uniform(-1, 1, self.shape).astype(self.dtype)
with fluid.dygraph.guard():
a = fluid.dygraph.to_variable(a_np)
res1 = a.astype(np.float16)
res2 = a.astype('float16')
res3 = a.astype(fluid.core.VarDesc.VarType.FP16)
self.assertEqual(res1.dtype, res2.dtype)
self.assertEqual(res1.dtype, res3.dtype)
self.assertTrue(np.array_equal(res1.numpy(), res2.numpy()))
self.assertTrue(np.array_equal(res1.numpy(), res3.numpy()))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -80,5 +80,6 @@ NO_FP16_CHECK_GRAD_OP_LIST = [ ...@@ -80,5 +80,6 @@ NO_FP16_CHECK_GRAD_OP_LIST = [
'fused_elemwise_activation', \ 'fused_elemwise_activation', \
'pool2d', \ 'pool2d', \
'pool3d', \ 'pool3d', \
'softmax' 'softmax',\
'conv2d_transpose'
] ]
...@@ -28,7 +28,7 @@ class PRChecker(object): ...@@ -28,7 +28,7 @@ class PRChecker(object):
self.repo = None self.repo = None
def check(self): def check(self):
""" check pr """ """ check pr. """
filename = 'block.txt' filename = 'block.txt'
pr_id = os.getenv('GIT_PR_ID') pr_id = os.getenv('GIT_PR_ID')
if not pr_id: if not pr_id:
...@@ -44,7 +44,8 @@ class PRChecker(object): ...@@ -44,7 +44,8 @@ class PRChecker(object):
with open(filename) as f: with open(filename) as f:
for l in f: for l in f:
if l.rstrip('\r\n') == user: if l.rstrip('\r\n') == user:
print('{} has UT to be fixed, so CI failed.'.format(user)) print('{} has unit-test to be fixed, so CI failed.'.format(
user))
exit(1) exit(1)
exit(0) exit(0)
......
...@@ -19,6 +19,15 @@ ENV HOME /root ...@@ -19,6 +19,15 @@ ENV HOME /root
# Add bash enhancements # Add bash enhancements
COPY ./paddle/scripts/docker/root/ /root/ COPY ./paddle/scripts/docker/root/ /root/
ENV PATH=/usr/local/gcc-8.2/bin:$PATH
RUN rm -rf /temp_gcc82 && rm -rf /gcc-8.2.0.tar.xz && rm -rf /gcc-8.2.0
# Prepare packages for Python
RUN apt-get update && \
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
# gcc8.2 # gcc8.2
RUN wget -q https://paddle-docker-tar.bj.bcebos.com/home/users/tianshuo/bce-python-sdk-0.8.27/gcc-8.2.0.tar.xz && \ RUN wget -q https://paddle-docker-tar.bj.bcebos.com/home/users/tianshuo/bce-python-sdk-0.8.27/gcc-8.2.0.tar.xz && \
tar -xvf gcc-8.2.0.tar.xz && \ tar -xvf gcc-8.2.0.tar.xz && \
...@@ -33,23 +42,6 @@ RUN wget -q https://paddle-docker-tar.bj.bcebos.com/home/users/tianshuo/bce-pyth ...@@ -33,23 +42,6 @@ RUN wget -q https://paddle-docker-tar.bj.bcebos.com/home/users/tianshuo/bce-pyth
ENV PATH=/usr/local/gcc-8.2/bin:$PATH ENV PATH=/usr/local/gcc-8.2/bin:$PATH
RUN rm -rf /temp_gcc82 && rm -rf /gcc-8.2.0.tar.xz && rm -rf /gcc-8.2.0 RUN rm -rf /temp_gcc82 && rm -rf /gcc-8.2.0.tar.xz && rm -rf /gcc-8.2.0
# Prepare packages for Python
RUN apt-get update && \
apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
# Downgrade gcc&&g++
RUN apt-get update
WORKDIR /usr/bin
RUN apt install -y gcc-4.8 g++-4.8
RUN cp gcc gcc.bak
RUN cp g++ g++.bak
RUN rm gcc
RUN rm g++
RUN ln -s gcc-4.8 gcc
RUN ln -s g++-4.8 g++
# Install Python3.6 # Install Python3.6
RUN mkdir -p /root/python_build/ && wget -q https://www.sqlite.org/2018/sqlite-autoconf-3250300.tar.gz && \ RUN mkdir -p /root/python_build/ && wget -q https://www.sqlite.org/2018/sqlite-autoconf-3250300.tar.gz && \
tar -zxf sqlite-autoconf-3250300.tar.gz && cd sqlite-autoconf-3250300 && \ tar -zxf sqlite-autoconf-3250300.tar.gz && cd sqlite-autoconf-3250300 && \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册