Skip to content

Commit d03dbb9

Browse files
committed
remove AttrType
1 parent 05ad158 commit d03dbb9

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

paddle/fluid/operators/dropout_op.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class DropoutOp : public framework::OperatorWithKernel {
3535
}
3636
};
3737

38-
template <typename AttrType>
3938
class DropoutOpMaker : public framework::OpProtoAndCheckerMaker {
4039
public:
4140
DropoutOpMaker(OpProto* proto, OpAttrChecker* op_checker)
@@ -73,7 +72,6 @@ are set equal to their corresponding inputs.
7372
}
7473
};
7574

76-
template <typename AttrType>
7775
class DropoutOpGrad : public framework::OperatorWithKernel {
7876
public:
7977
using framework::OperatorWithKernel::OperatorWithKernel;
@@ -103,11 +101,10 @@ class DropoutOpGrad : public framework::OperatorWithKernel {
103101
} // namespace paddle
104102

105103
namespace ops = paddle::operators;
106-
REGISTER_OP(dropout, ops::DropoutOp, ops::DropoutOpMaker<float>, dropout_grad,
107-
ops::DropoutOpGrad<float>);
104+
REGISTER_OP(dropout, ops::DropoutOp, ops::DropoutOpMaker, dropout_grad,
105+
ops::DropoutOpGrad);
108106
REGISTER_OP_CPU_KERNEL(
109-
dropout,
110-
ops::CPUDropoutKernel<paddle::platform::CPUDeviceContext, float, float>);
107+
dropout, ops::CPUDropoutKernel<paddle::platform::CPUDeviceContext, float>);
111108
REGISTER_OP_CPU_KERNEL(
112109
dropout_grad,
113110
ops::DropoutGradKernel<paddle::platform::CPUDeviceContext, float>);

paddle/fluid/operators/dropout_op.cu

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ limitations under the License. */
2323
namespace paddle {
2424
namespace operators {
2525

26-
template <typename T, typename AttrType>
26+
template <typename T>
2727
__global__ void RandomGenerator(const size_t n, const int seed,
28-
const AttrType dropout_prob, const T* src,
28+
const float dropout_prob, const T* src,
2929
T* mask_data, T* dst) {
3030
thrust::minstd_rand rng;
3131
rng.seed(seed);
32-
thrust::uniform_real_distribution<AttrType> dist(0, 1);
32+
thrust::uniform_real_distribution<float> dist(0, 1);
3333

3434
int idx = blockDim.x * blockIdx.x + threadIdx.x;
3535
for (; idx < n; idx += blockDim.x * gridDim.x) {
@@ -45,14 +45,14 @@ __global__ void RandomGenerator(const size_t n, const int seed,
4545
// It seems that Eigen::Tensor::setRandom in GPU will SEGFAULT.
4646
// Use std::random and thrust::random(thrust is a std library in CUDA) to
4747
// implement uniform random.
48-
template <typename Place, typename T, typename AttrType>
48+
template <typename Place, typename T>
4949
class GPUDropoutKernel : public framework::OpKernel<T> {
5050
public:
5151
void Compute(const framework::ExecutionContext& context) const override {
5252
auto* x = context.Input<Tensor>("X");
5353
auto* y = context.Output<Tensor>("Out");
5454
y->mutable_data<T>(context.GetPlace());
55-
AttrType dropout_prob = context.Attr<AttrType>("dropout_prob"));
55+
float dropout_prob = context.Attr<float>("dropout_prob");
5656

5757
auto X = EigenMatrix<T>::Reshape(*x, 1);
5858
auto Y = EigenMatrix<T>::Reshape(*y, 1);
@@ -71,8 +71,8 @@ class GPUDropoutKernel : public framework::OpKernel<T> {
7171

7272
int threads = 512;
7373
int grid = (x->numel() + threads - 1) / threads;
74-
RandomGenerator<T, AttrType><<<grid, threads, 0,
75-
context.cuda_device_context().stream()>>>(
74+
RandomGenerator<
75+
T><<<grid, threads, 0, context.cuda_device_context().stream()>>>(
7676
size, seed, dropout_prob, x_data, mask_data, y_data);
7777
} else {
7878
Y.device(place) = X * static_cast<T>(1.0f - dropout_prob);
@@ -86,7 +86,7 @@ class GPUDropoutKernel : public framework::OpKernel<T> {
8686
namespace ops = paddle::operators;
8787
namespace plat = paddle::platform;
8888
REGISTER_OP_CUDA_KERNEL(
89-
dropout, ops::GPUDropoutKernel<plat::CUDADeviceContext, float, float>,
90-
ops::GPUDropoutKernel<plat::CUDADeviceContext, plat::float16, float>);
89+
dropout, ops::GPUDropoutKernel<plat::CUDADeviceContext, float>,
90+
ops::GPUDropoutKernel<plat::CUDADeviceContext, plat::float16>);
9191
REGISTER_OP_CUDA_KERNEL(dropout_grad,
9292
ops::DropoutGradKernel<plat::CUDADeviceContext, float>);

paddle/fluid/operators/dropout_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ template <typename T, int MajorType = Eigen::RowMajor,
2525
typename IndexType = Eigen::DenseIndex>
2626
using EigenMatrix = framework::EigenMatrix<T, MajorType, IndexType>;
2727

28-
template <typename DeviceContext, typename T, typename AttrType>
28+
template <typename DeviceContext, typename T>
2929
class CPUDropoutKernel : public framework::OpKernel<T> {
3030
public:
3131
void Compute(const framework::ExecutionContext& context) const override {

python/paddle/fluid/tests/unittests/test_dropout_op.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import unittest
1616
import numpy as np
17+
import paddle.fluid.core as core
1718
from op_test import OpTest
1819

1920

0 commit comments

Comments
 (0)