Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Large Tensor] Add support to Random Sample & Pdf ops #17445

Merged
merged 5 commits into from
Jan 30, 2020

Conversation

ChaiBapchya
Copy link
Contributor

@ChaiBapchya ChaiBapchya commented Jan 27, 2020

Description

Extend LT support to all the random family operators

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Code is well-documented:
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • modified: src/operator/random/multisample_op.h
  • modified: src/operator/random/pdf_op.h

Tests

PDF Ops

>>> mx.nd.random_pdf_negative_binomial(sample=mx.nd.random_normal(shape=(1, 2**32 + 1)), k=mx.nd.random_normal(shape=(1)), p=mx.nd.random_normal(shape=(1)))
[[ 3.6517045   0.08385151  0.33836576 ...  1.2580111   1.200235232.96391   ]]
<NDArray 1x4294967297 @cpu(0)>
>>> mx.nd.random_pdf_dirichlet(sample=mx.nd.random_uniform(shape=(2**32 + 1,5),low=0, high=1), alpha=mx.nd.random_uniform(shape=(5), low=0, high=1))
[0.02400445 0.09834412 0.00485084 ... 0.00059637 0.00062773 0.00020362]
<NDArray 4294967297 @cpu(0)>
>>> mx.nd.random_pdf_exponential(sample=mx.nd.random_normal(shape=(1,2**32 + 1)), lam=mx.nd.random_normal(shape=(1)))
[[0.7160165 0.8786655  1.8491699  ... 0.590301   0.19441505 0.99005574]]
<NDArray 1x4294967297 @cpu(0)>
>>> mx.nd.random_pdf_normal(sample=mx.nd.random_normal(shape=(1,2**32)), mu=mx.nd.random_normal(shape=(1)), sigma=mx.nd.random_normal(shape=(1)))
[[-0.08357255 -0.7204103  -0.52567625 ... -0.03446919 -0.02720401-0.27186853]]
<NDArray 1x4294967296 @cpu(0)>
>>> mx.nd.random_pdf_poisson(sample=mx.nd.random_normal(shape=(1, 2**32 + 1)), lam=mx.nd.random_normal(shape=(1)))
[[0.39283866 0.3568688  0.46852896 ... 0.1435355  0.19014826 0.1828634 ]]
<NDArray 1x4294967297 @cpu(0)>
>>> mx.nd.random_pdf_uniform(sample=mx.nd.random_normal(shape=(1,2**32 + 1)), low=mx.nd.random_normal(shape=(1)), high=mx.nd.random_normal(shape=(1)))
[[-0.53082603 -0.53082603 -0.53082603 ... -0.53082603 -0.53082603-0.53082603]]
<NDArray 1x4294967297 @cpu(0)>

Sample Ops

>>> mx.nd.sample_uniform(shape=(2**32), low=mx.nd.random_normal(shape=(1,)), high=mx.nd.random_normal(shape=(1,)))

[[1.3453104  0.9783068  1.4285539  ... 2.1584532  0.990888   0.97627187]]
<NDArray 1x4294967296 @cpu(0)>
>>> mx.nd.sample_poisson(shape=(2**32 + 1), lam=mx.nd.random_normal(shape=(1)))

[[0. 0. 0. ... 0. 0. 0.]]
<NDArray 1x4294967297 @cpu(0)>
>>> mx.nd.sample_normal(mu=mx.nd.random_normal(shape=(2**32 + 1)), sigma=mx.nd.random_normal(shape=(2**32 + 1)))

[ 0.7192631   1.8029252  -3.1244457  ...  1.3172784  -0.44950533
  0.5782782 ]
<NDArray 4294967297 @cpu(0)>
>>> mx.nd.sample_exponential(shape=(1), lam=mx.nd.random_normal(shape=(2**32 + 1)))

[[-2.564538 ]
 [ 1.3046274]
 [ 3.4207358]
 ...
 [ 5.2444887]
 [ 1.7304702]
 [ 1.6264884]]
<NDArray 4294967297x1 @cpu(0)>
>>> mx.nd.sample_negative_binomial(k=mx.nd.random_uniform(shape=(2**32), low=0, high=1), p=mx.nd.random_uniform(shape=(2**32), low=0, high=1))

[ 0.  0.  0. ... 19.  1.  0.]
<NDArray 4294967296 @cpu(0)>
>>> mx.nd.sample_generalized_negative_binomial(alpha=mx.nd.random_uniform(shape=(2**32), low=0, high=1), mu=mx.nd.random_uniform(shape=(2**32), low=0, high=1))

[0. 0. 0. ... 2. 1. 0.]
<NDArray 4294967296 @cpu(0)>
>>> mx.nd.sample_gamma(alpha=mx.nd.random_uniform(shape=(2**32), low=0, high=1), beta=mx.nd.random_uniform(shape=(2**32), low=0, high=1))

[3.9847539e-05 9.7578183e-02 3.0167744e-04 ... 2.7813488e-03 5.8879163e-03
 3.3052340e-01]
<NDArray 4294967296 @cpu(0)>

Copy link
Contributor

@access2rohit access2rohit left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Contributor

@apeforest apeforest left a comment

Choose a reason for hiding this comment

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

LGTM. These ops are already covered by the opperf tests, right?

@apeforest apeforest merged commit b7d81b7 into apache:master Jan 30, 2020
@ChaiBapchya
Copy link
Contributor Author

Yes, already covered.

@ChaiBapchya ChaiBapchya deleted the random_sample_pdf_ops_lts branch January 30, 2020 22:07
zheyuye pushed a commit to zheyuye/incubator-mxnet that referenced this pull request Feb 19, 2020
* fix random pdf normal

* fix remaining pdf ops

* add LT support to sample_* ops

* fix spelling mistake

* fix lint
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants