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
PR #38585: 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 #34399
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
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
- 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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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