From 286af5b55f575568356931d4a1a3eaa0c4b59c87 Mon Sep 17 00:00:00 2001 From: Emily Fertig Date: Mon, 15 Nov 2021 19:18:18 -0800 Subject: [PATCH 1/3] Revert "Change references of tf.__internal__.saved_model.StructureCoder to their replacement functions" This reverts commit 1020caa382572b79e7be0f8c46f478e14b982cfa for compatibility of TFP 0.15 with TensorFlow 2.7.0. --- tensorflow_probability/python/bijectors/blockwise_test.py | 5 +++-- tensorflow_probability/python/bijectors/chain_test.py | 5 +++-- tensorflow_probability/python/bijectors/joint_map_test.py | 5 +++-- .../python/experimental/util/composite_tensor.py | 3 ++- .../python/internal/auto_composite_tensor_test.py | 7 ++++--- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tensorflow_probability/python/bijectors/blockwise_test.py b/tensorflow_probability/python/bijectors/blockwise_test.py index 232b8253d8..ee19433c1f 100644 --- a/tensorflow_probability/python/bijectors/blockwise_test.py +++ b/tensorflow_probability/python/bijectors/blockwise_test.py @@ -314,8 +314,9 @@ def call_forward(bij, x): self.assertAllClose(call_forward(unflat, x), blockwise.forward(x)) # Type spec can be encoded/decoded. - enc = tf.__internal__.saved_model.encode_structure(blockwise._type_spec) - dec = tf.__internal__.saved_model.decode_proto(enc) + struct_coder = tf.__internal__.saved_model.StructureCoder() + enc = struct_coder.encode_structure(blockwise._type_spec) + dec = struct_coder.decode_proto(enc) self.assertEqual(blockwise._type_spec, dec) def testNonCompositeTensor(self): diff --git a/tensorflow_probability/python/bijectors/chain_test.py b/tensorflow_probability/python/bijectors/chain_test.py index 6a72080b8f..620c3fa972 100644 --- a/tensorflow_probability/python/bijectors/chain_test.py +++ b/tensorflow_probability/python/bijectors/chain_test.py @@ -432,8 +432,9 @@ def call_forward(bij, x): self.assertAllClose(call_forward(unflat, x), chain.forward(x)) # TypeSpec can be encoded/decoded. - enc = tf.__internal__.saved_model.encode_structure(chain._type_spec) - dec = tf.__internal__.saved_model.decode_proto(enc) + struct_coder = tf.__internal__.saved_model.StructureCoder() + enc = struct_coder.encode_structure(chain._type_spec) + dec = struct_coder.decode_proto(enc) self.assertEqual(chain._type_spec, dec) def testNonCompositeTensor(self): diff --git a/tensorflow_probability/python/bijectors/joint_map_test.py b/tensorflow_probability/python/bijectors/joint_map_test.py index 2228a566ac..94e91eccf8 100644 --- a/tensorflow_probability/python/bijectors/joint_map_test.py +++ b/tensorflow_probability/python/bijectors/joint_map_test.py @@ -150,8 +150,9 @@ def call_forward(bij, x): self.assertAllCloseNested(call_forward(unflat, x), bij.forward(x)) # Type spec can be encoded/decoded. - enc = tf.__internal__.saved_model.encode_structure(bij._type_spec) - dec = tf.__internal__.saved_model.decode_proto(enc) + struct_coder = tf.__internal__.saved_model.StructureCoder() + enc = struct_coder.encode_structure(bij._type_spec) + dec = struct_coder.decode_proto(enc) self.assertEqual(bij._type_spec, dec) def testNonCompositeTensor(self): diff --git a/tensorflow_probability/python/experimental/util/composite_tensor.py b/tensorflow_probability/python/experimental/util/composite_tensor.py index a8c94f3b2c..684d5dd95b 100644 --- a/tensorflow_probability/python/experimental/util/composite_tensor.py +++ b/tensorflow_probability/python/experimental/util/composite_tensor.py @@ -279,8 +279,9 @@ def composite_helper(v): mk_err_msg('(Unable to convert dependent entry \'{}\' of object ' '\'{}\': {})'.format(k, obj, str(e)))) result = cls(**kwargs) + struct_coder = nested_structure_coder.StructureCoder() try: - nested_structure_coder.encode_structure(result._type_spec) # pylint: disable=protected-access + struct_coder.encode_structure(result._type_spec) # pylint: disable=protected-access except nested_structure_coder.NotEncodableError as e: raise NotImplementedError( mk_err_msg('(Unable to serialize: {})'.format(str(e)))) diff --git a/tensorflow_probability/python/internal/auto_composite_tensor_test.py b/tensorflow_probability/python/internal/auto_composite_tensor_test.py index bb1512e085..3b2d739e1f 100644 --- a/tensorflow_probability/python/internal/auto_composite_tensor_test.py +++ b/tensorflow_probability/python/internal/auto_composite_tensor_test.py @@ -362,8 +362,9 @@ def test_save_restore_functor(self): a = tf.constant([3., 2.]) ct = ThingWithCallableArg(a, f=f) + struct_coder = tf.__internal__.saved_model.StructureCoder() with self.assertRaisesRegex(ValueError, 'Cannot serialize'): - tf.__internal__.saved_model.encode_structure(ct._type_spec) # pylint: disable=protected-access + struct_coder.encode_structure(ct._type_spec) # pylint: disable=protected-access @tfp.experimental.auto_composite_tensor(module_name='my.module') class F(tfp.experimental.AutoCompositeTensor): @@ -372,8 +373,8 @@ def __call__(self, *args, **kwargs): return f(*args, **kwargs) ct_functor = ThingWithCallableArg(a, f=F()) - enc = tf.__internal__.saved_model.encode_structure(ct_functor._type_spec) - dec = tf.__internal__.saved_model.decode_proto(enc) + enc = struct_coder.encode_structure(ct_functor._type_spec) + dec = struct_coder.decode_proto(enc) self.assertEqual(dec, ct_functor._type_spec) def test_composite_tensor_callable_arg(self): From 02f31b5d46314c5fe4fa0b3d2b6f9d31de17a7e9 Mon Sep 17 00:00:00 2001 From: emilyaf Date: Tue, 16 Nov 2021 15:53:35 -0800 Subject: [PATCH 2/3] Replace value in `simple_step_size_adaptation_test` to work around a test failure caused by different numerics in Numpy 1.21.4/Python 3.9. PiperOrigin-RevId: 410371438 --- .../python/mcmc/simple_step_size_adaptation_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_probability/python/mcmc/simple_step_size_adaptation_test.py b/tensorflow_probability/python/mcmc/simple_step_size_adaptation_test.py index 01cb6cd404..9ac4f98b3d 100644 --- a/tensorflow_probability/python/mcmc/simple_step_size_adaptation_test.py +++ b/tensorflow_probability/python/mcmc/simple_step_size_adaptation_test.py @@ -471,7 +471,7 @@ class SimpleStepSizeAdaptationStaticBroadcastingTest(test_util.TestCase): ) def testBroadcasting(self, old_step_size, new_step_size): log_accept_ratio = tf.constant( - [[np.log(0.73), np.log(0.76), np.log(0.73)], + [[np.log(0.72), np.log(0.76), np.log(0.73)], [np.log(0.77), np.log(0.77), np.log(0.73)]], dtype=tf.float64) log_accept_ratio = tf1.placeholder_with_default( From 47f35daddb75b0d4d01810832d82c4bd12e07bca Mon Sep 17 00:00:00 2001 From: Emily Fertig Date: Tue, 16 Nov 2021 22:09:47 -0800 Subject: [PATCH 3/3] Remove 'dev' suffix from version. --- tensorflow_probability/python/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_probability/python/version.py b/tensorflow_probability/python/version.py index 6a16e2fc66..cdd7e402d7 100644 --- a/tensorflow_probability/python/version.py +++ b/tensorflow_probability/python/version.py @@ -24,7 +24,7 @@ # stable release (indicated by `_VERSION_SUFFIX = ''`). Outside the context of a # release branch, the current version is by default assumed to be a # 'development' version, labeled 'dev'. -_VERSION_SUFFIX = 'dev' +_VERSION_SUFFIX = '' # Example, '0.4.0-dev' __version__ = '.'.join([