(example, use_bfloat16)
Cast int64 into int32 and float32 to bfloat16 if use_bfloat16.
Cast int64 into int32 and float32 to bfloat16 if use_bfloat16.
Cast int64 into int32 and float32 to bfloat16 if use_bfloat16 .
def _convert_example(example, use_bfloat16):
  """Cast int64 into int32 and float32 to bfloat16 if use_bfloat16."""
  for key in list(example.keys()):
    val = example[key]
    if tf.keras.backend.is_sparse(val):
      val = tf.sparse.to_dense(val)
    if val.dtype == tf.int64:
      val = tf.cast(val, tf.int32)
    if use_bfloat16 and val.dtype == tf.float32:
      val = tf.cast(val, tf.bfloat16)

    example[key] = val
def _convert_example ( example , use_bfloat16 ) : for key in list ( example . keys ( ) ) : val = example [ key ] if tf . keras . backend . is_sparse ( val ) : val = tf . sparse . to_dense ( val ) if val . dtype == tf . int64 : val = tf . cast ( val , tf . int32 ) if use_bfloat16 and val . dtype == tf . float32 : val = tf . cast ( val , tf . bfloat16 ) example [ key ] = val