-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
add bernoulli op #26511
Conversation
Thanks for your contribution! |
There was a problem hiding this 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_); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
python/paddle/tensor/random.py
Outdated
@@ -37,6 +38,51 @@ | |||
] | |||
|
|||
|
|||
def bernoulli(x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个API是否需要name参数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/paddle/tensor/random.py
Outdated
out_i ~ Bernoulli (x_i) | ||
|
||
Args: | ||
x(int): A tensor with probabilities for generating the random binary number. The data type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x(int) ?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
给一下输出结果
There was a problem hiding this comment.
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 ? |
There was a problem hiding this comment.
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 ?
是否需要有结论?
Thanks, @lanxianghit I will refine the doc in next PR. |
7ace797
to
d8f950a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
PR types
New features
PR changes
APIs
Describe
bernoulli
op (c++ OP)paddle.bernoulli(x)
(python API)