Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions reverb/server_executable/server_from_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
from reverb.cc import schema_pb2
from reverb.cc.checkpointing import checkpoint_pb2

# pylint: disable=g-direct-tensorflow-import
from tensorflow.python.saved_model import nested_structure_coder
# pylint: enable=g-direct-tensorflow-import


def selector_from_proto(
s: schema_pb2.KeyDistributionOptions
Expand Down Expand Up @@ -68,6 +72,10 @@ def tables_from_proto(
"""Convert protobuf to reverb.Table."""
tables = []
for config in configs:
if config.HasField('signature'):
signature = nested_structure_coder.decode_proto(config.signature)
else:
signature = None
tables.append(
reverb.Table(
name=config.table_name,
Expand All @@ -76,5 +84,6 @@ def tables_from_proto(
max_size=config.max_size,
rate_limiter=rate_limiter_from_proto(config.rate_limiter),
max_times_sampled=config.max_times_sampled,
signature=signature,
))
return tables
21 changes: 21 additions & 0 deletions reverb/server_executable/server_from_proto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
from absl.testing import parameterized
import reverb
from reverb.server_executable import server_from_proto
import tensorflow as tf

from reverb.cc import schema_pb2
from reverb.cc.checkpointing import checkpoint_pb2

# pylint: disable=g-direct-tensorflow-import
from tensorflow.python.saved_model import nested_structure_coder
# pylint: enable=g-direct-tensorflow-import


class ServerFromProtoTest(parameterized.TestCase):

Expand Down Expand Up @@ -99,6 +104,22 @@ def test_table_from_proto(self):
self.assertEqual(table_info.remover_options.fifo,
table_proto.remover.fifo)

def test_table_from_proto_preserves_signature(self):
signature = tf.TensorSpec([None, 3], tf.float32)
table_proto = checkpoint_pb2.PriorityTableCheckpoint()
table_proto.table_name = 'test_table'
table_proto.max_size = 101
table_proto.rate_limiter.min_diff = -100
table_proto.rate_limiter.max_diff = 200
table_proto.rate_limiter.samples_per_insert = 10
table_proto.rate_limiter.min_size_to_sample = 1
table_proto.sampler.lifo = True
table_proto.remover.fifo = True
table_proto.signature.CopyFrom(
nested_structure_coder.encode_structure(signature))
tables = server_from_proto.tables_from_proto([table_proto])
self.assertEqual(signature, tables[0].info.signature)


if __name__ == '__main__':
absltest.main()