Beispiel #1
0
  def test_returns_value_with_federated_type_at_clients(self):
    value = [
        eager_tf_executor.EagerValue(10.0, None, tf.float32),
        eager_tf_executor.EagerValue(11.0, None, tf.float32),
        eager_tf_executor.EagerValue(12.0, None, tf.float32),
    ]
    type_signature = type_factory.at_clients(tf.float32)
    value = federating_executor.FederatingExecutorValue(value, type_signature)

    result = self.run_sync(value.compute())

    self.assertEqual(result, [10.0, 11.0, 12.0])
Beispiel #2
0
  def test_returns_value_with_federated_type_at_clients(self):
    tensor_type = computation_types.TensorType(tf.float32, shape=[])
    value = [
        eager_tf_executor.EagerValue(10.0, tensor_type),
        eager_tf_executor.EagerValue(11.0, tensor_type),
        eager_tf_executor.EagerValue(12.0, tensor_type),
    ]
    type_signature = computation_types.at_clients(tf.float32)
    value = federated_resolving_strategy.FederatedResolvingStrategyValue(
        value, type_signature)

    result = self.run_sync(value.compute())

    self.assertEqual(result, [10.0, 11.0, 12.0])
    def test_raises_type_error_with_value_and_bad_type(self):
        value = eager_tf_executor.EagerValue(10.0, None, tf.float32)
        bad_type_signature = None

        with self.assertRaises(TypeError):
            federating_executor.FederatingExecutorValue(
                value, bad_type_signature)
Beispiel #4
0
  def test_returns_value_with_embedded_value(self):
    value = eager_tf_executor.EagerValue(10.0, None, tf.float32)
    type_signature = computation_types.TensorType(tf.float32)
    value = federating_executor.FederatingExecutorValue(value, type_signature)

    result = self.run_sync(value.compute())

    self.assertEqual(result, 10.0)
Beispiel #5
0
 def test_eager_value_constructor_with_int_constant(self):
   int_tensor_type = computation_types.TensorType(dtype=tf.int32, shape=[])
   normalized_value = eager_tf_executor.to_representation_for_type(
       10, {}, int_tensor_type)
   v = eager_tf_executor.EagerValue(normalized_value, int_tensor_type)
   self.assertEqual(str(v.type_signature), 'int32')
   self.assertIsInstance(v.internal_representation, tf.Tensor)
   self.assertEqual(v.internal_representation, 10)
  def test_returns_value_with_federated_type_at_server(self):
    value = [eager_tf_executor.EagerValue(10.0, None, tf.float32)]
    type_signature = type_factory.at_server(tf.float32)
    value = federated_resolving_strategy.FederatedResolvingStrategyValue(
        value, type_signature)

    result = self.run_sync(value.compute())

    self.assertEqual(result, 10.0)
Beispiel #7
0
  def test_returns_value_with_embedded_value(self):
    tensor_type = computation_types.TensorType(tf.float32, shape=[])
    value = eager_tf_executor.EagerValue(10.0, tensor_type)
    type_signature = computation_types.TensorType(tf.float32)
    value = federated_resolving_strategy.FederatedResolvingStrategyValue(
        value, type_signature)

    result = self.run_sync(value.compute())

    self.assertEqual(result, 10.0)
Beispiel #8
0
    def test_returns_value_with_federated_type_at_clients_all_equal(self):
        value = [eager_tf_executor.EagerValue(10.0, None, tf.float32)]
        type_signature = computation_types.at_clients(tf.float32,
                                                      all_equal=True)
        value = federated_resolving_strategy.FederatedResolvingStrategyValue(
            value, type_signature)

        result = self.run_sync(value.compute())

        self.assertEqual(result, 10.0)
Beispiel #9
0
  def test_returns_value_with_anonymous_tuple_value(self):
    element = eager_tf_executor.EagerValue(10.0, None, tf.float32)
    element_type = computation_types.TensorType(tf.float32)
    names = ['a', 'b', 'c']
    value = anonymous_tuple.AnonymousTuple((n, element) for n in names)
    type_signature = computation_types.NamedTupleType(
        (n, element_type) for n in names)
    value = federating_executor.FederatingExecutorValue(value, type_signature)

    result = self.run_sync(value.compute())

    expected_result = anonymous_tuple.AnonymousTuple((n, 10.0) for n in names)
    self.assertEqual(result, expected_result)
Beispiel #10
0
    def test_returns_value_with_structure_value(self):
        element = eager_tf_executor.EagerValue(10.0, None, tf.float32)
        element_type = computation_types.TensorType(tf.float32)
        names = ['a', 'b', 'c']
        value = structure.Struct((n, element) for n in names)
        type_signature = computation_types.StructType(
            (n, element_type) for n in names)
        value = federated_resolving_strategy.FederatedResolvingStrategyValue(
            value, type_signature)

        result = self.run_sync(value.compute())

        expected_result = structure.Struct((n, 10.0) for n in names)
        self.assertEqual(result, expected_result)
 def test_eager_value_constructor_with_int_constant(self):
     v = eager_tf_executor.EagerValue(10, {}, tf.int32)
     self.assertEqual(str(v.type_signature), 'int32')
     self.assertIsInstance(v.internal_representation, tf.Tensor)
     self.assertEqual(v.internal_representation, 10)