(host_calls)
Validates the `eval_metrics` and `host_call` in `TPUEstimatorSpec`.
Validates the `eval_metrics` and `host_call` in `TPUEstimatorSpec`.
Validates the eval_metrics and host_call in TPUEstimatorSpec .
def validate(host_calls):
    """Validates the `eval_metrics` and `host_call` in `TPUEstimatorSpec`."""

    for name, host_call in host_calls.items():
      if not isinstance(host_call, (tuple, list)):
        raise ValueError('{} should be tuple or list'.format(name))
      if len(host_call) != 2:
        raise ValueError('{} should have two elements.'.format(name))
      if not callable(host_call[0]):
        raise TypeError('{}[0] should be callable.'.format(name))
      if not isinstance(host_call[1], (tuple, list, dict)):
        raise ValueError('{}[1] should be tuple or list, or dict.'.format(name))

      if isinstance(host_call[1], (tuple, list)):
        fullargspec = tf_inspect.getfullargspec(host_call[0])
        fn_args = function_utils.fn_args(host_call[0])
        # wrapped_hostcall_with_global_step uses varargs, so we allow that.
        if fullargspec.varargs is None and len(host_call[1]) != len(fn_args):
          raise RuntimeError(
              'In TPUEstimatorSpec.{}, length of tensors {} does not match '
              'method args of the function, which takes {}.'.format(
                  name, len(host_call[1]), len(fn_args)))
def validate ( host_calls ) : for name , host_call in host_calls . items ( ) : if not isinstance ( host_call , ( tuple , list ) ) : raise ValueError ( '{} should be tuple or list' . format ( name ) ) if len ( host_call ) != 2 : raise ValueError ( '{} should have two elements.' . format ( name ) ) if not callable ( host_call [ 0 ] ) : raise TypeError ( '{}[0] should be callable.' . format ( name ) ) if not isinstance ( host_call [ 1 ] , ( tuple , list , dict ) ) : raise ValueError ( '{}[1] should be tuple or list, or dict.' . format ( name ) ) if isinstance ( host_call [ 1 ] , ( tuple , list ) ) : fullargspec = tf_inspect . getfullargspec ( host_call [ 0 ] ) fn_args = function_utils . fn_args ( host_call [ 0 ] ) # wrapped_hostcall_with_global_step uses varargs, so we allow that. if fullargspec . varargs is None and len ( host_call [ 1 ] ) != len ( fn_args ) : raise RuntimeError ( 'In TPUEstimatorSpec.{}, length of tensors {} does not match ' 'method args of the function, which takes {}.' . format ( name , len ( host_call [ 1 ] ) , len ( fn_args ) ) )