@tf.custom_gradient
def converted_fun_flat_with_custom_gradient(*args_flat: TfVal) -> TfVal:
    out_with_avals = _interpret_fun(flat_fun, args_flat, args_avals_flat)
    (outs, out_avals) = util.unzip2(out_with_avals)
    return (tuple(outs), functools.partial(converted_grad_fn, _out_cts_avals=tuple(out_avals)))
@tf.custom_gradient
def converted_fun_flat_with_custom_gradient(*args_flat: TfVal) -> TfVal:
    out_with_avals = _interpret_fun(flat_fun, args_flat, args_avals_flat)
    (outs, out_avals) = util.unzip2(out_with_avals)
    return (tuple(outs), functools.partial(converted_grad_fn, _out_cts_avals=tuple(out_avals)))