From 344f63721671f4faa4e6b55d1da3687274893b7c Mon Sep 17 00:00:00 2001 From: Arun Ganesh Date: Thu, 22 Oct 2026 14:45:48 -0700 Subject: [PATCH] Avoid passing symbolic Tensors or NaN to dp_accounting DpEvents in tensorflow_federated. PiperOrigin-RevId: 1005068482 --- tensorflow_privacy/privacy/dp_query/gaussian_query.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tensorflow_privacy/privacy/dp_query/gaussian_query.py b/tensorflow_privacy/privacy/dp_query/gaussian_query.py index 5d03aedc..e73dbb16 100644 --- a/tensorflow_privacy/privacy/dp_query/gaussian_query.py +++ b/tensorflow_privacy/privacy/dp_query/gaussian_query.py @@ -91,7 +91,15 @@ def add_noise(v): return v + tf.cast(random_normal(tf.shape(input=v)), dtype=v.dtype) # pyrefly: ignore[not-callable] result = tf.nest.map_structure(add_noise, sample_state) - noise_multiplier = global_state.stddev / global_state.l2_norm_clip + if not tf.executing_eagerly(): + # Cannot pass symbolic tensors to dp_accounting.GaussianDpEvent. + return result, global_state, dp_accounting.UnsupportedDpEvent() + l2_norm_clip = float(global_state.l2_norm_clip) + noise_multiplier = ( + float('inf') + if l2_norm_clip == 0 + else float(global_state.stddev) / l2_norm_clip + ) event = dp_accounting.GaussianDpEvent(noise_multiplier) return result, global_state, event