Skip to content

Commit a7b35af

Browse files
srvasudetensorflower-gardener
authored andcommitted
Enable numpy testing for distributions / bijectors.
PiperOrigin-RevId: 455513834
1 parent 0df7250 commit a7b35af

23 files changed

+55
-23
lines changed

tensorflow_probability/python/bijectors/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,6 @@ multi_substrate_py_test(
12541254
size = "medium",
12551255
srcs = ["correlation_cholesky_test.py"],
12561256
jax_size = "large",
1257-
numpy_tags = ["notap"],
12581257
shard_count = 2,
12591258
deps = [
12601259
":bijector_test_util",
@@ -1636,7 +1635,6 @@ multi_substrate_py_test(
16361635
name = "permute_test",
16371636
size = "small",
16381637
srcs = ["permute_test.py"],
1639-
numpy_tags = ["notap"],
16401638
deps = [
16411639
":bijector_test_util",
16421640
":bijectors",
@@ -1705,7 +1703,6 @@ multi_substrate_py_test(
17051703
name = "rational_quadratic_spline_test",
17061704
size = "medium",
17071705
srcs = ["rational_quadratic_spline_test.py"],
1708-
numpy_tags = ["notap"],
17091706
tags = ["hypothesis"],
17101707
deps = [
17111708
":bijector_test_util",

tensorflow_probability/python/bijectors/bijector_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,8 @@ def testInstanceCache(self):
904904
z = instance_cache_bijector.forward(x)
905905
self.assertIsNot(y, z)
906906

907-
@test_util.jax_disable_test_missing_functionality('keras')
907+
@test_util.disable_test_for_backend(
908+
disable_numpy=True, disable_jax=True, reason='keras')
908909
@parameterized.named_parameters(
909910
('Keras', True),
910911
('NoKeras', False))
@@ -1093,13 +1094,15 @@ def test_caches(self):
10931094
@test_util.test_all_tf_execution_regimes
10941095
class TfModuleTest(test_util.TestCase):
10951096

1097+
@test_util.numpy_disable_variable_test
10961098
@test_util.jax_disable_variable_test
10971099
def test_variable_tracking(self):
10981100
x = tf.Variable(1.)
10991101
b = ForwardOnlyBijector(scale=x, validate_args=True)
11001102
self.assertIsInstance(b, tf.Module)
11011103
self.assertEqual((x,), b.trainable_variables)
11021104

1105+
@test_util.numpy_disable_variable_test
11031106
@test_util.jax_disable_variable_test
11041107
def test_gradient(self):
11051108
x = tf.Variable(1.)

tensorflow_probability/python/bijectors/correlation_cholesky_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def sample_mcmc_chain():
227227
cdf=beta_dist.cdf,
228228
false_fail_rate=1e-9))
229229

230+
@test_util.numpy_disable_gradient_test
230231
def testTheoreticalFldj(self):
231232
bijector = tfb.CorrelationCholesky()
232233
x = np.linspace(-50, 50, num=30).reshape(5, 6).astype(np.float64)

tensorflow_probability/python/bijectors/permute_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ def testBijectiveAndFiniteAxis(self):
8383
bijector, x, y, eval_func=self.evaluate, event_ndims=2, rtol=1e-6,
8484
atol=0)
8585

86-
@test_util.jax_disable_test_missing_functionality(
87-
'Test specific to Keras with losing shape information.')
86+
@test_util.disable_test_for_backend(
87+
disable_numpy=True, disable_jax=True,
88+
reason='Test specific to Keras with losing shape information.')
8889
def testPreservesShape(self):
8990
# TODO(b/131157549, b/131124359): Test should not be needed. Consider
9091
# deleting when underlying issue with constant eager tensors is fixed.

tensorflow_probability/python/bijectors/rational_quadratic_spline_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def testDegenerateSplines(self):
144144
np.zeros_like(xs),
145145
self.evaluate(bijector.forward_log_det_jacobian(xs, event_ndims=0)))
146146

147+
@test_util.numpy_disable_gradient_test
147148
def testTheoreticalFldjSimple(self):
148149
bijector = tfb.RationalQuadraticSpline(
149150
bin_widths=[1., 1],

tensorflow_probability/python/distributions/BUILD

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,7 +2668,6 @@ multi_substrate_py_test(
26682668
size = "medium",
26692669
srcs = ["distribution_test.py"],
26702670
jax_size = "medium",
2671-
numpy_tags = ["notap"],
26722671
deps = [
26732672
# numpy dep,
26742673
# tensorflow dep,
@@ -2918,7 +2917,6 @@ multi_substrate_py_test(
29182917
multi_substrate_py_test(
29192918
name = "half_cauchy_test",
29202919
srcs = ["half_cauchy_test.py"],
2921-
numpy_tags = ["notap"],
29222920
shard_count = 5,
29232921
deps = [
29242922
# numpy dep,
@@ -2932,7 +2930,6 @@ multi_substrate_py_test(
29322930
multi_substrate_py_test(
29332931
name = "half_normal_test",
29342932
srcs = ["half_normal_test.py"],
2935-
numpy_tags = ["notap"],
29362933
deps = [
29372934
# numpy dep,
29382935
# scipy dep,
@@ -3157,7 +3154,6 @@ multi_substrate_py_test(
31573154
multi_substrate_py_test(
31583155
name = "lambertw_f_test",
31593156
srcs = ["lambertw_f_test.py"],
3160-
numpy_tags = ["notap"],
31613157
deps = [
31623158
":lambertw_f",
31633159
# absl/testing:parameterized dep,
@@ -3228,7 +3224,6 @@ multi_substrate_py_test(
32283224
multi_substrate_py_test(
32293225
name = "loglogistic_test",
32303226
srcs = ["loglogistic_test.py"],
3231-
numpy_tags = ["notap"],
32323227
deps = [
32333228
# numpy dep,
32343229
# scipy dep,
@@ -3339,7 +3334,6 @@ multi_substrate_py_test(
33393334
size = "medium",
33403335
srcs = ["mixture_same_family_test.py"],
33413336
jax_size = "large",
3342-
numpy_tags = ["notap"],
33433337
shard_count = 3,
33443338
deps = [
33453339
# hypothesis dep,
@@ -3370,7 +3364,6 @@ multi_substrate_py_test(
33703364
size = "medium",
33713365
srcs = ["multinomial_test.py"],
33723366
jax_size = "medium",
3373-
numpy_tags = ["notap"],
33743367
shard_count = 5,
33753368
deps = [
33763369
# hypothesis dep,
@@ -3426,7 +3419,6 @@ multi_substrate_py_test(
34263419
multi_substrate_py_test(
34273420
name = "mvn_diag_test",
34283421
srcs = ["mvn_diag_test.py"],
3429-
numpy_tags = ["notap"],
34303422
deps = [
34313423
# numpy dep,
34323424
# scipy dep,
@@ -3454,7 +3446,6 @@ multi_substrate_py_test(
34543446
multi_substrate_py_test(
34553447
name = "mvn_linear_operator_test",
34563448
srcs = ["mvn_linear_operator_test.py"],
3457-
numpy_tags = ["notap"],
34583449
deps = [
34593450
# numpy dep,
34603451
# scipy dep,
@@ -3481,7 +3472,6 @@ multi_substrate_py_test(
34813472
name = "mvn_tril_test",
34823473
size = "medium",
34833474
srcs = ["mvn_tril_test.py"],
3484-
numpy_tags = ["notap"],
34853475
shard_count = 7,
34863476
tags = ["nomsan"],
34873477
deps = [

tensorflow_probability/python/distributions/distribution_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def __init__(self, extra_param, *args, **kwargs):
787787
@test_util.test_all_tf_execution_regimes
788788
class TfModuleTest(test_util.TestCase):
789789

790+
@test_util.numpy_disable_variable_test
790791
@test_util.jax_disable_variable_test
791792
def test_variable_tracking_works(self):
792793
scale = tf.Variable(1.)

tensorflow_probability/python/distributions/half_cauchy_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def testHalfCauchySampleMultidimensionalMedian(self):
411411
expected_shape = (tf.TensorShape(n_).concatenate(half_cauchy.batch_shape))
412412
self.assertAllEqual(expected_shape, samples.shape)
413413

414+
@test_util.numpy_disable_gradient_test
414415
def testHalfCauchyPdfGradientZeroOutsideSupport(self):
415416
loc_ = [-3.1, -2., 0., 1.1]
416417
loc = self._create_placeholder_with_default(loc_, name='loc')
@@ -430,6 +431,7 @@ def testHalfCauchyPdfGradientZeroOutsideSupport(self):
430431
grads,
431432
[np.zeros_like(loc_), 0., np.zeros_like(loc_)])
432433

434+
@test_util.numpy_disable_gradient_test
433435
def testHalfCauchyCdfGradientZeroOutsideSupport(self):
434436
loc_ = [-3.1, -2., 0., 1.1]
435437
loc = self._create_placeholder_with_default(loc_, name='loc')
@@ -449,6 +451,7 @@ def testHalfCauchyCdfGradientZeroOutsideSupport(self):
449451
grads,
450452
[np.zeros_like(loc_), 0., np.zeros_like(loc_)])
451453

454+
@test_util.numpy_disable_gradient_test
452455
def testHalfCauchyGradientsAndValueFiniteAtLoc(self):
453456
batch_size = 1000
454457
loc_ = np.linspace(0., 100., batch_size)
@@ -470,6 +473,7 @@ def testHalfCauchyGradientsAndValueFiniteAtLoc(self):
470473
for grad in grads:
471474
self.assertAllFinite(grad)
472475

476+
@test_util.numpy_disable_gradient_test
473477
def testHalfCauchyGradientsAndValueFiniteAtGreaterThanLoc(self):
474478
batch_size = 1000
475479
loc = self._create_placeholder_with_default([0.] * batch_size, name='loc')

tensorflow_probability/python/distributions/half_normal_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def testHalfNormalQuantile(self):
154154
expected_x = sp_stats.halfnorm(scale=scale).ppf(p)
155155
self.assertAllClose(expected_x, self.evaluate(x), atol=0)
156156

157+
@test_util.numpy_disable_gradient_test
157158
@parameterized.parameters(np.float32, np.float64)
158159
def testFiniteGradients(self, dtype):
159160
scale = tf.constant(dtype(3.0))
@@ -318,12 +319,12 @@ def testHalfNormalHalfNormalKL(self):
318319

319320
kl = tfd.kl_divergence(a, b)
320321

321-
x = a.sample(int(4e5), seed=test_util.test_seed(hardcoded_seed=0))
322+
x = a.sample(int(6e5), seed=test_util.test_seed(hardcoded_seed=0))
322323
kl_samples = a.log_prob(x) - b.log_prob(x)
323324

324325
kl_, kl_samples_ = self.evaluate([kl, kl_samples])
325326
self.assertAllClose(kl_, true_kl, atol=2e-15)
326-
self.assertAllMeansClose(kl_samples_, true_kl, axis=0, atol=0., rtol=5e-2)
327+
self.assertAllMeansClose(kl_samples_, true_kl, axis=0, atol=0., rtol=8e-2)
327328

328329
zero_kl = tfd.kl_divergence(a, a)
329330
true_zero_kl_, zero_kl_ = self.evaluate([tf.zeros_like(zero_kl), zero_kl])

tensorflow_probability/python/distributions/johnson_su_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def testJohnsonSULogCDF(self):
219219
expected_cdf = sp_stats.johnsonsu.logcdf(x, skewness, tailweight, mu, sigma)
220220
self.assertAllClose(expected_cdf, self.evaluate(cdf), atol=0, rtol=1e-3)
221221

222+
@test_util.numpy_disable_gradient_test
222223
def testFiniteGradientAtDifficultPoints(self):
223224
def make_fn(dtype, attr):
224225
x = np.array([-100., -20., -5., 0., 5., 20., 100.]).astype(dtype)
@@ -318,9 +319,11 @@ def _testQuantileFiniteGradientAtDifficultPoints(self, dtype):
318319
self.assertAllFinite(grads[0])
319320
self.assertAllFinite(grads[1])
320321

322+
@test_util.numpy_disable_gradient_test
321323
def testQuantileFiniteGradientAtDifficultPointsFloat32(self):
322324
self._testQuantileFiniteGradientAtDifficultPoints(np.float32)
323325

326+
@test_util.numpy_disable_gradient_test
324327
def testQuantileFiniteGradientAtDifficultPointsFloat64(self):
325328
self._testQuantileFiniteGradientAtDifficultPoints(np.float64)
326329

@@ -389,6 +392,7 @@ def testJohnsonSUSample(self):
389392
self.assertAllEqual(expected_samples_shape, samples.shape)
390393
self.assertAllEqual(expected_samples_shape, sample_values.shape)
391394

395+
@test_util.numpy_disable_gradient_test
392396
def testJohnsonSUFullyReparameterized(self):
393397
skewness = tf.constant(1.0)
394398
tailweight = tf.constant(2.0)

0 commit comments

Comments
 (0)