Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreasonable output of dropout_op with GPU kernel #8654

Closed
guoshengCS opened this issue Feb 28, 2018 · 1 comment
Closed

Unreasonable output of dropout_op with GPU kernel #8654

guoshengCS opened this issue Feb 28, 2018 · 1 comment
Assignees

Comments

@guoshengCS
Copy link
Contributor

guoshengCS commented Feb 28, 2018

Bugs may exist in the GPU kernel of dropout_op.

I just found that dropout_op often outputs tensor with all 0s even with a big size. I test the dropout_op with GPU by simple codes (the dropout_prob is 0.1 and the input data is 1s with shape [64, 32, 512]), and print the max and min of the output tensor 10 times as following:

1.0 1.0
0.0 0.0
1.0 1.0
1.0 1.0
1.0 1.0
1.0 1.0
1.0 1.0
0.0 0.0
0.0 0.0
1.0 1.0

The test codes are as following:

import numpy as np

import paddle.v2 as paddle
import paddle.fluid as fluid


def program():
    x = fluid.layers.data(name='x', shape=[64, 32, 512], dtype='float32', append_batch_size=False)
    out = fluid.layers.dropout(x, dropout_prob=0.1, is_test=False)
    return out


def main():
    #place = fluid.CPUPlace()
    place = fluid.CUDAPlace(0)
    exe = fluid.Executor(place)
    out = program()
    data_input = {}
    in_tensor = fluid.LoDTensor()
    in_tensor.set(np.ones([64, 32, 512], dtype="float32"), place)
    data_input['x'] = in_tensor
    for i in range(10):
       out_ = exe.run(fluid.framework.default_main_program(), feed=data_input, fetch_list=[out])[0]
       print np.max(out_), np.min(out_)


if __name__ == "__main__":
    main()

Running the code with CPU gets the proper outputs.

1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
1.0 0.0
@guoshengCS
Copy link
Contributor Author

guoshengCS commented Mar 1, 2018

It seems that the GPU kernel uses the fixed seed for all threads. https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/operators/dropout_op.cu#L30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants