From f9e9309162d6c3531074fb5b26b8b45197153570 Mon Sep 17 00:00:00 2001 From: qijun Date: Thu, 8 Mar 2018 10:13:21 +0800 Subject: [PATCH 1/4] fix mac build error --- paddle/fluid/inference/tests/test_helper.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/paddle/fluid/inference/tests/test_helper.h b/paddle/fluid/inference/tests/test_helper.h index d0688445fe642..0f5fe6d0aa9a5 100644 --- a/paddle/fluid/inference/tests/test_helper.h +++ b/paddle/fluid/inference/tests/test_helper.h @@ -110,6 +110,8 @@ void TestInference(const std::string& dirname, // Users can get the device_id using: // int device_id = place.GetDeviceId(); paddle::platform::SetDeviceId(0); +#else + PADDLE_THROW("'CUDAPlace' is not supported in CPU only device."); #endif } From 15448c3a92e285a11323aad3826014766dc25490 Mon Sep 17 00:00:00 2001 From: qijun Date: Fri, 9 Mar 2018 15:36:45 +0800 Subject: [PATCH 2/4] override GetExpectedKernelType for cast op --- paddle/fluid/operators/cast_op.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/cast_op.cc b/paddle/fluid/operators/cast_op.cc index a5ec47d84fe42..2fadf329f43e1 100644 --- a/paddle/fluid/operators/cast_op.cc +++ b/paddle/fluid/operators/cast_op.cc @@ -63,13 +63,27 @@ class CastOpGradMaker : public framework::SingleGradOpDescMaker { } }; +class CastOp : public framework::OperatorWithKernel { + public: + using framework::OperatorWithKernel::OperatorWithKernel; + + protected: + framework::OpKernelType GetExpectedKernelType( + const framework::ExecutionContext &ctx) const override { + framework::OpKernelType kt = OperatorWithKernel::GetExpectedKernelType(ctx); + // LogicalOp kernel's device type is decided by input tensor place + kt.place_ = ctx.Input("X")->place(); + return kt; + } +}; + } // namespace operators } // namespace paddle namespace ops = paddle::operators; using CPU = paddle::platform::CPUDeviceContext; -REGISTER_OP_WITH_KERNEL(cast, ops::CastOpGradMaker, ops::CastOpInferShape, - ops::CastOpProtoMaker); +REGISTER_OPERATOR(cast, ops::CastOp, ops::CastOpGradMaker, + ops::CastOpInferShape, ops::CastOpProtoMaker); REGISTER_OP_CPU_KERNEL(cast, ops::CastOpKernel, ops::CastOpKernel, ops::CastOpKernel, From d697ca478d6dc0a506210a79d9707dbe5264351d Mon Sep 17 00:00:00 2001 From: qijun Date: Fri, 9 Mar 2018 15:56:41 +0800 Subject: [PATCH 3/4] fix typo --- paddle/fluid/operators/cast_op.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/fluid/operators/cast_op.cc b/paddle/fluid/operators/cast_op.cc index 2fadf329f43e1..72f8cb04f2de3 100644 --- a/paddle/fluid/operators/cast_op.cc +++ b/paddle/fluid/operators/cast_op.cc @@ -71,7 +71,7 @@ class CastOp : public framework::OperatorWithKernel { framework::OpKernelType GetExpectedKernelType( const framework::ExecutionContext &ctx) const override { framework::OpKernelType kt = OperatorWithKernel::GetExpectedKernelType(ctx); - // LogicalOp kernel's device type is decided by input tensor place + // CastOp kernel's device type is decided by input tensor place kt.place_ = ctx.Input("X")->place(); return kt; } From 5d20d3ba6f21e2ead0d0854f6791589731b75463 Mon Sep 17 00:00:00 2001 From: qijun Date: Fri, 9 Mar 2018 16:35:55 +0800 Subject: [PATCH 4/4] add cuda unittest --- .../tests/unittests/test_learning_rate_scheduler.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_learning_rate_scheduler.py b/python/paddle/fluid/tests/unittests/test_learning_rate_scheduler.py index e75a6529e9fa2..00a6f7c237d58 100644 --- a/python/paddle/fluid/tests/unittests/test_learning_rate_scheduler.py +++ b/python/paddle/fluid/tests/unittests/test_learning_rate_scheduler.py @@ -19,6 +19,7 @@ import paddle.fluid as fluid import paddle.fluid.layers as layers import paddle.fluid.framework as framework +import paddle.fluid.core as core def exponential_decay(learning_rate, @@ -81,6 +82,16 @@ def piecewise_decay(global_step, boundaries, values): class TestLearningRateDecay(unittest.TestCase): def check_decay(self, python_decay_fn, fluid_decay_fn, kwargs): + places = [fluid.CPUPlace()] + if core.is_compiled_with_cuda(): + places.append(fluid.CUDAPlace(0)) + for place in places: + self.check_decay_with_place(place, python_decay_fn, fluid_decay_fn, + kwargs) + + def check_decay_with_place(self, place, python_decay_fn, fluid_decay_fn, + kwargs): + decayed_lr = fluid_decay_fn(**kwargs) place = fluid.CPUPlace()