Skip to content

add bernoulli op #26511

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

Merged
merged 4 commits into from
Aug 21, 2020
Merged

add bernoulli op #26511

merged 4 commits into from
Aug 21, 2020

Conversation

zhiqiu
Copy link
Contributor

@zhiqiu zhiqiu commented Aug 20, 2020

PR types

New features

PR changes

APIs

Describe

  • add bernoulli op (c++ OP)
  • add paddle.bernoulli(x) (python API)

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

jzhang533
jzhang533 previously approved these changes Aug 21, 2020
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


__host__ __device__ T operator()(const unsigned int n, const T p) const {
thrust::minstd_rand rng;
rng.seed(seed_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change to use global generator later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be refined after GPUGenerator is provided.

@zhiqiu zhiqiu requested a review from lanxianghit August 21, 2020 03:04
@@ -37,6 +38,51 @@
]


def bernoulli(x):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个API是否需要name参数

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

out_i ~ Bernoulli (x_i)

Args:
x(int): A tensor with probabilities for generating the random binary number. The data type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x(int) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed to x(Tensor).

x = paddle.rand([2, 3])
print(x.numpy())
out = paddle.bernoulli(x)
print(out.numpy())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

给一下输出结果

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


helper = LayerHelper("randint", **locals())
out = helper.create_variable_for_type_inference(
dtype=x.dtype) # maybe set out to int32 ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe set out to int32 ?

是否需要有结论?

@zhiqiu
Copy link
Contributor Author

zhiqiu commented Aug 21, 2020

Thanks, @lanxianghit I will refine the doc in next PR.

lanxianghit
lanxianghit previously approved these changes Aug 21, 2020
@zhiqiu zhiqiu dismissed stale reviews from lanxianghit and jzhang533 via d8f950a August 21, 2020 05:35
@zhiqiu zhiqiu force-pushed the dev/add_bernoulli branch from 7ace797 to d8f950a Compare August 21, 2020 05:35
Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zhiqiu zhiqiu merged commit aa2a9b5 into PaddlePaddle:develop Aug 21, 2020
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

Successfully merging this pull request may close these issues.

3 participants