pytorch
35beff0b - RNG infrastructure improvements (#37984)

Commit
4 years ago
RNG infrastructure improvements (#37984) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/37984 - `NumericUtils.h` CUDA distribution kernels had two variants of transformation labdas(`uniform`/`normal` -> `lognormal`/`exponential`/`cauchy`/`geometric`...): for double-precision and optimized for CUDA single precision. It was done by using `::log`/`__logf`, `::exp`/`__expf` and `::tan/__tanf`. I moved them to `NumericUtils.h` and called them `at::exp`, `at::log` and `at::tan`. It allowed to unify CPU/CUDA transformation templates in `TransformationHelper.h`. - `DistributionsHelper.h` Made `normal_distribution`, `geometric_distribution`, `exponential_distribution`, `cauchy_distribution`, `lognormal_distribution` C10_HOST_DEVICE compatible to reuse them in CPU/CUDA distribution kernels. Replaced explicit math with transformations from `TransformationHelper.h` - `TransformationHelper.h` Renamed `*_transformation` to `transformation::*` Added clear unified host/device transformations templates `normal`, `cauchy`, `exponential`, `geometric`, `log_normal` which are used by both CPU and CUDA distribution kernels and custom PRNG distribution kernels. - `cpu/DistributionTemplates.h` Unified `normal_kernel`, `cauchy_kernel`, `log_normal_kernel`, `geometric_kernel`, `exponential_kernel`. - `cuda/DistributionTemplates.h` Extracted `UNIFORM_AND_TRANSFORM` and `NORMAL_AND_TRANSFORM` macros to reuse code between distribution kernel templates. Unified transformation labdas(`uniform`/`normal` -> `lognormal`/`exponential`/`cauchy`/`geometric`...) - `test_torch.py` Added `scipy.stats.kstest` [Kolmogorov–Smirnov](https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test) tests for `uniform`/`normal`/`lognormal`/`exponential`/`cauchy` distributions and [Chi-squared](https://en.wikipedia.org/wiki/Chi-squared_test) test for `geometric` one. To make sure that our distributions are correct. - `cpu_rng_test.cpp`, `rng_test.h` Fixed random_()'s from and to bounds issue for floating-point types, fixed cast/overflow warnings - `THTensorRandom.h`, `THVector.h` Moved unnecessary includes to `THTensorRandom.cpp` Test Plan: Imported from OSS Differential Revision: D21477955 Pulled By: pbelevich fbshipit-source-id: 7b793d1761a7a921c4b4a4a7d21d5d6c48f03e72
Author
Parents
Loading