def maybe_call_fn_and_grads(fn,<EOL>fn_arg_list,<EOL>result=None,<EOL>grads=None,<EOL>check_non_none_grads=True,<EOL>name=None):
with tf.compat.v1.name_scope(name, '<STR_LIT>',<EOL>[fn_arg_list, result, grads]):<EOL><INDENT>fn_arg_list = (list(fn_arg_list) if is_list_like(fn_arg_list)<EOL>else [fn_arg_list])<EOL>result, grads = _value_and_gradients(fn, fn_arg_list, result, grads)<EOL>if not all(r.dtype.is_floating<EOL>for r in (result if is_list_like(result) else [result])):  <EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if len(fn_arg_list) != len(grads):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if check_non_none_grads and any(g is None for g in grads):<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(fn_arg_list, grads))<EOL><DEDENT>return result, grads<EOL><DEDENT>
Calls `fn` and computes the gradient of the result wrt `args_list`.