|
29 | 29 |
|
30 | 30 | def check_tensor_sanity(tensor, logger): |
31 | 31 | """Tests for the present of NaNs and Infs in a tensor.""" |
32 | | - |
33 | | - if tf.reduce_any(tf.math.is_nan(tensor)): |
34 | | - num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy() |
35 | | - logger.warn(f"Warning! Returned estimates contain {num_na} nan values!") |
36 | | - if tf.reduce_any(tf.math.is_inf(tensor)): |
37 | | - num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy() |
38 | | - logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!") |
| 32 | + if tf.executing_eagerly(): |
| 33 | + if tf.reduce_any(tf.math.is_nan(tensor)): |
| 34 | + num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)).numpy() |
| 35 | + logger.warn(f"Warning! Returned estimates contain {num_na} nan values!") |
| 36 | + if tf.reduce_any(tf.math.is_inf(tensor)): |
| 37 | + num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)).numpy() |
| 38 | + logger.warn(f"Warning! Returned estimates contain {num_inf} inf values!") |
| 39 | + else: |
| 40 | + if tf.reduce_any(tf.math.is_nan(tensor)): |
| 41 | + num_na = tf.reduce_sum(tf.cast(tf.math.is_nan(tensor), tf.int8)) |
| 42 | + tf.print("Warning! Returned estimates contain", num_na, "nan values!") |
| 43 | + if tf.reduce_any(tf.math.is_inf(tensor)): |
| 44 | + num_inf = tf.reduce_sum(tf.cast(tf.math.is_inf(tensor), tf.int8)) |
| 45 | + tf.print(f"Warning! Returned estimates contain", num_inf, "inf values!") |
39 | 46 |
|
40 | 47 |
|
41 | 48 | def merge_left_into_right(left_dict, right_dict): |
|
0 commit comments