Skip to content

Commit

Permalink
Update to the latest commit of federated-language.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 730461042
  • Loading branch information
michaelreneer authored and copybara-github committed Feb 24, 2025
1 parent e529c1a commit b95d06d
Show file tree
Hide file tree
Showing 29 changed files with 258 additions and 1,075 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ and this project adheres to
`federated_language.framework.computation_contains` instead.
* `tff.test.assert_types_equivalent`, use
`federated_language.Type.is_equivalent_to` instead.
* `tff.program.NativeFederatedContext`, use
`federated_language.program.NativeFederatedContext` instead.
* `tff.program.NativeValueReference`, use
`federated_language.program.NativeValueReference` instead.

## Release 0.88.0

Expand Down
7 changes: 4 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ http_archive(
http_archive(
name = "federated_language",
patches = [
"//third_party/federated_language:numpy.patch",
"//third_party/federated_language:proto_library_loads.patch",
"//third_party/federated_language:python_deps.patch",
# Must come after `python_deps.patch`, this patches the output of `python_deps.patch`.
Expand All @@ -98,9 +99,9 @@ http_archive(
repo_mapping = {
"@protobuf": "@com_google_protobuf",
},
sha256 = "d1500db4e6dc7403c3da121cf98ec03693b48384ec7cccae6fdc8ac3df182be0",
strip_prefix = "federated-language-be055feb0137577e0d27fe7c78aab87fbcb70b6d",
url = "https://github.com/google-parfait/federated-language/archive/be055feb0137577e0d27fe7c78aab87fbcb70b6d.tar.gz",
sha256 = "e2b13844d56233616d8ed664d15e155dbc6bb45743b6e5ce775a8553026b34a6",
strip_prefix = "federated-language-b685d2243891f9d7ca3c5820cfd690b4ecdb9697",
url = "https://github.com/google-parfait/federated-language/archive/b685d2243891f9d7ca3c5820cfd690b4ecdb9697.tar.gz",
)

# The version of TensorFlow should match the version in
Expand Down
2 changes: 1 addition & 1 deletion examples/learning/federated_program/vizier/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def main(argv: Sequence[str]) -> None:
raise app.UsageError('Too many command-line arguments.')

context = tff.backends.native.create_async_local_cpp_execution_context()
context = tff.program.NativeFederatedContext(context)
context = federated_language.program.NativeFederatedContext(context)
federated_language.framework.set_default_context(context)

timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
Expand Down
2 changes: 1 addition & 1 deletion examples/program/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def main(argv: Sequence[str]) -> None:

# Create a context in which to execute the program logic.
context = tff.backends.native.create_async_local_cpp_execution_context()
context = tff.program.NativeFederatedContext(context)
context = federated_language.program.NativeFederatedContext(context)
federated_language.framework.set_default_context(context)

# Create data sources that are compatible with the context and computations.
Expand Down
6 changes: 4 additions & 2 deletions examples/program/program_logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@

def _create_native_federated_context():
context = tff.backends.native.create_async_local_cpp_execution_context()
return tff.program.NativeFederatedContext(context)
return federated_language.program.NativeFederatedContext(context)


def _create_mock_context() -> mock.Mock:
return mock.create_autospec(
tff.program.NativeFederatedContext, spec_set=True, instance=True
federated_language.program.NativeFederatedContext,
spec_set=True,
instance=True,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ def test_type_properties(self, value_type, mechanism):
)
actual_next_type = process.next.type_signature
self.assertTrue(actual_next_type.is_equivalent_to(expected_next_type))
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

@parameterized.named_parameters(
Expand Down
18 changes: 10 additions & 8 deletions tensorflow_federated/python/aggregators/primitives_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ def comp_py_bounds(value):
np.array(1.0, dtype),
)

federated_language.framework.assert_not_contains_unsecure_aggregation(
comp_py_bounds
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
comp_py_bounds
)
)

# Bounds provided as tff values.
Expand All @@ -197,12 +199,12 @@ def comp_py_bounds(value):
def comp_tff_bounds(value, upper_bound, lower_bound):
return primitives.secure_quantized_sum(value, upper_bound, lower_bound)

try:
federated_language.framework.assert_not_contains_unsecure_aggregation(
comp_tff_bounds
)
except AssertionError:
self.fail('Computation contains non-secure aggregation.')
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
comp_tff_bounds
),
'Computation contains non-secure aggregation.',
)


class SecureQuantizedSumTest(tf.test.TestCase, parameterized.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ def test_secure_estimation_true_only_contains_secure_aggregation(self):
learning_rate=1.0,
secure_estimation=True,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
secure_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
secure_process.next
)
)


Expand Down
24 changes: 16 additions & 8 deletions tensorflow_federated/python/aggregators/secure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ def test_type_properties(self, modulus, value_type, symmetric_range):
self.assertTrue(
process.next.type_signature.is_equivalent_to(expected_next_type)
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

def test_float_modulus_raises(self):
Expand Down Expand Up @@ -321,8 +323,10 @@ def test_type_properties_constant_bounds(
self.assertTrue(
process.next.type_signature.is_equivalent_to(expected_next_type)
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

@parameterized.named_parameters(
Expand Down Expand Up @@ -374,8 +378,10 @@ def test_type_properties_single_bound(self, value_type, dtype):
self.assertTrue(
process.next.type_signature.is_equivalent_to(expected_next_type)
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

@parameterized.named_parameters(
Expand Down Expand Up @@ -430,8 +436,10 @@ def test_type_properties_adaptive_bounds(self, value_type, dtype):
self.assertTrue(
process.next.type_signature.is_equivalent_to(expected_next_type)
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

@parameterized.named_parameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,10 @@ def test_secure_sum(self, dp_mechanism):
dp_mechanism=dp_mechanism,
enable_secure_sum=True,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
hihi_computation
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
hihi_computation
)
)

@mock.patch('tensorflow.timestamp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ def _aggregation_predicate(
# computation.protos; to avoid opening up a visibility hole that isn't
# technically necessary here, we prefer to simply skip the static check here
# for computations which cannot convert themselves to building blocks.
if hasattr(
after_merge, 'to_building_block'
if isinstance(
after_merge, federated_language.framework.ConcreteComputation
) and federated_language.framework.computation_contains(
after_merge.to_building_block(), _aggregation_predicate
after_merge, _aggregation_predicate
):
formatted_aggregations = ', '.join(
'{}: {}'.format(elem[0], elem[1]) for elem in aggregations
Expand Down
18 changes: 12 additions & 6 deletions tensorflow_federated/python/learning/algorithms/fed_avg_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ def test_weighted_fed_avg_with_only_secure_aggregation(self):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)

def test_unweighted_fed_avg_with_only_secure_aggregation(self):
Expand All @@ -149,8 +151,10 @@ def test_unweighted_fed_avg_with_only_secure_aggregation(self):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)


Expand Down Expand Up @@ -182,8 +186,10 @@ def test_weighted_fed_avg_with_only_secure_aggregation(self, constructor):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ def test_construction_with_only_secure_aggregation(self):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)

def test_measurements_include_client_learning_rate(self):
Expand Down
12 changes: 8 additions & 4 deletions tensorflow_federated/python/learning/algorithms/fed_prox_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ def test_weighted_fed_prox_with_only_secure_aggregation(self):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)

def test_unweighted_fed_prox_with_only_secure_aggregation(self):
Expand All @@ -186,8 +188,10 @@ def test_unweighted_fed_prox_with_only_secure_aggregation(self):
),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)


Expand Down
12 changes: 8 additions & 4 deletions tensorflow_federated/python/learning/algorithms/fed_sgd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ def test_no_unsecure_aggregation_with_secure_aggregator(self):
model_aggregator=model_update_aggregator.secure_aggregator(),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)


Expand Down Expand Up @@ -287,8 +289,10 @@ def test_no_unsecure_aggregation_with_secure_aggregator(self):
model_aggregator=model_update_aggregator.secure_aggregator(),
metrics_aggregator=aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)


Expand Down
12 changes: 8 additions & 4 deletions tensorflow_federated/python/learning/algorithms/mime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,10 @@ def test_weighted_mime_lite_with_only_secure_aggregation(self):
full_gradient_aggregator=aggregator,
metrics_aggregator=metrics_aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)

def test_unweighted_mime_lite_with_only_secure_aggregation(self):
Expand All @@ -492,8 +494,10 @@ def test_unweighted_mime_lite_with_only_secure_aggregation(self):
full_gradient_aggregator=aggregator,
metrics_aggregator=metrics_aggregator.secure_sum_then_finalize,
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
learning_process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
learning_process.next
)
)

@tensorflow_test_utils.skip_test_for_multi_gpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ def test_default_value_ranges_returns_correct_results(
def aggregator_computation(unfinalized_metrics):
return polymorphic_aggregator_computation(unfinalized_metrics)

federated_language.framework.assert_not_contains_unsecure_aggregation(
aggregator_computation
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
aggregator_computation
)
)

aggregated_metrics = aggregator_computation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ def test_type_properties_with_inner_secure_sum_process(
self.assertTrue(
process.next.type_signature.is_equivalent_to(expected_next_type)
)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

@parameterized.named_parameters(
Expand Down Expand Up @@ -518,8 +520,10 @@ def test_secure_sum_then_finalize_metrics(self):

client_data = [local_unfinalized_metrics, local_unfinalized_metrics]
output = process.next(state, client_data)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

_, unfinalized_metrics_accumulators = output.state
Expand Down Expand Up @@ -600,8 +604,10 @@ def test_default_value_ranges_returns_correct_results(self):
collections.OrderedDict,
)
process = aggregate_factory.create(local_unfinalized_metrics_type)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

state = process.initialize()
Expand Down Expand Up @@ -688,8 +694,10 @@ def test_user_value_ranges_returns_correct_results(self):
metric_value_ranges
)
process = aggregate_factory.create(local_unfinalized_metrics_type)
federated_language.framework.assert_not_contains_unsecure_aggregation(
process.next
self.assertFalse(
federated_language.framework.computation_contains_unsecure_aggregation(
process.next
)
)

state = process.initialize()
Expand Down
Loading

0 comments on commit b95d06d

Please sign in to comment.