Commit Graph

60 Commits

Author SHA1 Message Date
Srinivas Vasudevan
455750f362 Add StatelessParameterizedTruncatedNormal sampler.
This sampler supports broadcasting of its input parameters as well as puts the # samples at the left of the output shape, rather than the right.

PiperOrigin-RevId: 317129622
Change-Id: I4b62ad2e89a9637ae8b30b73af4b662ad0caa943
2020-06-18 10:28:38 -07:00
A. Unique TensorFlower
8b1f77197a Internal change
PiperOrigin-RevId: 313473478
Change-Id: I53882ee616693d8f3006870786c153e470b4b939
2020-05-27 15:22:27 -07:00
A. Unique TensorFlower
426869b50f patch cl/312773551
PR : Fix invalid shape issue in random.uniform

Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/38585

Note: This PR is a resubmission from 

This PR tries to address the issue raised in  where
invalid shape passed to minval/maxval (expected to be 0-D)
does not raise an error.

The issue was that in most of the scenarios the shape was
checked inside the C++ kernel ops.

However, in one condition math_ops.add was used which will
implicitly do broadcast when necessarily.
This results in maxval/minval's shape getting carried.

This PR adds the shape check before math_ops.add, to make
sure the shape is guaranteed.

This PR fixes .

Signed-off-by: Yong Tang yong.tang.github@outlook.com
Copybara import of the project:

--
1c480a2175ed7d8a86210882bfbb0ed45f0730d6 by Yong Tang <yong.tang.github@outlook.com>:

Fix invalid shape issue in random.uniform

This PR tries to address the issue raised in 34363 where
invalid shape passed to minval/maxval (expected to be 0-D)
does not raise an error.

The issue was that in most of the scenarios the shape was
checked inside the C++ kernel ops.

However, in one condition math_ops.add was used which will
implicitly do broadcast when necessarily.
This results in maxval/minval's shape getting carried.

This PR adds the shape check before math_ops.add, to make
sure the shape is guaranteed.

This PR fixes 34363.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

--
81dca0016c1efbfc99d7f22e2ac6d26e0c5099b5 by Yong Tang <yong.tang.github@outlook.com>:

Add test case for invalid shape issue in random.uniform

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

--
be3dee4337f45883326536bc2fad7539cd1a2244 by Yong Tang <yong.tang.github@outlook.com>:

Use explicit broadcast_to to prevent shape overflow

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
RELNOTES=n/a
PiperOrigin-RevId: 313446121
Change-Id: I34b076d79c13a7db040bf46aa5b2f2b43075c55f
2020-05-27 12:59:12 -07:00
Kibeom Kim
f7d038cc3b Enable more TFRT tests.
PiperOrigin-RevId: 312230367
Change-Id: Icc82c7ce424a1db2ca3cf2eabc1e5932fec7b6a7
2020-05-19 00:24:26 -07:00
Peng Wang
aba2ca4603 Adds tf.random.experimental.stateless_split and tf.random.experimental.stateless_fold_in to manage seeds for stateless RNGs.
PiperOrigin-RevId: 302520177
Change-Id: I43c3d2e2aa5dd26a64e978027df0ecb1f6095140
2020-03-23 14:42:43 -07:00
Peng Wang
07eff99852 Fixes doc and error messages about non-scalar minval/maxval in integer uniform RNGs.
PiperOrigin-RevId: 299235545
Change-Id: If70d2abbb777f8add2e459fa5cb1ddc9008a6238
2020-03-05 17:28:06 -08:00
Brian Patton
d8dc9415b0 Adds a tf.random.stateless_poisson sampler for CPU.
PiperOrigin-RevId: 293834809
Change-Id: I719e218b43f8aecbd74d1472f1291748a61979b8
2020-02-07 10:05:56 -08:00
Brian Patton
31c94250fc Adds a tf.random.stateless_gamma sampler for CPU. (Stateless analogue to tf.random.gamma.)
PiperOrigin-RevId: 293454705
Change-Id: I103900822dac37989246eaf7b410157e5563b78b
2020-02-05 14:45:26 -08:00
Brian Patton
1dc9305329 Adds a tf.random.stateless_binomial (stateless analogue to tf.random.Generator.binomial).
PiperOrigin-RevId: 293446442
Change-Id: I1fc995304adbf82a5f43fddd27d015b6133b5a31
2020-02-05 14:07:38 -08:00
Brian Atkinson
4ca6bb5c34 Move additional_deps to deps for tf_py_test.
PiperOrigin-RevId: 285307780
Change-Id: Id556a146ba01afa1138454153ae6568e073ace41
2019-12-12 17:38:47 -08:00
Brian Atkinson
2fcfa6085b Move additional_deps to deps for cuda_py_test.
PiperOrigin-RevId: 285283853
Change-Id: I2534d9fb51955cc9a86d1900ec60fc265f451ddc
2019-12-12 15:28:04 -08:00
Srinivas Vasudevan
5396e7a3cd Allow RandomBinomial op to broadcast parameters.
- Add multiple parameter broadcasting support for BCast. This will allow it to be used in multiparameter broadcasting contexts. This is specifically for ternary ops, but will be used to make other samplers like ParameterizedTruncatedNormal broadcast.

- Add batch index methods for generating a list of batch indices when the input vectors are flattened. This is used to get broadcasting on flattened inputs (which is used in the RandomBinomial sampler).

- Shard on the number of outputs. This allows us to scale better to Tensor inputs.

PiperOrigin-RevId: 281202841
Change-Id: I0b276e983bf31056677a67b4d5ce8ebc98d77930
2019-11-18 20:18:33 -08:00
Tres Popp
e01699ccbd [TF:XLA] Cleanup cuda_py_test calls with xla_enable_strict_auto_jit = True.
PiperOrigin-RevId: 270858131
2019-09-24 02:07:26 -07:00
Brian Patton
c0219bdebd Allow np dtypes as args to random_gamma. Previously, failed with AttributeError: type object 'numpy.float32' has no attribute 'as_numpy_dtype'
PiperOrigin-RevId: 263783739
2019-08-16 09:30:44 -07:00
Peng Wang
096f7e3906 Fixed compiler/tests:stateful_random_ops_test for f64, made the test more parallel and faster, and removed @run_v2_only so the test can be picked up by TAP.
PiperOrigin-RevId: 256223403
2019-07-02 14:55:28 -07:00
Alexey Radul
84a3afbb02 Fix some corner cases in the binomial sampler, and spell out some details in its docstring.
PiperOrigin-RevId: 255658335
2019-06-28 15:20:18 -07:00
A. Unique TensorFlower
a0e2b971b0 Adjust structure of all BUILD files to recommended style (https://docs.bazel.build/versions/master/skylark/build-style.html#file-structure), moving loads to top.
PiperOrigin-RevId: 252864967
2019-06-12 12:28:54 -07:00
A. Unique TensorFlower
4469ed4ed8 Apply 'buildozer fix moveLicensesAndDistribs movePackageToTop' to all BUILD files.
PiperOrigin-RevId: 249807024
2019-05-24 03:53:05 -07:00
A. Unique TensorFlower
ba19774664 [TF:XLA] Enable more TF python tests for XLA:GPU
Additionally increase tolerances in the flaky multi_worker_callback_test.py assertions.
Fix typo in matmul assertions.

PiperOrigin-RevId: 249787704
2019-05-24 00:40:13 -07:00
Peng Wang
8ebb2d418c Added alternative ways to initialize and reset a generator other than seed.
PiperOrigin-RevId: 248040749
2019-05-13 18:06:33 -07:00
A. Unique TensorFlower
795f0849f5 Add test_util.no_xla_auto_jit decorator to more tests.
Also add the decorator to tensorflow/python:layout_optimizer_test_gpu. For convenience, add a for_all_test_methods decorator, which applies a given decorator to all test methods of a class.

PiperOrigin-RevId: 245904023
2019-04-30 01:37:54 -07:00
Haoyu Zhang
0116278312 Disable "random_binomial_test" in OSS due to flakiness.
PiperOrigin-RevId: 244445932
2019-04-19 17:08:48 -07:00
A. Unique TensorFlower
c80ba8dba5 Temporarily set random_binomial_test to be tf_py_test (disable GPU tests).
PiperOrigin-RevId: 243143398
2019-04-11 15:16:35 -07:00
A. Unique TensorFlower
55d0efee68 Add random binomial sampling op.
PiperOrigin-RevId: 242723492
2019-04-09 13:20:18 -07:00
Bixia Zheng
4b50df1569 [XLA] Miscellaneous code clean up to prepare for adding a Philox random bit
generator.

Modify prng.h to export the ThreeFry random bit generators. Add three functions
to support both stateful and stateless random number generation. These
functions take a random bit generator to generate random bits, convert the
random bits to values in uniform or normal distributions, and return the random
numbers as well as the updated state of the random bit generator. This allows
tensorflow to use the same XLA client APIs to implement stateful random ops and
stateless random ops.

There was a subtle difference between the old stateless and stateful random
number generations. After we merge the two implementations into one, we need to
slightly increase the relative error tolerance for a test.

Move StatelessRngUniform from prng.h to random_ops_util.h in the tf2xla bridge.

PiperOrigin-RevId: 242557394
2019-04-08 16:10:05 -07:00
Peng Wang
99c4d2ae1a A continuing partial implementation of RFC "Random numbers in TensorFlow 2.0" (https://github.com/tensorflow/community/blob/master/rfcs/20181217-tf2-random-numbers.md):
In this change:
- XLA kernels for op 'StatefulUniform' and 'StatefulTruncatedNormal'.

To be done:
- ops for other distributions;
- other RNG algorithms;
- batch seeds;
- initializers ('RandomUniform', etc.);

PiperOrigin-RevId: 240658747
2019-03-27 15:56:29 -07:00
TensorFlower Gardener
9e4fc7fdae Merge pull request from lgeiger:literals
PiperOrigin-RevId: 239507826
2019-03-20 17:29:57 -07:00
Brian Patton
a24cfc8d09 RandomGamma should return an empty Tensor for empty alpha.
Before this change, it returns an error "Input alpha should have non-zero element count" if empty `alpha` is presented with non-empty `shape`.

PiperOrigin-RevId: 239255074
2019-03-19 13:25:58 -07:00
A. Unique TensorFlower
6bdbc4689e Raise an error if several scopes are not properly nested, e.g. due to
using __enter__ and __exit__ on the context manager directly instead
of using "with" blocks.  In preparation for creating a
tf.distribute.set_strategy() API which will manually call
strategy.scope().__enter__ and .__exit__.

PiperOrigin-RevId: 239124241
2019-03-18 21:54:47 -07:00
Peng Wang
949474a448 A continuing partial implementation of RFC "Random numbers in TensorFlow 2.0" (https://github.com/tensorflow/community/blob/master/rfcs/20181217-tf2-random-numbers.md):
In this change:
- CPU and GPU kernels for op 'StatefulRandomInt' and 'StatefulRandomFullInt'.

To be done:
- ops for other distributions;
- other RNG algorithms;
- batch seeds;
- initializers ('RandomUniform', etc.);

PiperOrigin-RevId: 239104292
2019-03-18 18:37:14 -07:00
Lukas Geiger
d3c1e397f6 var = list() --> var = [] 2019-03-11 11:58:26 +00:00
A. Unique TensorFlower
ee46b37963 Fix flakiness in random_gamma_test.
Set random seeds and increase the number of random samples.

PiperOrigin-RevId: 234553193
2019-02-19 00:31:31 -08:00
A. Unique TensorFlower
142bd9fc37 Disable flaky test.
PiperOrigin-RevId: 233806315
2019-02-13 13:00:57 -08:00
A. Unique TensorFlower
7c929bf6ef Refactor out moment-testing and make more numpy friendly.
PiperOrigin-RevId: 230804842
2019-01-24 15:53:40 -08:00
A. Unique TensorFlower
4ac9bda9d0 [TF:XLA] Enable XLA through autojit for all tensorflow/python/kernel_test/ tests.
Some test methods are disabled, but all tests now have a new "_xla" version of the test for XLA:GPU testing. This will run 2 different tests. One with XLA and one without.

PiperOrigin-RevId: 229149574
2019-01-14 02:42:27 -08:00
Gaurav Jain
d26205bd53 Update @run_v1_only annotation for symbols removed from v2
PiperOrigin-RevId: 225855005
2018-12-17 11:09:45 -08:00
Gaurav Jain
4890b781b6 Annotate tests as @run_v1_only
Skip individual test cases or entire suites that are not
running in v1. Also replace some @run_deprecated_v1
annotations since simply running the test in graph mode
was not enough.

PiperOrigin-RevId: 224604547
2018-12-07 17:41:47 -08:00
Gaurav Jain
24f578cd66 Add @run_deprecated_v1 annotation to tests failing in v2
PiperOrigin-RevId: 223422907
2018-11-29 15:43:25 -08:00
Gaurav Jain
5f111d5a6c Remove calls to test_session() or use test_util helpers
PiperOrigin-RevId: 223105516
2018-11-27 20:58:32 -08:00
Gaurav Jain
b17d53c0cd Replace a few calls of Session run with evaluate
In order to support tests running in eager mode we need to avoid
unnecessary use of Sessions in tests. This moves to remove some
of the uses of the `run` function in favor of `evaluate`.

PiperOrigin-RevId: 223009795
2018-11-27 10:09:00 -08:00
Alexandre Passos
f6ce9fd485 Automated rollback of commit 1fdd7c7408
PiperOrigin-RevId: 222434204
2018-11-21 11:14:22 -08:00
Gaurav Jain
1fdd7c7408 Replace a few calls of Session run with evaluate
In order to support tests running in eager mode we need to avoid
unnecessary use of Sessions in tests. This moves to remove some
of the uses of the `run` function in favor of `evaluate`.

PiperOrigin-RevId: 222013881
2018-11-18 20:05:24 -08:00
Gaurav Jain
4fe22bc9da Replace many calls to eval() with self.evaluate()
In order to get tests running in eager mode we need to remove invalid
functions calls such as eval(). This change is simply a search and
replace for tests where this was safe. As a result, a few more tests now
work in eager mode.

PiperOrigin-RevId: 221836866
2018-11-16 13:10:31 -08:00
Geoffrey Irving
a13c744ca6 Move stateless ops out of contrib 2018-10-15 13:36:08 -07:00
A. Unique TensorFlower
b94f5bb165 Move from deprecated self.test_session() to self.session() or self.cached_session().
Move to cached_session() if the session is create more than once per test. Move to session() otherwise.

self.test_session() has been deprecated in 9962eb5e84 as its name confuses readers of the test. Moving to session() instead which slightly changes the semantic of the function:
* the session is not cached anymore (a new session is created).
* the session is closed when exiting the "with" scope.

PiperOrigin-RevId: 216868101
2018-10-12 08:48:31 -07:00
Geoffrey Irving
97011c17de Make tf.random_uniform([0], maxval=0, dtype=tf.int32) not crash
For integers, tf.random_uniform enforces a nonempty range with minval < maxval.
However, an empty range is fine if we're producing no output values, and
this degenerate case occurs naturally for some code patterns.

Thus, tf.random_uniform now allows empty ranges for integer random
numbers if the output shape is empty.
2018-09-18 07:53:44 -07:00
A. Unique TensorFlower
754fffb399 Move from deprecated self.test_session() to self.cached_session().
self.test_session() has been deprecated in 9962eb5e84 as its name confuses readers of the test. Moving to cached_session() instead which is more explicit about:
* the fact that the session may be reused.
* the session is not closed even when doing a "with self.test_session()" statement.

PiperOrigin-RevId: 209700634
2018-08-21 19:13:28 -07:00
Bixia Zheng
217dd20c5e [TF] Add test cases to check that random ops are stateful.
Check that running the same random op multiple times in the same session rarely
produces the same result.

PiperOrigin-RevId: 206764062
2018-07-31 08:23:15 -07:00
Tom Hennigan
945d1a77ae Replace unnecessary () in run_in_graph_and_eager_modes().
PiperOrigin-RevId: 201652888
2018-06-22 01:49:29 -07:00
Skye Wanderman-Milne
6caf20322c Use PyLong_FromLongLong to convert 64-bit ints in SWIG code.
On some platforms (namely Windows), a long is 32 bits, not 64.
This is what was causing random_ops_test to fail on Winodws.

PiperOrigin-RevId: 201427591
2018-06-20 15:33:58 -07:00