Beispiel #1
0
def ragged_tensor_to_variant(rt_nested_splits,
                             rt_dense_values,
                             batched_input,
                             name=None):
    r"""Encodes a `RaggedTensor` into a `variant` Tensor.

  
  Encodes the given `RaggedTensor` and returns a `variant` Tensor. If
  `batched_input` is True, then input `RaggedTensor` is unbatched along the
  zero-th dimension, each component `RaggedTensor` is encoded into a scalar
  `variant` Tensor, and these are stacked to return a 1-D `variant` Tensor.
  If `batched_input` is False, then the input `RaggedTensor` is encoded as is and
  a scalar `variant` Tensor is returned. A `RaggedTensor` is encoded by first
  creating a 1-D `variant` Tensor with `ragged_rank + 1` elements, containing the
  splits and values Tensors of the `RaggedTensor`. Then the 1-D `variant` Tensor
  is wrapped in a scalar `variant` Tensor. See `RaggedTensorFromVariant` for the
  corresponding decoding logic.

  Args:
    rt_nested_splits: A list of `Tensor` objects with the same type in: `int32`, `int64`.
      A list of one or more Tensors representing the splits of the input
      `RaggedTensor`.
    rt_dense_values: A `Tensor`.
      A Tensor representing the values of the input `RaggedTensor`.
    batched_input: A `bool`.
      A `bool` denoting whether the input is a batched `RaggedTensor`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `variant`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "RaggedTensorToVariant",
                name, tld.op_callbacks, rt_nested_splits, rt_dense_values,
                "batched_input", batched_input)
            return _result
        except _core._FallbackException:
            try:
                return ragged_tensor_to_variant_eager_fallback(
                    rt_nested_splits,
                    rt_dense_values,
                    batched_input=batched_input,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    if not isinstance(rt_nested_splits, (list, tuple)):
        raise TypeError("Expected list for 'rt_nested_splits' argument to "
                        "'ragged_tensor_to_variant' Op, not %r." %
                        rt_nested_splits)
    _attr_RAGGED_RANK = len(rt_nested_splits)
    batched_input = _execute.make_bool(batched_input, "batched_input")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "RaggedTensorToVariant",
        rt_nested_splits=rt_nested_splits,
        rt_dense_values=rt_dense_values,
        batched_input=batched_input,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("RAGGED_RANK", _op._get_attr_int("RAGGED_RANK"), "Tvalues",
                  _op._get_attr_type("Tvalues"), "Tsplits",
                  _op._get_attr_type("Tsplits"), "batched_input",
                  _op._get_attr_bool("batched_input"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("RaggedTensorToVariant", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result
def enter(data,
          frame_name,
          is_constant=False,
          parallel_iterations=10,
          name=None):
    r"""Creates or finds a child frame, and makes `data` available to the child frame.

  This op is used together with `Exit` to create loops in the graph.
  The unique `frame_name` is used by the `Executor` to identify frames. If
  `is_constant` is true, `output` is a constant in the child frame; otherwise
  it may be changed in the child frame. At most `parallel_iterations` iterations
  are run in parallel in the child frame.

  Args:
    data: A `Tensor`. The tensor to be made available to the child frame.
    frame_name: A `string`. The name of the child frame.
    is_constant: An optional `bool`. Defaults to `False`.
      If true, the output is constant within the child frame.
    parallel_iterations: An optional `int`. Defaults to `10`.
      The number of iterations allowed to run in parallel.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `data`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "Enter", name,
                tld.op_callbacks, data, "frame_name", frame_name,
                "is_constant", is_constant, "parallel_iterations",
                parallel_iterations)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return enter_eager_fallback(
                data,
                frame_name=frame_name,
                is_constant=is_constant,
                parallel_iterations=parallel_iterations,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    frame_name = _execute.make_str(frame_name, "frame_name")
    if is_constant is None:
        is_constant = False
    is_constant = _execute.make_bool(is_constant, "is_constant")
    if parallel_iterations is None:
        parallel_iterations = 10
    parallel_iterations = _execute.make_int(parallel_iterations,
                                            "parallel_iterations")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "Enter",
        data=data,
        frame_name=frame_name,
        is_constant=is_constant,
        parallel_iterations=parallel_iterations,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("T", _op._get_attr_type("T"), "frame_name",
                  _op.get_attr("frame_name"), "is_constant",
                  _op._get_attr_bool("is_constant"), "parallel_iterations",
                  _op._get_attr_int("parallel_iterations"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("Enter", _inputs_flat, _attrs, _result)
    _result, = _result
    return _result
Beispiel #3
0
def generate_vocab_remapping(new_vocab_file,
                             old_vocab_file,
                             new_vocab_offset,
                             num_new_vocab,
                             old_vocab_size=-1,
                             name=None):
    r"""Given a path to new and old vocabulary files, returns a remapping Tensor of

  length `num_new_vocab`, where `remapping[i]` contains the row number in the old
  vocabulary that corresponds to row `i` in the new vocabulary (starting at line
  `new_vocab_offset` and up to `num_new_vocab` entities), or `-1` if entry `i`
  in the new vocabulary is not in the old vocabulary.  The old vocabulary is
  constrained to the first `old_vocab_size` entries if `old_vocab_size` is not the
  default value of -1.

  `num_vocab_offset` enables
  use in the partitioned variable case, and should generally be set through
  examining partitioning info.  The format of the files should be a text file,
  with each line containing a single entity within the vocabulary.

  For example, with `new_vocab_file` a text file containing each of the following
  elements on a single line: `[f0, f1, f2, f3]`, old_vocab_file = [f1, f0, f3],
  `num_new_vocab = 3, new_vocab_offset = 1`, the returned remapping would be
  `[0, -1, 2]`.

  The op also returns a count of how many entries in the new vocabulary
  were present in the old vocabulary, which is used to calculate the number of
  values to initialize in a weight matrix remapping

  This functionality can be used to remap both row vocabularies (typically,
  features) and column vocabularies (typically, classes) from TensorFlow
  checkpoints.  Note that the partitioning logic relies on contiguous vocabularies
  corresponding to div-partitioned variables.  Moreover, the underlying remapping
  uses an IndexTable (as opposed to an inexact CuckooTable), so client code should
  use the corresponding index_table_from_file() as the FeatureColumn framework
  does (as opposed to tf.feature_to_id(), which uses a CuckooTable).

  Args:
    new_vocab_file: A `Tensor` of type `string`. Path to the new vocab file.
    old_vocab_file: A `Tensor` of type `string`. Path to the old vocab file.
    new_vocab_offset: An `int` that is `>= 0`.
      How many entries into the new vocab file to start reading.
    num_new_vocab: An `int` that is `>= 0`.
      Number of entries in the new vocab file to remap.
    old_vocab_size: An optional `int` that is `>= -1`. Defaults to `-1`.
      Number of entries in the old vocab file to consider.  If -1,
      use the entire old vocabulary.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (remapping, num_present).

    remapping: A `Tensor` of type `int64`.
    num_present: A `Tensor` of type `int32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "GenerateVocabRemapping", name, new_vocab_file,
                old_vocab_file, "new_vocab_offset", new_vocab_offset,
                "num_new_vocab", num_new_vocab, "old_vocab_size",
                old_vocab_size)
            _result = _GenerateVocabRemappingOutput._make(_result)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return generate_vocab_remapping_eager_fallback(
                new_vocab_file,
                old_vocab_file,
                new_vocab_offset=new_vocab_offset,
                num_new_vocab=num_new_vocab,
                old_vocab_size=old_vocab_size,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    new_vocab_offset = _execute.make_int(new_vocab_offset, "new_vocab_offset")
    num_new_vocab = _execute.make_int(num_new_vocab, "num_new_vocab")
    if old_vocab_size is None:
        old_vocab_size = -1
    old_vocab_size = _execute.make_int(old_vocab_size, "old_vocab_size")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "GenerateVocabRemapping",
        new_vocab_file=new_vocab_file,
        old_vocab_file=old_vocab_file,
        new_vocab_offset=new_vocab_offset,
        num_new_vocab=num_new_vocab,
        old_vocab_size=old_vocab_size,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("new_vocab_offset", _op._get_attr_int("new_vocab_offset"),
                  "num_new_vocab", _op._get_attr_int("num_new_vocab"),
                  "old_vocab_size", _op._get_attr_int("old_vocab_size"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("GenerateVocabRemapping", _inputs_flat,
                                 _attrs, _result)
    _result = _GenerateVocabRemappingOutput._make(_result)
    return _result
def ragged_range(starts, limits, deltas, Tsplits=_dtypes.int64, name=None):
    r"""Returns a `RaggedTensor` containing the specified sequences of numbers.

  
  Returns a `RaggedTensor` `result` composed from `rt_dense_values` and
  `rt_nested_splits`, such that
  `result[i] = range(starts[i], limits[i], deltas[i])`.

  ```python
  (rt_nested_splits, rt_dense_values) = ragged_range(
        starts=[2, 5, 8], limits=[3, 5, 12], deltas=1)
  result = tf.ragged.from_row_splits(rt_dense_values, rt_nested_splits)
  print(result)
  <tf.RaggedTensor [[2], [], [8, 9, 10, 11]] >
  ```

  The input tensors `starts`, `limits`, and `deltas` may be scalars or vectors.
  The vector inputs must all have the same size.  Scalar inputs are broadcast
  to match the size of the vector inputs.

  Args:
    starts: A `Tensor`. Must be one of the following types: `bfloat16`, `float32`, `float64`, `int32`, `int64`.
      The starts of each range.
    limits: A `Tensor`. Must have the same type as `starts`.
      The limits of each range.
    deltas: A `Tensor`. Must have the same type as `starts`.
      The deltas of each range.
    Tsplits: An optional `tf.DType` from: `tf.int32, tf.int64`. Defaults to `tf.int64`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (rt_nested_splits, rt_dense_values).

    rt_nested_splits: A `Tensor` of type `Tsplits`.
    rt_dense_values: A `Tensor`. Has the same type as `starts`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "RaggedRange", name,
                tld.op_callbacks, starts, limits, deltas, "Tsplits", Tsplits)
            _result = _RaggedRangeOutput._make(_result)
            return _result
        except _core._FallbackException:
            try:
                return ragged_range_eager_fallback(starts,
                                                   limits,
                                                   deltas,
                                                   Tsplits=Tsplits,
                                                   name=name,
                                                   ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    if Tsplits is None:
        Tsplits = _dtypes.int64
    Tsplits = _execute.make_type(Tsplits, "Tsplits")
    _, _, _op, _outputs = _op_def_library._apply_op_helper("RaggedRange",
                                                           starts=starts,
                                                           limits=limits,
                                                           deltas=deltas,
                                                           Tsplits=Tsplits,
                                                           name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("T", _op._get_attr_type("T"), "Tsplits",
                  _op._get_attr_type("Tsplits"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("RaggedRange", _inputs_flat, _attrs, _result)
    _result = _RaggedRangeOutput._make(_result)
    return _result
Beispiel #5
0
def fixed_unigram_candidate_sampler(true_classes,
                                    num_true,
                                    num_sampled,
                                    unique,
                                    range_max,
                                    vocab_file="",
                                    distortion=1,
                                    num_reserved_ids=0,
                                    num_shards=1,
                                    shard=0,
                                    unigrams=[],
                                    seed=0,
                                    seed2=0,
                                    name=None):
    r"""Generates labels for candidate sampling with a learned unigram distribution.

  A unigram sampler could use a fixed unigram distribution read from a
  file or passed in as an in-memory array instead of building up the distribution
  from data on the fly. There is also an option to skew the distribution by
  applying a distortion power to the weights.

  The vocabulary file should be in CSV-like format, with the last field
  being the weight associated with the word.

  For each batch, this op picks a single set of sampled candidate labels.

  The advantages of sampling candidates per-batch are simplicity and the
  possibility of efficient dense matrix multiplication. The disadvantage is that
  the sampled candidates must be chosen independently of the context and of the
  true labels.

  Args:
    true_classes: A `Tensor` of type `int64`.
      A batch_size * num_true matrix, in which each row contains the
      IDs of the num_true target_classes in the corresponding original label.
    num_true: An `int` that is `>= 1`. Number of true labels per context.
    num_sampled: An `int` that is `>= 1`.
      Number of candidates to randomly sample.
    unique: A `bool`.
      If unique is true, we sample with rejection, so that all sampled
      candidates in a batch are unique. This requires some approximation to
      estimate the post-rejection sampling probabilities.
    range_max: An `int` that is `>= 1`.
      The sampler will sample integers from the interval [0, range_max).
    vocab_file: An optional `string`. Defaults to `""`.
      Each valid line in this file (which should have a CSV-like format)
      corresponds to a valid word ID. IDs are in sequential order, starting from
      num_reserved_ids. The last entry in each line is expected to be a value
      corresponding to the count or relative probability. Exactly one of vocab_file
      and unigrams needs to be passed to this op.
    distortion: An optional `float`. Defaults to `1`.
      The distortion is used to skew the unigram probability distribution.
      Each weight is first raised to the distortion's power before adding to the
      internal unigram distribution. As a result, distortion = 1.0 gives regular
      unigram sampling (as defined by the vocab file), and distortion = 0.0 gives
      a uniform distribution.
    num_reserved_ids: An optional `int`. Defaults to `0`.
      Optionally some reserved IDs can be added in the range [0,
      ..., num_reserved_ids) by the users. One use case is that a special unknown
      word token is used as ID 0. These IDs will have a sampling probability of 0.
    num_shards: An optional `int` that is `>= 1`. Defaults to `1`.
      A sampler can be used to sample from a subset of the original range
      in order to speed up the whole computation through parallelism. This parameter
      (together with 'shard') indicates the number of partitions that are being
      used in the overall computation.
    shard: An optional `int` that is `>= 0`. Defaults to `0`.
      A sampler can be used to sample from a subset of the original range
      in order to speed up the whole computation through parallelism. This parameter
      (together with 'num_shards') indicates the particular partition number of a
      sampler op, when partitioning is being used.
    unigrams: An optional list of `floats`. Defaults to `[]`.
      A list of unigram counts or probabilities, one per ID in sequential
      order. Exactly one of vocab_file and unigrams should be passed to this op.
    seed: An optional `int`. Defaults to `0`.
      If either seed or seed2 are set to be non-zero, the random number
      generator is seeded by the given seed.  Otherwise, it is seeded by a
      random seed.
    seed2: An optional `int`. Defaults to `0`.
      An second seed to avoid seed collision.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (sampled_candidates, true_expected_count, sampled_expected_count).

    sampled_candidates: A `Tensor` of type `int64`.
    true_expected_count: A `Tensor` of type `float32`.
    sampled_expected_count: A `Tensor` of type `float32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "FixedUnigramCandidateSampler", name, true_classes,
                "num_true", num_true, "num_sampled", num_sampled, "unique",
                unique, "range_max", range_max, "vocab_file", vocab_file,
                "distortion", distortion, "num_reserved_ids", num_reserved_ids,
                "num_shards", num_shards, "shard", shard, "unigrams", unigrams,
                "seed", seed, "seed2", seed2)
            _result = _FixedUnigramCandidateSamplerOutput._make(_result)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return fixed_unigram_candidate_sampler_eager_fallback(
                true_classes,
                num_true=num_true,
                num_sampled=num_sampled,
                unique=unique,
                range_max=range_max,
                vocab_file=vocab_file,
                distortion=distortion,
                num_reserved_ids=num_reserved_ids,
                num_shards=num_shards,
                shard=shard,
                unigrams=unigrams,
                seed=seed,
                seed2=seed2,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    num_true = _execute.make_int(num_true, "num_true")
    num_sampled = _execute.make_int(num_sampled, "num_sampled")
    unique = _execute.make_bool(unique, "unique")
    range_max = _execute.make_int(range_max, "range_max")
    if vocab_file is None:
        vocab_file = ""
    vocab_file = _execute.make_str(vocab_file, "vocab_file")
    if distortion is None:
        distortion = 1
    distortion = _execute.make_float(distortion, "distortion")
    if num_reserved_ids is None:
        num_reserved_ids = 0
    num_reserved_ids = _execute.make_int(num_reserved_ids, "num_reserved_ids")
    if num_shards is None:
        num_shards = 1
    num_shards = _execute.make_int(num_shards, "num_shards")
    if shard is None:
        shard = 0
    shard = _execute.make_int(shard, "shard")
    if unigrams is None:
        unigrams = []
    if not isinstance(unigrams, (list, tuple)):
        raise TypeError("Expected list for 'unigrams' argument to "
                        "'fixed_unigram_candidate_sampler' Op, not %r." %
                        unigrams)
    unigrams = [_execute.make_float(_f, "unigrams") for _f in unigrams]
    if seed is None:
        seed = 0
    seed = _execute.make_int(seed, "seed")
    if seed2 is None:
        seed2 = 0
    seed2 = _execute.make_int(seed2, "seed2")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "FixedUnigramCandidateSampler",
        true_classes=true_classes,
        num_true=num_true,
        num_sampled=num_sampled,
        unique=unique,
        range_max=range_max,
        vocab_file=vocab_file,
        distortion=distortion,
        num_reserved_ids=num_reserved_ids,
        num_shards=num_shards,
        shard=shard,
        unigrams=unigrams,
        seed=seed,
        seed2=seed2,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("num_true", _op._get_attr_int("num_true"), "num_sampled",
                  _op._get_attr_int("num_sampled"), "unique",
                  _op._get_attr_bool("unique"), "range_max",
                  _op._get_attr_int("range_max"), "vocab_file",
                  _op.get_attr("vocab_file"), "distortion",
                  _op.get_attr("distortion"), "num_reserved_ids",
                  _op._get_attr_int("num_reserved_ids"), "num_shards",
                  _op._get_attr_int("num_shards"), "shard",
                  _op._get_attr_int("shard"), "unigrams",
                  _op.get_attr("unigrams"), "seed", _op._get_attr_int("seed"),
                  "seed2", _op._get_attr_int("seed2"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("FixedUnigramCandidateSampler", _inputs_flat,
                                 _attrs, _result)
    _result = _FixedUnigramCandidateSamplerOutput._make(_result)
    return _result
Beispiel #6
0
def debug_nan_count(input, device_name="", tensor_name="", debug_urls=[], gated_grpc=False, name=None):
  r"""Debug NaN Value Counter Op.

  Counts number of NaNs in the input tensor, for debugging.

  Args:
    input: A `Tensor`. Input tensor, non-Reference type.
    device_name: An optional `string`. Defaults to `""`.
    tensor_name: An optional `string`. Defaults to `""`.
      Name of the input tensor.
    debug_urls: An optional list of `strings`. Defaults to `[]`.
      List of URLs to debug targets, e.g.,
        file:///foo/tfdbg_dump, grpc:://localhost:11011.
    gated_grpc: An optional `bool`. Defaults to `False`.
       Whether this op will be gated. If any of the debug_urls of this
        debug node is of the grpc:// scheme, when the value of this attribute is set
        to True, the data will not actually be sent via the grpc stream unless this
        debug op has been enabled at the debug_url. If all of the debug_urls of this
        debug node are of the grpc:// scheme and the debug op is enabled at none of
        them, the output will be an empty Tensor.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int64`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "DebugNanCount", name, input, "device_name", device_name,
        "tensor_name", tensor_name, "debug_urls", debug_urls, "gated_grpc",
        gated_grpc)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return debug_nan_count_eager_fallback(
          input, device_name=device_name, tensor_name=tensor_name,
          debug_urls=debug_urls, gated_grpc=gated_grpc, name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  if device_name is None:
    device_name = ""
  device_name = _execute.make_str(device_name, "device_name")
  if tensor_name is None:
    tensor_name = ""
  tensor_name = _execute.make_str(tensor_name, "tensor_name")
  if debug_urls is None:
    debug_urls = []
  if not isinstance(debug_urls, (list, tuple)):
    raise TypeError(
        "Expected list for 'debug_urls' argument to "
        "'debug_nan_count' Op, not %r." % debug_urls)
  debug_urls = [_execute.make_str(_s, "debug_urls") for _s in debug_urls]
  if gated_grpc is None:
    gated_grpc = False
  gated_grpc = _execute.make_bool(gated_grpc, "gated_grpc")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "DebugNanCount", input=input, device_name=device_name,
                         tensor_name=tensor_name, debug_urls=debug_urls,
                         gated_grpc=gated_grpc, name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("T", _op._get_attr_type("T"), "device_name",
              _op.get_attr("device_name"), "tensor_name",
              _op.get_attr("tensor_name"), "debug_urls",
              _op.get_attr("debug_urls"), "gated_grpc",
              _op._get_attr_bool("gated_grpc"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "DebugNanCount", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
Beispiel #7
0
def debug_numeric_summary_v2(input, output_dtype=_dtypes.float32, tensor_debug_mode=-1, tensor_id=-1, name=None):
  r"""Debug Numeric Summary V2 Op.

  Computes a numeric summary of the input tensor. The shape of the output
  depends on the tensor_debug_mode attribute.
  This op is used internally by TensorFlow Debugger (tfdbg) v2.

  Args:
    input: A `Tensor`. Input tensor, to be summarized by the op.
    output_dtype: An optional `tf.DType` from: `tf.float32, tf.float64`. Defaults to `tf.float32`.
      Optional. The type of the output. Can be float32 or float64 (default: float32).
    tensor_debug_mode: An optional `int`. Defaults to `-1`.
      Tensor debug mode: the mode in which the input tensor is summarized
        by the op. See the TensorDebugMode enum in
        tensorflow/core/protobuf/debug_event.proto for details.

      Supported values:
        2 (CURT_HEALTH): Output a float32/64 tensor of shape [2]. The 1st
        element is the tensor_id, if provided, and -1 otherwise. The 2nd
        element is a bit which is set to 1 if the input tensor has an
        infinity or nan value, or zero otherwise.

        3 (CONCISE_HEALTH): Output a float32/64 tensor of shape [5]. The 1st
        element is the tensor_id, if provided, and -1 otherwise. The
        remaining four slots are the total number of elements, -infs,
        +infs, and nans in the input tensor respectively.

        4 (FULL_HEALTH): Output a float32/64 tensor of shape [11]. The 1st
        element is the tensor_id, if provided, and -1 otherwise. The 2nd
        element is the device_id, if provided, and -1 otherwise. The 3rd
        element holds the datatype value of the input tensor as according
        to the enumerated type in tensorflow/core/framework/types.proto.
        The remaining elements hold the total number of elements, -infs,
        +infs, nans, negative finite numbers, zeros, and positive finite
        numbers in the input tensor respectively.

        5 (SHAPE): Output a float32/64 tensor of shape [10]. The 1st
        element is the tensor_id, if provided, and -1 otherwise. The 2nd
        element holds the datatype value of the input tensor as according
        to the enumerated type in tensorflow/core/framework/types.proto.
        The 3rd element holds the rank of the tensor. The 4th element holds
        the number of elements within the tensor. Finally the remaining 6
        elements hold the shape of the tensor. If the rank of the tensor
        is lower than 6, the shape is right padded with zeros. If the rank
        is greater than 6, the head of the shape is truncated.

        6 (FULL_NUMERICS): Output a float32/64 tensor of shape [22]. The 1st
        element is the tensor_id, if provided, and -1 otherwise. The 2nd
        element is the device_id, if provided, and -1 otherwise. The 3rd
        element holds the datatype value of the input tensor as according
        to the enumerated type in tensorflow/core/framework/types.proto.
        The 4th element holds the rank of the tensor. The 5th to 11th
        elements hold the shape of the tensor. If the rank of the tensor
        is lower than 6, the shape is right padded with zeros. If the rank
        is greater than 6, the head of the shape is truncated. The 12th to
        18th elements hold the number of elements, -infs, +infs, nans,
        denormal floats, negative finite numbers, zeros, and positive
        finite numbers in the input tensor respectively. The final four
        elements hold the min value, max value, mean, and variance of the
        input tensor.

        8 (REDUCE_INF_NAN_THREE_SLOTS): Output a float32/64 tensor of shape
        [3]. The 1st element is -inf if any elements of the input tensor
        is -inf, or zero otherwise. The 2nd element is +inf if any elements
        of the input tensor is +inf, or zero otherwise.  The 3rd element is
        nan if any element of the input tensor is nan, or zero otherwise.
    tensor_id: An optional `int`. Defaults to `-1`.
      Optional. An integer identifier for the tensor being summarized by this op.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `output_dtype`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "DebugNumericSummaryV2", name, input, "output_dtype",
        output_dtype, "tensor_debug_mode", tensor_debug_mode, "tensor_id",
        tensor_id)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return debug_numeric_summary_v2_eager_fallback(
          input, output_dtype=output_dtype,
          tensor_debug_mode=tensor_debug_mode, tensor_id=tensor_id, name=name,
          ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  if output_dtype is None:
    output_dtype = _dtypes.float32
  output_dtype = _execute.make_type(output_dtype, "output_dtype")
  if tensor_debug_mode is None:
    tensor_debug_mode = -1
  tensor_debug_mode = _execute.make_int(tensor_debug_mode, "tensor_debug_mode")
  if tensor_id is None:
    tensor_id = -1
  tensor_id = _execute.make_int(tensor_id, "tensor_id")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "DebugNumericSummaryV2", input=input, output_dtype=output_dtype,
                                 tensor_debug_mode=tensor_debug_mode,
                                 tensor_id=tensor_id, name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("output_dtype", _op._get_attr_type("output_dtype"), "T",
              _op._get_attr_type("T"), "tensor_debug_mode",
              _op._get_attr_int("tensor_debug_mode"), "tensor_id",
              _op._get_attr_int("tensor_id"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "DebugNumericSummaryV2", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
Beispiel #8
0
def set_size(set_indices,
             set_values,
             set_shape,
             validate_indices=True,
             name=None):
    r"""Number of unique elements along last dimension of input `set`.

  Input `set` is a `SparseTensor` represented by `set_indices`, `set_values`,
  and `set_shape`. The last dimension contains values in a set, duplicates are
  allowed but ignored.

  If `validate_indices` is `True`, this op validates the order and range of `set`
  indices.

  Args:
    set_indices: A `Tensor` of type `int64`.
      2D `Tensor`, indices of a `SparseTensor`.
    set_values: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
      1D `Tensor`, values of a `SparseTensor`.
    set_shape: A `Tensor` of type `int64`.
      1D `Tensor`, shape of a `SparseTensor`.
    validate_indices: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "SetSize", name, set_indices, set_values, set_shape,
                "validate_indices", validate_indices)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return set_size_eager_fallback(set_indices,
                                           set_values,
                                           set_shape,
                                           validate_indices=validate_indices,
                                           name=name,
                                           ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    if validate_indices is None:
        validate_indices = True
    validate_indices = _execute.make_bool(validate_indices, "validate_indices")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "SetSize",
        set_indices=set_indices,
        set_values=set_values,
        set_shape=set_shape,
        validate_indices=validate_indices,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("validate_indices", _op._get_attr_bool("validate_indices"),
                  "T", _op._get_attr_type("T"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("SetSize", _inputs_flat, _attrs, _result)
    _result, = _result
    return _result
def audio_microfrontend(audio,
                        sample_rate=16000,
                        window_size=25,
                        window_step=10,
                        num_channels=32,
                        upper_band_limit=7500,
                        lower_band_limit=125,
                        smoothing_bits=10,
                        even_smoothing=0.025,
                        odd_smoothing=0.06,
                        min_signal_remaining=0.05,
                        enable_pcan=False,
                        pcan_strength=0.95,
                        pcan_offset=80,
                        gain_bits=21,
                        enable_log=True,
                        scale_shift=6,
                        left_context=0,
                        right_context=0,
                        frame_stride=1,
                        zero_padding=False,
                        out_scale=1,
                        out_type=_dtypes.uint16,
                        name=None):
    r"""Audio Microfrontend Op.

  This Op converts a sequence of audio data into one or more
  feature vectors containing filterbanks of the input. The
  conversion process uses a lightweight library to perform:

  1. A slicing window function
  2. Short-time FFTs
  3. Filterbank calculations
  4. Noise reduction
  5. PCAN Auto Gain Control
  6. Logarithmic scaling

  Arguments
    audio: 1D Tensor, int16 audio data in temporal ordering.
    sample_rate: Integer, the sample rate of the audio in Hz.
    window_size: Integer, length of desired time frames in ms.
    window_step: Integer, length of step size for the next frame in ms.
    num_channels: Integer, the number of filterbank channels to use.
    upper_band_limit: Float, the highest frequency included in the filterbanks.
    lower_band_limit: Float, the lowest frequency included in the filterbanks.
    smoothing_bits: Int, scale up signal by 2^(smoothing_bits) before reduction.
    even_smoothing: Float, smoothing coefficient for even-numbered channels.
    odd_smoothing: Float, smoothing coefficient for odd-numbered channels.
    min_signal_remaining: Float, fraction of signal to preserve in smoothing.
    enable_pcan: Bool, enable PCAN auto gain control.
    pcan_strength: Float, gain normalization exponent.
    pcan_offset: Float, positive value added in the normalization denominator.
    gain_bits: Int, number of fractional bits in the gain.
    enable_log: Bool, enable logarithmic scaling of filterbanks.
    scale_shift: Integer, scale filterbanks by 2^(scale_shift).
    left_context: Integer, number of preceding frames to attach to each frame.
    right_context: Integer, number of preceding frames to attach to each frame.
    frame_stride: Integer, M frames to skip over, where output[n] = frame[n*M].
    zero_padding: Bool, if left/right context is out-of-bounds, attach frame of
                  zeroes. Otherwise, frame[0] or frame[size-1] will be copied.
    out_scale: Integer, divide all filterbanks by this number.
    out_type: DType, type of the output Tensor, defaults to UINT16.

  Returns
    filterbanks: 2D Tensor, each row is a time frame, each column is a channel.

  Args:
    audio: A `Tensor` of type `int16`.
    sample_rate: An optional `int`. Defaults to `16000`.
    window_size: An optional `int`. Defaults to `25`.
    window_step: An optional `int`. Defaults to `10`.
    num_channels: An optional `int`. Defaults to `32`.
    upper_band_limit: An optional `float`. Defaults to `7500`.
    lower_band_limit: An optional `float`. Defaults to `125`.
    smoothing_bits: An optional `int`. Defaults to `10`.
    even_smoothing: An optional `float`. Defaults to `0.025`.
    odd_smoothing: An optional `float`. Defaults to `0.06`.
    min_signal_remaining: An optional `float`. Defaults to `0.05`.
    enable_pcan: An optional `bool`. Defaults to `False`.
    pcan_strength: An optional `float`. Defaults to `0.95`.
    pcan_offset: An optional `float`. Defaults to `80`.
    gain_bits: An optional `int`. Defaults to `21`.
    enable_log: An optional `bool`. Defaults to `True`.
    scale_shift: An optional `int`. Defaults to `6`.
    left_context: An optional `int`. Defaults to `0`.
    right_context: An optional `int`. Defaults to `0`.
    frame_stride: An optional `int`. Defaults to `1`.
    zero_padding: An optional `bool`. Defaults to `False`.
    out_scale: An optional `int`. Defaults to `1`.
    out_type: An optional `tf.DType` from: `tf.uint16, tf.float32`. Defaults to `tf.uint16`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `out_type`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "AudioMicrofrontend", name, audio, "sample_rate",
                sample_rate, "window_size", window_size, "window_step",
                window_step, "num_channels", num_channels, "upper_band_limit",
                upper_band_limit, "lower_band_limit", lower_band_limit,
                "smoothing_bits", smoothing_bits, "even_smoothing",
                even_smoothing, "odd_smoothing", odd_smoothing,
                "min_signal_remaining", min_signal_remaining, "enable_pcan",
                enable_pcan, "pcan_strength", pcan_strength, "pcan_offset",
                pcan_offset, "gain_bits", gain_bits, "enable_log", enable_log,
                "scale_shift", scale_shift, "left_context", left_context,
                "right_context", right_context, "frame_stride", frame_stride,
                "zero_padding", zero_padding, "out_scale", out_scale,
                "out_type", out_type)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return audio_microfrontend_eager_fallback(
                audio,
                sample_rate=sample_rate,
                window_size=window_size,
                window_step=window_step,
                num_channels=num_channels,
                upper_band_limit=upper_band_limit,
                lower_band_limit=lower_band_limit,
                smoothing_bits=smoothing_bits,
                even_smoothing=even_smoothing,
                odd_smoothing=odd_smoothing,
                min_signal_remaining=min_signal_remaining,
                enable_pcan=enable_pcan,
                pcan_strength=pcan_strength,
                pcan_offset=pcan_offset,
                gain_bits=gain_bits,
                enable_log=enable_log,
                scale_shift=scale_shift,
                left_context=left_context,
                right_context=right_context,
                frame_stride=frame_stride,
                zero_padding=zero_padding,
                out_scale=out_scale,
                out_type=out_type,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
        except (TypeError, ValueError):
            result = _dispatch.dispatch(
                audio_microfrontend, (),
                dict(audio=audio,
                     sample_rate=sample_rate,
                     window_size=window_size,
                     window_step=window_step,
                     num_channels=num_channels,
                     upper_band_limit=upper_band_limit,
                     lower_band_limit=lower_band_limit,
                     smoothing_bits=smoothing_bits,
                     even_smoothing=even_smoothing,
                     odd_smoothing=odd_smoothing,
                     min_signal_remaining=min_signal_remaining,
                     enable_pcan=enable_pcan,
                     pcan_strength=pcan_strength,
                     pcan_offset=pcan_offset,
                     gain_bits=gain_bits,
                     enable_log=enable_log,
                     scale_shift=scale_shift,
                     left_context=left_context,
                     right_context=right_context,
                     frame_stride=frame_stride,
                     zero_padding=zero_padding,
                     out_scale=out_scale,
                     out_type=out_type,
                     name=name))
            if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                return result
            raise
    # Add nodes to the TensorFlow graph.
    if sample_rate is None:
        sample_rate = 16000
    sample_rate = _execute.make_int(sample_rate, "sample_rate")
    if window_size is None:
        window_size = 25
    window_size = _execute.make_int(window_size, "window_size")
    if window_step is None:
        window_step = 10
    window_step = _execute.make_int(window_step, "window_step")
    if num_channels is None:
        num_channels = 32
    num_channels = _execute.make_int(num_channels, "num_channels")
    if upper_band_limit is None:
        upper_band_limit = 7500
    upper_band_limit = _execute.make_float(upper_band_limit,
                                           "upper_band_limit")
    if lower_band_limit is None:
        lower_band_limit = 125
    lower_band_limit = _execute.make_float(lower_band_limit,
                                           "lower_band_limit")
    if smoothing_bits is None:
        smoothing_bits = 10
    smoothing_bits = _execute.make_int(smoothing_bits, "smoothing_bits")
    if even_smoothing is None:
        even_smoothing = 0.025
    even_smoothing = _execute.make_float(even_smoothing, "even_smoothing")
    if odd_smoothing is None:
        odd_smoothing = 0.06
    odd_smoothing = _execute.make_float(odd_smoothing, "odd_smoothing")
    if min_signal_remaining is None:
        min_signal_remaining = 0.05
    min_signal_remaining = _execute.make_float(min_signal_remaining,
                                               "min_signal_remaining")
    if enable_pcan is None:
        enable_pcan = False
    enable_pcan = _execute.make_bool(enable_pcan, "enable_pcan")
    if pcan_strength is None:
        pcan_strength = 0.95
    pcan_strength = _execute.make_float(pcan_strength, "pcan_strength")
    if pcan_offset is None:
        pcan_offset = 80
    pcan_offset = _execute.make_float(pcan_offset, "pcan_offset")
    if gain_bits is None:
        gain_bits = 21
    gain_bits = _execute.make_int(gain_bits, "gain_bits")
    if enable_log is None:
        enable_log = True
    enable_log = _execute.make_bool(enable_log, "enable_log")
    if scale_shift is None:
        scale_shift = 6
    scale_shift = _execute.make_int(scale_shift, "scale_shift")
    if left_context is None:
        left_context = 0
    left_context = _execute.make_int(left_context, "left_context")
    if right_context is None:
        right_context = 0
    right_context = _execute.make_int(right_context, "right_context")
    if frame_stride is None:
        frame_stride = 1
    frame_stride = _execute.make_int(frame_stride, "frame_stride")
    if zero_padding is None:
        zero_padding = False
    zero_padding = _execute.make_bool(zero_padding, "zero_padding")
    if out_scale is None:
        out_scale = 1
    out_scale = _execute.make_int(out_scale, "out_scale")
    if out_type is None:
        out_type = _dtypes.uint16
    out_type = _execute.make_type(out_type, "out_type")
    try:
        _, _, _op, _outputs = _op_def_library._apply_op_helper(
            "AudioMicrofrontend",
            audio=audio,
            sample_rate=sample_rate,
            window_size=window_size,
            window_step=window_step,
            num_channels=num_channels,
            upper_band_limit=upper_band_limit,
            lower_band_limit=lower_band_limit,
            smoothing_bits=smoothing_bits,
            even_smoothing=even_smoothing,
            odd_smoothing=odd_smoothing,
            min_signal_remaining=min_signal_remaining,
            enable_pcan=enable_pcan,
            pcan_strength=pcan_strength,
            pcan_offset=pcan_offset,
            gain_bits=gain_bits,
            enable_log=enable_log,
            scale_shift=scale_shift,
            left_context=left_context,
            right_context=right_context,
            frame_stride=frame_stride,
            zero_padding=zero_padding,
            out_scale=out_scale,
            out_type=out_type,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(
            audio_microfrontend, (),
            dict(audio=audio,
                 sample_rate=sample_rate,
                 window_size=window_size,
                 window_step=window_step,
                 num_channels=num_channels,
                 upper_band_limit=upper_band_limit,
                 lower_band_limit=lower_band_limit,
                 smoothing_bits=smoothing_bits,
                 even_smoothing=even_smoothing,
                 odd_smoothing=odd_smoothing,
                 min_signal_remaining=min_signal_remaining,
                 enable_pcan=enable_pcan,
                 pcan_strength=pcan_strength,
                 pcan_offset=pcan_offset,
                 gain_bits=gain_bits,
                 enable_log=enable_log,
                 scale_shift=scale_shift,
                 left_context=left_context,
                 right_context=right_context,
                 frame_stride=frame_stride,
                 zero_padding=zero_padding,
                 out_scale=out_scale,
                 out_type=out_type,
                 name=name))
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("sample_rate",
                  _op._get_attr_int("sample_rate"), "window_size",
                  _op._get_attr_int("window_size"), "window_step",
                  _op._get_attr_int("window_step"), "num_channels",
                  _op._get_attr_int("num_channels"), "upper_band_limit",
                  _op.get_attr("upper_band_limit"), "lower_band_limit",
                  _op.get_attr("lower_band_limit"), "smoothing_bits",
                  _op._get_attr_int("smoothing_bits"), "even_smoothing",
                  _op.get_attr("even_smoothing"), "odd_smoothing",
                  _op.get_attr("odd_smoothing"), "min_signal_remaining",
                  _op.get_attr("min_signal_remaining"), "enable_pcan",
                  _op._get_attr_bool("enable_pcan"), "pcan_strength",
                  _op.get_attr("pcan_strength"), "pcan_offset",
                  _op.get_attr("pcan_offset"), "gain_bits",
                  _op._get_attr_int("gain_bits"), "enable_log",
                  _op._get_attr_bool("enable_log"), "scale_shift",
                  _op._get_attr_int("scale_shift"), "left_context",
                  _op._get_attr_int("left_context"), "right_context",
                  _op._get_attr_int("right_context"), "frame_stride",
                  _op._get_attr_int("frame_stride"), "zero_padding",
                  _op._get_attr_bool("zero_padding"), "out_scale",
                  _op._get_attr_int("out_scale"), "out_type",
                  _op._get_attr_type("out_type"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("AudioMicrofrontend", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result
Beispiel #10
0
def trt_engine_op(in_tensor,
                  serialized_segment,
                  OutT,
                  workspace_size_bytes,
                  precision_mode,
                  segment_func="",
                  input_shapes=[],
                  max_cached_engines_count=1,
                  calibration_data="",
                  use_calibration=True,
                  segment_funcdef_name="",
                  cached_engine_batches=[],
                  fixed_input_size=True,
                  output_shapes=[],
                  static_engine=True,
                  name=None):
    r"""TODO: add doc.

  Args:
    in_tensor: A list of `Tensor` objects with types from: `int8`, `half`, `float32`, `int32`.
    serialized_segment: A `string`.
    OutT: A list of `tf.DTypes` from: `tf.int8, tf.half, tf.float32, tf.int32` that has length `>= 1`.
    workspace_size_bytes: An `int`.
    precision_mode: A `string` from: `"FP32", "FP16", "INT8"`.
    segment_func: An optional function decorated with @Defun. Defaults to `""`.
    input_shapes: An optional list of shapes (each a `tf.TensorShape` or list of `ints`). Defaults to `[]`.
    max_cached_engines_count: An optional `int`. Defaults to `1`.
    calibration_data: An optional `string`. Defaults to `""`.
    use_calibration: An optional `bool`. Defaults to `True`.
    segment_funcdef_name: An optional `string`. Defaults to `""`.
    cached_engine_batches: An optional list of `ints`. Defaults to `[]`.
    fixed_input_size: An optional `bool`. Defaults to `True`.
    output_shapes: An optional list of shapes (each a `tf.TensorShape` or list of `ints`). Defaults to `[]`.
    static_engine: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `OutT`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "TRTEngineOp", name,
                tld.op_callbacks, in_tensor, "serialized_segment",
                serialized_segment, "segment_func", segment_func, "OutT", OutT,
                "input_shapes", input_shapes, "max_cached_engines_count",
                max_cached_engines_count, "workspace_size_bytes",
                workspace_size_bytes, "precision_mode", precision_mode,
                "calibration_data", calibration_data, "use_calibration",
                use_calibration, "segment_funcdef_name", segment_funcdef_name,
                "cached_engine_batches", cached_engine_batches,
                "fixed_input_size", fixed_input_size, "output_shapes",
                output_shapes, "static_engine", static_engine)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return trt_engine_op_eager_fallback(
                in_tensor,
                serialized_segment=serialized_segment,
                segment_func=segment_func,
                OutT=OutT,
                input_shapes=input_shapes,
                max_cached_engines_count=max_cached_engines_count,
                workspace_size_bytes=workspace_size_bytes,
                precision_mode=precision_mode,
                calibration_data=calibration_data,
                use_calibration=use_calibration,
                segment_funcdef_name=segment_funcdef_name,
                cached_engine_batches=cached_engine_batches,
                fixed_input_size=fixed_input_size,
                output_shapes=output_shapes,
                static_engine=static_engine,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
        except (TypeError, ValueError):
            result = _dispatch.dispatch(
                trt_engine_op, (),
                dict(in_tensor=in_tensor,
                     serialized_segment=serialized_segment,
                     OutT=OutT,
                     workspace_size_bytes=workspace_size_bytes,
                     precision_mode=precision_mode,
                     segment_func=segment_func,
                     input_shapes=input_shapes,
                     max_cached_engines_count=max_cached_engines_count,
                     calibration_data=calibration_data,
                     use_calibration=use_calibration,
                     segment_funcdef_name=segment_funcdef_name,
                     cached_engine_batches=cached_engine_batches,
                     fixed_input_size=fixed_input_size,
                     output_shapes=output_shapes,
                     static_engine=static_engine,
                     name=name))
            if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                return result
            raise
    # Add nodes to the TensorFlow graph.
    serialized_segment = _execute.make_str(serialized_segment,
                                           "serialized_segment")
    if not isinstance(OutT, (list, tuple)):
        raise TypeError("Expected list for 'OutT' argument to "
                        "'trt_engine_op' Op, not %r." % OutT)
    OutT = [_execute.make_type(_t, "OutT") for _t in OutT]
    workspace_size_bytes = _execute.make_int(workspace_size_bytes,
                                             "workspace_size_bytes")
    precision_mode = _execute.make_str(precision_mode, "precision_mode")
    if segment_func is None:
        segment_func = ""
    if input_shapes is None:
        input_shapes = []
    if not isinstance(input_shapes, (list, tuple)):
        raise TypeError("Expected list for 'input_shapes' argument to "
                        "'trt_engine_op' Op, not %r." % input_shapes)
    input_shapes = [
        _execute.make_shape(_s, "input_shapes") for _s in input_shapes
    ]
    if max_cached_engines_count is None:
        max_cached_engines_count = 1
    max_cached_engines_count = _execute.make_int(max_cached_engines_count,
                                                 "max_cached_engines_count")
    if calibration_data is None:
        calibration_data = ""
    calibration_data = _execute.make_str(calibration_data, "calibration_data")
    if use_calibration is None:
        use_calibration = True
    use_calibration = _execute.make_bool(use_calibration, "use_calibration")
    if segment_funcdef_name is None:
        segment_funcdef_name = ""
    segment_funcdef_name = _execute.make_str(segment_funcdef_name,
                                             "segment_funcdef_name")
    if cached_engine_batches is None:
        cached_engine_batches = []
    if not isinstance(cached_engine_batches, (list, tuple)):
        raise TypeError(
            "Expected list for 'cached_engine_batches' argument to "
            "'trt_engine_op' Op, not %r." % cached_engine_batches)
    cached_engine_batches = [
        _execute.make_int(_i, "cached_engine_batches")
        for _i in cached_engine_batches
    ]
    if fixed_input_size is None:
        fixed_input_size = True
    fixed_input_size = _execute.make_bool(fixed_input_size, "fixed_input_size")
    if output_shapes is None:
        output_shapes = []
    if not isinstance(output_shapes, (list, tuple)):
        raise TypeError("Expected list for 'output_shapes' argument to "
                        "'trt_engine_op' Op, not %r." % output_shapes)
    output_shapes = [
        _execute.make_shape(_s, "output_shapes") for _s in output_shapes
    ]
    if static_engine is None:
        static_engine = True
    static_engine = _execute.make_bool(static_engine, "static_engine")
    try:
        _, _, _op, _outputs = _op_def_library._apply_op_helper(
            "TRTEngineOp",
            in_tensor=in_tensor,
            serialized_segment=serialized_segment,
            OutT=OutT,
            workspace_size_bytes=workspace_size_bytes,
            precision_mode=precision_mode,
            segment_func=segment_func,
            input_shapes=input_shapes,
            max_cached_engines_count=max_cached_engines_count,
            calibration_data=calibration_data,
            use_calibration=use_calibration,
            segment_funcdef_name=segment_funcdef_name,
            cached_engine_batches=cached_engine_batches,
            fixed_input_size=fixed_input_size,
            output_shapes=output_shapes,
            static_engine=static_engine,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(
            trt_engine_op, (),
            dict(in_tensor=in_tensor,
                 serialized_segment=serialized_segment,
                 OutT=OutT,
                 workspace_size_bytes=workspace_size_bytes,
                 precision_mode=precision_mode,
                 segment_func=segment_func,
                 input_shapes=input_shapes,
                 max_cached_engines_count=max_cached_engines_count,
                 calibration_data=calibration_data,
                 use_calibration=use_calibration,
                 segment_funcdef_name=segment_funcdef_name,
                 cached_engine_batches=cached_engine_batches,
                 fixed_input_size=fixed_input_size,
                 output_shapes=output_shapes,
                 static_engine=static_engine,
                 name=name))
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("serialized_segment", _op.get_attr("serialized_segment"),
                  "segment_func", _op.get_attr("segment_func"), "InT",
                  _op.get_attr("InT"), "OutT",
                  _op.get_attr("OutT"), "input_shapes",
                  _op.get_attr("input_shapes"), "max_cached_engines_count",
                  _op._get_attr_int("max_cached_engines_count"),
                  "workspace_size_bytes",
                  _op._get_attr_int("workspace_size_bytes"), "precision_mode",
                  _op.get_attr("precision_mode"), "calibration_data",
                  _op.get_attr("calibration_data"), "use_calibration",
                  _op._get_attr_bool("use_calibration"),
                  "segment_funcdef_name", _op.get_attr("segment_funcdef_name"),
                  "cached_engine_batches",
                  _op.get_attr("cached_engine_batches"), "fixed_input_size",
                  _op._get_attr_bool("fixed_input_size"), "output_shapes",
                  _op.get_attr("output_shapes"), "static_engine",
                  _op._get_attr_bool("static_engine"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("TRTEngineOp", _inputs_flat, _attrs, _result)
    return _result
Beispiel #11
0
def debug_numeric_summary_v2(input,
                             tensor_debug_mode=-1,
                             tensor_id=-1,
                             name=None):
    r"""Debug Numeric Summary V2 Op.

  Computes a numeric summary of the input tensor. The shape of the output
  depends on the tensor_debug_mode attribute.
  This op is used internally by TensorFlow Debugger (tfdbg) v2.

  Args:
    input: A `Tensor`. Input tensor, to be summarized by the op.
    tensor_debug_mode: An optional `int`. Defaults to `-1`.
      Tensor debug mode: the mode in which the input tensor is summarized
        by the op. See the TensorDebugMode enum in
        tensorflow/core/protobuf/debug_event.proto for details.

      Supported values:
        8 (REDUCE_INF_NAN_THREE_SLOTS): Output a float32 tensor of shape
        [3]. The 1st element is -inf if any elements of the input tensor
        is -inf, or zero otherwise. The 2nd element is +inf if any elements
        of the input tensor is +inf, or zero otherwise.  The 3rd element is
        nan if any element of the input tensor is nan, or zero otherwise
    tensor_id: An optional `int`. Defaults to `-1`.
      Optional. An integer identifier for the tensor being summarized by this op.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "DebugNumericSummaryV2",
                name, tld.op_callbacks, input, "tensor_debug_mode",
                tensor_debug_mode, "tensor_id", tensor_id)
            return _result
        except _core._FallbackException:
            try:
                return debug_numeric_summary_v2_eager_fallback(
                    input,
                    tensor_debug_mode=tensor_debug_mode,
                    tensor_id=tensor_id,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    if tensor_debug_mode is None:
        tensor_debug_mode = -1
    tensor_debug_mode = _execute.make_int(tensor_debug_mode,
                                          "tensor_debug_mode")
    if tensor_id is None:
        tensor_id = -1
    tensor_id = _execute.make_int(tensor_id, "tensor_id")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "DebugNumericSummaryV2",
        input=input,
        tensor_debug_mode=tensor_debug_mode,
        tensor_id=tensor_id,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("T", _op._get_attr_type("T"), "tensor_debug_mode",
                  _op._get_attr_int("tensor_debug_mode"), "tensor_id",
                  _op._get_attr_int("tensor_id"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("DebugNumericSummaryV2", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result
Beispiel #12
0
def serialize_trt_resource(resource_name,
                           filename,
                           delete_resource=False,
                           name=None):
    r"""TODO: add doc.

  Args:
    resource_name: A `Tensor` of type `string`.
    filename: A `Tensor` of type `string`.
    delete_resource: An optional `bool`. Defaults to `False`.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "SerializeTRTResource",
                name, tld.op_callbacks, resource_name, filename,
                "delete_resource", delete_resource)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return serialize_trt_resource_eager_fallback(
                resource_name,
                filename,
                delete_resource=delete_resource,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
        except (TypeError, ValueError):
            result = _dispatch.dispatch(
                serialize_trt_resource, (),
                dict(resource_name=resource_name,
                     filename=filename,
                     delete_resource=delete_resource,
                     name=name))
            if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                return result
            raise
    # Add nodes to the TensorFlow graph.
    if delete_resource is None:
        delete_resource = False
    delete_resource = _execute.make_bool(delete_resource, "delete_resource")
    try:
        _, _, _op, _outputs = _op_def_library._apply_op_helper(
            "SerializeTRTResource",
            resource_name=resource_name,
            filename=filename,
            delete_resource=delete_resource,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(
            serialize_trt_resource, (),
            dict(resource_name=resource_name,
                 filename=filename,
                 delete_resource=delete_resource,
                 name=name))
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    return _op
Beispiel #13
0
def nccl_all_reduce(input, reduction, num_devices, shared_name, name=None):
  r"""Outputs a tensor containing the reduction across all input tensors.

  Outputs a tensor containing the reduction across all input tensors passed to ops
  within the same `shared_name.

  The graph should be constructed so if one op runs with shared_name value `c`,
  then `num_devices` ops will run with shared_name value `c`.  Failure to do so
  will cause the graph execution to fail to complete.

  input: the input to the reduction
  data: the value of the reduction across all `num_devices` devices.
  reduction: the reduction operation to perform.
  num_devices: The number of devices participating in this reduction.
  shared_name: Identifier that shared between ops of the same reduction.

  Args:
    input: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `int32`, `int64`.
    reduction: A `string` from: `"min", "max", "prod", "sum"`.
    num_devices: An `int`.
    shared_name: A `string`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "NcclAllReduce", name, input, "reduction", reduction,
        "num_devices", num_devices, "shared_name", shared_name)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return nccl_all_reduce_eager_fallback(
          input, reduction=reduction, num_devices=num_devices,
          shared_name=shared_name, name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  reduction = _execute.make_str(reduction, "reduction")
  num_devices = _execute.make_int(num_devices, "num_devices")
  shared_name = _execute.make_str(shared_name, "shared_name")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "NcclAllReduce", input=input, reduction=reduction,
                         num_devices=num_devices, shared_name=shared_name,
                         name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("reduction", _op.get_attr("reduction"), "T",
              _op._get_attr_type("T"), "num_devices",
              _op._get_attr_int("num_devices"), "shared_name",
              _op.get_attr("shared_name"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "NcclAllReduce", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
Beispiel #14
0
def send(tensor,
         tensor_name,
         send_device,
         send_device_incarnation,
         recv_device,
         client_terminated=False,
         name=None):
    r"""Sends the named tensor from send_device to recv_device.

  Args:
    tensor: A `Tensor`. The tensor to send.
    tensor_name: A `string`. The name of the tensor to send.
    send_device: A `string`. The name of the device sending the tensor.
    send_device_incarnation: An `int`. The current incarnation of send_device.
    recv_device: A `string`. The name of the device receiving the tensor.
    client_terminated: An optional `bool`. Defaults to `False`.
      If set to true, this indicates that the node was added
      to the graph as a result of a client-side feed or fetch of Tensor data,
      in which case the corresponding send or recv is expected to be managed
      locally by the caller.
    name: A name for the operation (optional).

  Returns:
    The created Operation.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "Send", name,
                tld.op_callbacks, tensor, "tensor_name", tensor_name,
                "send_device", send_device, "send_device_incarnation",
                send_device_incarnation, "recv_device", recv_device,
                "client_terminated", client_terminated)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return send_eager_fallback(
                tensor,
                tensor_name=tensor_name,
                send_device=send_device,
                send_device_incarnation=send_device_incarnation,
                recv_device=recv_device,
                client_terminated=client_terminated,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    tensor_name = _execute.make_str(tensor_name, "tensor_name")
    send_device = _execute.make_str(send_device, "send_device")
    send_device_incarnation = _execute.make_int(send_device_incarnation,
                                                "send_device_incarnation")
    recv_device = _execute.make_str(recv_device, "recv_device")
    if client_terminated is None:
        client_terminated = False
    client_terminated = _execute.make_bool(client_terminated,
                                           "client_terminated")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "Send",
        tensor=tensor,
        tensor_name=tensor_name,
        send_device=send_device,
        send_device_incarnation=send_device_incarnation,
        recv_device=recv_device,
        client_terminated=client_terminated,
        name=name)
    return _op
Beispiel #15
0
def copy(input, tensor_name="", debug_ops_spec=[], name=None):
  r"""Copy a tensor from CPU-to-CPU or GPU-to-GPU.

  Performs CPU-to-CPU or GPU-to-GPU deep-copying of tensor, depending on the
  device on which the tensor is allocated.
  N.B.: If the all downstream attached debug ops are disabled given the current
  gRPC gating status, the output will simply forward the input tensor without
  deep-copying. See the documentation of Debug* ops for more details.

  Unlike the CopyHost Op, this op does not have HostMemory constraint on its
  input or output.

  Args:
    input: A `Tensor`. Input tensor.
    tensor_name: An optional `string`. Defaults to `""`.
      The name of the input tensor.
    debug_ops_spec: An optional list of `strings`. Defaults to `[]`.
      A list of debug op spec (op, url, gated_grpc) for attached debug
      ops. Each element of the list has the format
      <debug_op>;<grpc_url>;<gated_grpc>, wherein gated_grpc is boolean represented
      as 0/1. E.g., "DebugIdentity;grpc://foo:3333;1",
      "DebugIdentity;file:///tmp/tfdbg_1;0".
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "Copy", name, input, "tensor_name", tensor_name,
        "debug_ops_spec", debug_ops_spec)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return copy_eager_fallback(
          input, tensor_name=tensor_name, debug_ops_spec=debug_ops_spec,
          name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  if tensor_name is None:
    tensor_name = ""
  tensor_name = _execute.make_str(tensor_name, "tensor_name")
  if debug_ops_spec is None:
    debug_ops_spec = []
  if not isinstance(debug_ops_spec, (list, tuple)):
    raise TypeError(
        "Expected list for 'debug_ops_spec' argument to "
        "'copy' Op, not %r." % debug_ops_spec)
  debug_ops_spec = [_execute.make_str(_s, "debug_ops_spec") for _s in debug_ops_spec]
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "Copy", input=input, tensor_name=tensor_name,
                debug_ops_spec=debug_ops_spec, name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("T", _op._get_attr_type("T"), "tensor_name",
              _op.get_attr("tensor_name"), "debug_ops_spec",
              _op.get_attr("debug_ops_spec"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "Copy", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
def sparse_to_sparse_set_operation(set1_indices, set1_values, set1_shape, set2_indices, set2_values, set2_shape, set_operation, validate_indices=True, name=None):
  r"""Applies set operation along last dimension of 2 `SparseTensor` inputs.

  See SetOperationOp::SetOperationFromContext for values of `set_operation`.

  If `validate_indices` is `True`, `SparseToSparseSetOperation` validates the
  order and range of `set1` and `set2` indices.

  Input `set1` is a `SparseTensor` represented by `set1_indices`, `set1_values`,
  and `set1_shape`. For `set1` ranked `n`, 1st `n-1` dimensions must be the same
  as `set2`. Dimension `n` contains values in a set, duplicates are allowed but
  ignored.

  Input `set2` is a `SparseTensor` represented by `set2_indices`, `set2_values`,
  and `set2_shape`. For `set2` ranked `n`, 1st `n-1` dimensions must be the same
  as `set1`. Dimension `n` contains values in a set, duplicates are allowed but
  ignored.

  If `validate_indices` is `True`, this op validates the order and range of `set1`
  and `set2` indices.

  Output `result` is a `SparseTensor` represented by `result_indices`,
  `result_values`, and `result_shape`. For `set1` and `set2` ranked `n`, this
  has rank `n` and the same 1st `n-1` dimensions as `set1` and `set2`. The `nth`
  dimension contains the result of `set_operation` applied to the corresponding
  `[0...n-1]` dimension of `set`.

  Args:
    set1_indices: A `Tensor` of type `int64`.
      2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
      order.
    set1_values: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
      1D `Tensor`, values of a `SparseTensor`. Must be in row-major
      order.
    set1_shape: A `Tensor` of type `int64`.
      1D `Tensor`, shape of a `SparseTensor`. `set1_shape[0...n-1]` must
      be the same as `set2_shape[0...n-1]`, `set1_shape[n]` is the
      max set size across `0...n-1` dimensions.
    set2_indices: A `Tensor` of type `int64`.
      2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
      order.
    set2_values: A `Tensor`. Must have the same type as `set1_values`.
      1D `Tensor`, values of a `SparseTensor`. Must be in row-major
      order.
    set2_shape: A `Tensor` of type `int64`.
      1D `Tensor`, shape of a `SparseTensor`. `set2_shape[0...n-1]` must
      be the same as `set1_shape[0...n-1]`, `set2_shape[n]` is the
      max set size across `0...n-1` dimensions.
    set_operation: A `string`.
    validate_indices: An optional `bool`. Defaults to `True`.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (result_indices, result_values, result_shape).

    result_indices: A `Tensor` of type `int64`.
    result_values: A `Tensor`. Has the same type as `set1_values`.
    result_shape: A `Tensor` of type `int64`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx._context_handle, tld.device_name, "SparseToSparseSetOperation",
        name, tld.op_callbacks, set1_indices, set1_values, set1_shape,
        set2_indices, set2_values, set2_shape, "set_operation", set_operation,
        "validate_indices", validate_indices)
      _result = _SparseToSparseSetOperationOutput._make(_result)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return sparse_to_sparse_set_operation_eager_fallback(
          set1_indices, set1_values, set1_shape, set2_indices, set2_values,
          set2_shape, set_operation=set_operation,
          validate_indices=validate_indices, name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  set_operation = _execute.make_str(set_operation, "set_operation")
  if validate_indices is None:
    validate_indices = True
  validate_indices = _execute.make_bool(validate_indices, "validate_indices")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "SparseToSparseSetOperation", set1_indices=set1_indices,
                                      set1_values=set1_values,
                                      set1_shape=set1_shape,
                                      set2_indices=set2_indices,
                                      set2_values=set2_values,
                                      set2_shape=set2_shape,
                                      set_operation=set_operation,
                                      validate_indices=validate_indices,
                                      name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("set_operation", _op.get_attr("set_operation"),
              "validate_indices", _op._get_attr_bool("validate_indices"), "T",
              _op._get_attr_type("T"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "SparseToSparseSetOperation", _inputs_flat, _attrs, _result)
  _result = _SparseToSparseSetOperationOutput._make(_result)
  return _result
Beispiel #17
0
def debug_identity_v2(input, tfdbg_context_id="", op_name="", output_slot=-1, tensor_debug_mode=-1, debug_urls=[], circular_buffer_size=1000, tfdbg_run_id="", name=None):
  r"""Debug Identity V2 Op.

  Provides an identity mapping from input to output, while writing the content of
  the input tensor by calling DebugEventsWriter.

  The semantics of the input tensor depends on tensor_debug_mode. In typical
  usage, the input tensor comes directly from the user computation only when
  graph_debug_mode is FULL_TENSOR (see protobuf/debug_event.proto for a
  list of all the possible values of graph_debug_mode). For the other debug modes,
  the input tensor should be produced by an additional op or subgraph that
  computes summary information about one or more tensors.

  Args:
    input: A `Tensor`. Input tensor, non-Reference type
    tfdbg_context_id: An optional `string`. Defaults to `""`.
      A tfdbg-generated ID for the context that the op belongs to,
        e.g., a concrete compiled tf.function.
    op_name: An optional `string`. Defaults to `""`.
      Optional. Name of the op that the debug op is concerned with.
        Used only for single-tensor trace.
    output_slot: An optional `int`. Defaults to `-1`.
      Optional. Output slot index of the tensor that the debug op
        is concerned with. Used only for single-tensor trace.
    tensor_debug_mode: An optional `int`. Defaults to `-1`.
      TensorDebugMode enum value. See debug_event.proto for details.
    debug_urls: An optional list of `strings`. Defaults to `[]`.
      List of URLs to debug targets, e.g., file:///foo/tfdbg_dump.
    circular_buffer_size: An optional `int`. Defaults to `1000`.
    tfdbg_run_id: An optional `string`. Defaults to `""`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "DebugIdentityV2", name, input, "tfdbg_context_id",
        tfdbg_context_id, "op_name", op_name, "output_slot", output_slot,
        "tensor_debug_mode", tensor_debug_mode, "debug_urls", debug_urls,
        "circular_buffer_size", circular_buffer_size, "tfdbg_run_id",
        tfdbg_run_id)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return debug_identity_v2_eager_fallback(
          input, tfdbg_context_id=tfdbg_context_id, op_name=op_name,
          output_slot=output_slot, tensor_debug_mode=tensor_debug_mode,
          debug_urls=debug_urls, circular_buffer_size=circular_buffer_size,
          tfdbg_run_id=tfdbg_run_id, name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  if tfdbg_context_id is None:
    tfdbg_context_id = ""
  tfdbg_context_id = _execute.make_str(tfdbg_context_id, "tfdbg_context_id")
  if op_name is None:
    op_name = ""
  op_name = _execute.make_str(op_name, "op_name")
  if output_slot is None:
    output_slot = -1
  output_slot = _execute.make_int(output_slot, "output_slot")
  if tensor_debug_mode is None:
    tensor_debug_mode = -1
  tensor_debug_mode = _execute.make_int(tensor_debug_mode, "tensor_debug_mode")
  if debug_urls is None:
    debug_urls = []
  if not isinstance(debug_urls, (list, tuple)):
    raise TypeError(
        "Expected list for 'debug_urls' argument to "
        "'debug_identity_v2' Op, not %r." % debug_urls)
  debug_urls = [_execute.make_str(_s, "debug_urls") for _s in debug_urls]
  if circular_buffer_size is None:
    circular_buffer_size = 1000
  circular_buffer_size = _execute.make_int(circular_buffer_size, "circular_buffer_size")
  if tfdbg_run_id is None:
    tfdbg_run_id = ""
  tfdbg_run_id = _execute.make_str(tfdbg_run_id, "tfdbg_run_id")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "DebugIdentityV2", input=input, tfdbg_context_id=tfdbg_context_id,
                           op_name=op_name, output_slot=output_slot,
                           tensor_debug_mode=tensor_debug_mode,
                           debug_urls=debug_urls,
                           circular_buffer_size=circular_buffer_size,
                           tfdbg_run_id=tfdbg_run_id, name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("T", _op._get_attr_type("T"), "tfdbg_context_id",
              _op.get_attr("tfdbg_context_id"), "op_name",
              _op.get_attr("op_name"), "output_slot",
              _op._get_attr_int("output_slot"), "tensor_debug_mode",
              _op._get_attr_int("tensor_debug_mode"), "debug_urls",
              _op.get_attr("debug_urls"), "circular_buffer_size",
              _op._get_attr_int("circular_buffer_size"), "tfdbg_run_id",
              _op.get_attr("tfdbg_run_id"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "DebugIdentityV2", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
Beispiel #18
0
def recv(tensor_type,
         tensor_name,
         send_device,
         send_device_incarnation,
         recv_device,
         client_terminated=False,
         name=None):
    r"""Receives the named tensor from send_device on recv_device.

  Args:
    tensor_type: A `tf.DType`.
    tensor_name: A `string`. The name of the tensor to receive.
    send_device: A `string`. The name of the device sending the tensor.
    send_device_incarnation: An `int`. The current incarnation of send_device.
    recv_device: A `string`. The name of the device receiving the tensor.
    client_terminated: An optional `bool`. Defaults to `False`.
      If set to true, this indicates that the node was added
      to the graph as a result of a client-side feed or fetch of Tensor data,
      in which case the corresponding send or recv is expected to be managed
      locally by the caller.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `tensor_type`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "Recv", name,
                tld.op_callbacks, "tensor_type", tensor_type, "tensor_name",
                tensor_name, "send_device", send_device,
                "send_device_incarnation", send_device_incarnation,
                "recv_device", recv_device, "client_terminated",
                client_terminated)
            return _result
        except _core._FallbackException:
            try:
                return recv_eager_fallback(
                    tensor_type=tensor_type,
                    tensor_name=tensor_name,
                    send_device=send_device,
                    send_device_incarnation=send_device_incarnation,
                    recv_device=recv_device,
                    client_terminated=client_terminated,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    tensor_type = _execute.make_type(tensor_type, "tensor_type")
    tensor_name = _execute.make_str(tensor_name, "tensor_name")
    send_device = _execute.make_str(send_device, "send_device")
    send_device_incarnation = _execute.make_int(send_device_incarnation,
                                                "send_device_incarnation")
    recv_device = _execute.make_str(recv_device, "recv_device")
    if client_terminated is None:
        client_terminated = False
    client_terminated = _execute.make_bool(client_terminated,
                                           "client_terminated")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "Recv",
        tensor_type=tensor_type,
        tensor_name=tensor_name,
        send_device=send_device,
        send_device_incarnation=send_device_incarnation,
        recv_device=recv_device,
        client_terminated=client_terminated,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("tensor_type", _op._get_attr_type("tensor_type"),
                  "tensor_name", _op.get_attr("tensor_name"), "send_device",
                  _op.get_attr("send_device"), "send_device_incarnation",
                  _op._get_attr_int("send_device_incarnation"), "recv_device",
                  _op.get_attr("recv_device"), "client_terminated",
                  _op._get_attr_bool("client_terminated"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("Recv", _inputs_flat, _attrs, _result)
    _result, = _result
    return _result
Beispiel #19
0
def debug_numeric_summary(input, device_name="", tensor_name="", debug_urls=[], lower_bound=float('-inf'), upper_bound=float('inf'), mute_if_healthy=False, gated_grpc=False, name=None):
  r"""Debug Numeric Summary Op.

  Provide a basic summary of numeric value types, range and distribution.

  output: A double tensor of shape [14 + nDimensions], where nDimensions is the
    number of dimensions of the tensor's shape. The elements of output are:
    [0]: is initialized (1.0) or not (0.0).
    [1]: total number of elements
    [2]: NaN element count
    [3]: generalized -inf count: elements <= lower_bound. lower_bound is -inf by
      default.
    [4]: negative element count (excluding -inf), if lower_bound is the default
      -inf. Otherwise, this is the count of elements > lower_bound and < 0.
    [5]: zero element count
    [6]: positive element count (excluding +inf), if upper_bound is the default
      +inf. Otherwise, this is the count of elements < upper_bound and > 0.
    [7]: generalized +inf count, elements >= upper_bound. upper_bound is +inf by
      default.
  Output elements [1:8] are all zero, if the tensor is uninitialized.
    [8]: minimum of all non-inf and non-NaN elements.
         If uninitialized or no such element exists: +inf.
    [9]: maximum of all non-inf and non-NaN elements.
         If uninitialized or no such element exists: -inf.
    [10]: mean of all non-inf and non-NaN elements.
          If uninitialized or no such element exists: NaN.
    [11]: variance of all non-inf and non-NaN elements.
          If uninitialized or no such element exists: NaN.
    [12]: Data type of the tensor encoded as an enum integer. See the DataType
          proto for more details.
    [13]: Number of dimensions of the tensor (ndims).
    [14+]: Sizes of the dimensions.

  Args:
    input: A `Tensor`. Input tensor, non-Reference type.
    device_name: An optional `string`. Defaults to `""`.
    tensor_name: An optional `string`. Defaults to `""`.
      Name of the input tensor.
    debug_urls: An optional list of `strings`. Defaults to `[]`.
      List of URLs to debug targets, e.g.,
        file:///foo/tfdbg_dump, grpc:://localhost:11011.
    lower_bound: An optional `float`. Defaults to `float('-inf')`.
      (float) The lower bound <= which values will be included in the
        generalized -inf count. Default: -inf.
    upper_bound: An optional `float`. Defaults to `float('inf')`.
      (float) The upper bound >= which values will be included in the
        generalized +inf count. Default: +inf.
    mute_if_healthy: An optional `bool`. Defaults to `False`.
      (bool) Do not send data to the debug URLs unless at least one
        of elements [2], [3] and [7] (i.e., the nan count and the generalized -inf and
        inf counts) is non-zero.
    gated_grpc: An optional `bool`. Defaults to `False`.
      Whether this op will be gated. If any of the debug_urls of this
        debug node is of the grpc:// scheme, when the value of this attribute is set
        to True, the data will not actually be sent via the grpc stream unless this
        debug op has been enabled at the debug_url. If all of the debug_urls of this
        debug node are of the grpc:// scheme and the debug op is enabled at none of
        them, the output will be an empty Tensor.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float64`.
  """
  _ctx = _context._context or _context.context()
  tld = _ctx._thread_local_data
  if tld.is_eager:
    try:
      _result = pywrap_tfe.TFE_Py_FastPathExecute(
        _ctx, "DebugNumericSummary", name, input, "device_name", device_name,
        "tensor_name", tensor_name, "debug_urls", debug_urls, "lower_bound",
        lower_bound, "upper_bound", upper_bound, "mute_if_healthy",
        mute_if_healthy, "gated_grpc", gated_grpc)
      return _result
    except _core._NotOkStatusException as e:
      _ops.raise_from_not_ok_status(e, name)
    except _core._FallbackException:
      pass
    try:
      return debug_numeric_summary_eager_fallback(
          input, device_name=device_name, tensor_name=tensor_name,
          debug_urls=debug_urls, lower_bound=lower_bound,
          upper_bound=upper_bound, mute_if_healthy=mute_if_healthy,
          gated_grpc=gated_grpc, name=name, ctx=_ctx)
    except _core._SymbolicException:
      pass  # Add nodes to the TensorFlow graph.
  # Add nodes to the TensorFlow graph.
  if device_name is None:
    device_name = ""
  device_name = _execute.make_str(device_name, "device_name")
  if tensor_name is None:
    tensor_name = ""
  tensor_name = _execute.make_str(tensor_name, "tensor_name")
  if debug_urls is None:
    debug_urls = []
  if not isinstance(debug_urls, (list, tuple)):
    raise TypeError(
        "Expected list for 'debug_urls' argument to "
        "'debug_numeric_summary' Op, not %r." % debug_urls)
  debug_urls = [_execute.make_str(_s, "debug_urls") for _s in debug_urls]
  if lower_bound is None:
    lower_bound = float('-inf')
  lower_bound = _execute.make_float(lower_bound, "lower_bound")
  if upper_bound is None:
    upper_bound = float('inf')
  upper_bound = _execute.make_float(upper_bound, "upper_bound")
  if mute_if_healthy is None:
    mute_if_healthy = False
  mute_if_healthy = _execute.make_bool(mute_if_healthy, "mute_if_healthy")
  if gated_grpc is None:
    gated_grpc = False
  gated_grpc = _execute.make_bool(gated_grpc, "gated_grpc")
  _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "DebugNumericSummary", input=input, device_name=device_name,
                               tensor_name=tensor_name, debug_urls=debug_urls,
                               lower_bound=lower_bound,
                               upper_bound=upper_bound,
                               mute_if_healthy=mute_if_healthy,
                               gated_grpc=gated_grpc, name=name)
  _result = _outputs[:]
  if _execute.must_record_gradient():
    _attrs = ("T", _op._get_attr_type("T"), "device_name",
              _op.get_attr("device_name"), "tensor_name",
              _op.get_attr("tensor_name"), "debug_urls",
              _op.get_attr("debug_urls"), "lower_bound",
              _op.get_attr("lower_bound"), "upper_bound",
              _op.get_attr("upper_bound"), "mute_if_healthy",
              _op._get_attr_bool("mute_if_healthy"), "gated_grpc",
              _op._get_attr_bool("gated_grpc"))
    _inputs_flat = _op.inputs
    _execute.record_gradient(
        "DebugNumericSummary", _inputs_flat, _attrs, _result)
  _result, = _result
  return _result
def stateful_random_binomial(resource,
                             algorithm,
                             shape,
                             counts,
                             probs,
                             dtype=_dtypes.int64,
                             name=None):
    r"""TODO: add doc.

  Args:
    resource: A `Tensor` of type `resource`.
    algorithm: A `Tensor` of type `int64`.
    shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
    counts: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `int32`, `int64`.
    probs: A `Tensor`. Must have the same type as `counts`.
    dtype: An optional `tf.DType` from: `tf.half, tf.float32, tf.float64, tf.int32, tf.int64`. Defaults to `tf.int64`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `dtype`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "StatefulRandomBinomial", name, resource, algorithm,
                shape, counts, probs, "dtype", dtype)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return stateful_random_binomial_eager_fallback(resource,
                                                           algorithm,
                                                           shape,
                                                           counts,
                                                           probs,
                                                           dtype=dtype,
                                                           name=name,
                                                           ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    if dtype is None:
        dtype = _dtypes.int64
    dtype = _execute.make_type(dtype, "dtype")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "StatefulRandomBinomial",
        resource=resource,
        algorithm=algorithm,
        shape=shape,
        counts=counts,
        probs=probs,
        dtype=dtype,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("S", _op._get_attr_type("S"), "T", _op._get_attr_type("T"),
                  "dtype", _op._get_attr_type("dtype"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("StatefulRandomBinomial", _inputs_flat,
                                 _attrs, _result)
    _result, = _result
    return _result
Beispiel #21
0
def xla_launch(constants, args, resources, Tresults, function, name=None):
    r"""XLA Launch Op. For use by the XLA JIT only.

  Args:
    constants: A list of `Tensor` objects.
    args: A list of `Tensor` objects.
    resources: A list of `Tensor` objects with type `resource`.
    Tresults: A list of `tf.DTypes`.
    function: A function decorated with @Defun.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `Tresults`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "XlaLaunch", name, constants, args, resources,
                "Tresults", Tresults, "function", function)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return xla_launch_eager_fallback(constants,
                                             args,
                                             resources,
                                             Tresults=Tresults,
                                             function=function,
                                             name=name,
                                             ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
        except (TypeError, ValueError):
            result = _dispatch.dispatch(
                xla_launch, (),
                dict(constants=constants,
                     args=args,
                     resources=resources,
                     Tresults=Tresults,
                     function=function,
                     name=name))
            if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
                return result
            raise
    # Add nodes to the TensorFlow graph.
    if not isinstance(resources, (list, tuple)):
        raise TypeError("Expected list for 'resources' argument to "
                        "'xla_launch' Op, not %r." % resources)
    _attr_Nresources = len(resources)
    if not isinstance(Tresults, (list, tuple)):
        raise TypeError("Expected list for 'Tresults' argument to "
                        "'xla_launch' Op, not %r." % Tresults)
    Tresults = [_execute.make_type(_t, "Tresults") for _t in Tresults]
    try:
        _, _, _op, _outputs = _op_def_library._apply_op_helper(
            "XlaLaunch",
            constants=constants,
            args=args,
            resources=resources,
            Tresults=Tresults,
            function=function,
            name=name)
    except (TypeError, ValueError):
        result = _dispatch.dispatch(
            xla_launch, (),
            dict(constants=constants,
                 args=args,
                 resources=resources,
                 Tresults=Tresults,
                 function=function,
                 name=name))
        if result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
            return result
        raise
    _result = _outputs[:]
    if not _result:
        return _op
    if _execute.must_record_gradient():
        _attrs = ("Tconstants", _op.get_attr("Tconstants"), "Targs",
                  _op.get_attr("Targs"), "Nresources",
                  _op._get_attr_int("Nresources"), "Tresults",
                  _op.get_attr("Tresults"), "function",
                  _op.get_attr("function"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("XlaLaunch", _inputs_flat, _attrs, _result)
    return _result
def stateful_truncated_normal(resource,
                              algorithm,
                              shape,
                              dtype=_dtypes.float32,
                              name=None):
    r"""Outputs random values from a truncated normal distribution.

  The generated values follow a normal distribution with mean 0 and standard
  deviation 1, except that values whose magnitude is more than 2 standard
  deviations from the mean are dropped and re-picked.

  Args:
    resource: A `Tensor` of type `resource`.
      The handle of the resource variable that stores the state of the RNG.
    algorithm: A `Tensor` of type `int64`. The RNG algorithm.
    shape: A `Tensor`. The shape of the output tensor.
    dtype: An optional `tf.DType`. Defaults to `tf.float32`.
      The type of the output.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `dtype`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "StatefulTruncatedNormal", name, resource, algorithm,
                shape, "dtype", dtype)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return stateful_truncated_normal_eager_fallback(resource,
                                                            algorithm,
                                                            shape,
                                                            dtype=dtype,
                                                            name=name,
                                                            ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    if dtype is None:
        dtype = _dtypes.float32
    dtype = _execute.make_type(dtype, "dtype")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "StatefulTruncatedNormal",
        resource=resource,
        algorithm=algorithm,
        shape=shape,
        dtype=dtype,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("dtype", _op._get_attr_type("dtype"), "shape_dtype",
                  _op._get_attr_type("shape_dtype"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("StatefulTruncatedNormal", _inputs_flat,
                                 _attrs, _result)
    _result, = _result
    return _result
Beispiel #23
0
def compute_accidental_hits(true_classes,
                            sampled_candidates,
                            num_true,
                            seed=0,
                            seed2=0,
                            name=None):
    r"""Computes the ids of the positions in sampled_candidates that match true_labels.

  When doing log-odds NCE, the result of this op should be passed through a
  SparseToDense op, then added to the logits of the sampled candidates. This has
  the effect of 'removing' the sampled labels that match the true labels by
  making the classifier sure that they are sampled labels.

  Args:
    true_classes: A `Tensor` of type `int64`.
      The true_classes output of UnpackSparseLabels.
    sampled_candidates: A `Tensor` of type `int64`.
      The sampled_candidates output of CandidateSampler.
    num_true: An `int`. Number of true labels per context.
    seed: An optional `int`. Defaults to `0`.
      If either seed or seed2 are set to be non-zero, the random number
      generator is seeded by the given seed.  Otherwise, it is seeded by a
      random seed.
    seed2: An optional `int`. Defaults to `0`.
      An second seed to avoid seed collision.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (indices, ids, weights).

    indices: A `Tensor` of type `int32`.
    ids: A `Tensor` of type `int64`.
    weights: A `Tensor` of type `float32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "ComputeAccidentalHits", name, true_classes,
                sampled_candidates, "num_true", num_true, "seed", seed,
                "seed2", seed2)
            _result = _ComputeAccidentalHitsOutput._make(_result)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return compute_accidental_hits_eager_fallback(true_classes,
                                                          sampled_candidates,
                                                          num_true=num_true,
                                                          seed=seed,
                                                          seed2=seed2,
                                                          name=name,
                                                          ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    num_true = _execute.make_int(num_true, "num_true")
    if seed is None:
        seed = 0
    seed = _execute.make_int(seed, "seed")
    if seed2 is None:
        seed2 = 0
    seed2 = _execute.make_int(seed2, "seed2")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "ComputeAccidentalHits",
        true_classes=true_classes,
        sampled_candidates=sampled_candidates,
        num_true=num_true,
        seed=seed,
        seed2=seed2,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("num_true", _op._get_attr_int("num_true"), "seed",
                  _op._get_attr_int("seed"), "seed2",
                  _op._get_attr_int("seed2"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("ComputeAccidentalHits", _inputs_flat, _attrs,
                                 _result)
    _result = _ComputeAccidentalHitsOutput._make(_result)
    return _result
def stateful_uniform_full_int(resource,
                              algorithm,
                              shape,
                              dtype=_dtypes.uint64,
                              name=None):
    r"""Outputs random integers from a uniform distribution.

  The generated values are uniform integers covering the whole range of `dtype`.

  Args:
    resource: A `Tensor` of type `resource`.
      The handle of the resource variable that stores the state of the RNG.
    algorithm: A `Tensor` of type `int64`. The RNG algorithm.
    shape: A `Tensor`. The shape of the output tensor.
    dtype: An optional `tf.DType`. Defaults to `tf.uint64`.
      The type of the output.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `dtype`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "StatefulUniformFullInt", name, resource, algorithm,
                shape, "dtype", dtype)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return stateful_uniform_full_int_eager_fallback(resource,
                                                            algorithm,
                                                            shape,
                                                            dtype=dtype,
                                                            name=name,
                                                            ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    if dtype is None:
        dtype = _dtypes.uint64
    dtype = _execute.make_type(dtype, "dtype")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "StatefulUniformFullInt",
        resource=resource,
        algorithm=algorithm,
        shape=shape,
        dtype=dtype,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("dtype", _op._get_attr_type("dtype"), "shape_dtype",
                  _op._get_attr_type("shape_dtype"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("StatefulUniformFullInt", _inputs_flat,
                                 _attrs, _result)
    _result, = _result
    return _result
Beispiel #25
0
def thread_unsafe_unigram_candidate_sampler(true_classes,
                                            num_true,
                                            num_sampled,
                                            unique,
                                            range_max,
                                            seed=0,
                                            seed2=0,
                                            name=None):
    r"""Generates labels for candidate sampling with a learned unigram distribution.

  See explanations of candidate sampling and the data formats at
  go/candidate-sampling.

  For each batch, this op picks a single set of sampled candidate labels.

  The advantages of sampling candidates per-batch are simplicity and the
  possibility of efficient dense matrix multiplication. The disadvantage is that
  the sampled candidates must be chosen independently of the context and of the
  true labels.

  Args:
    true_classes: A `Tensor` of type `int64`.
      A batch_size * num_true matrix, in which each row contains the
      IDs of the num_true target_classes in the corresponding original label.
    num_true: An `int` that is `>= 1`. Number of true labels per context.
    num_sampled: An `int` that is `>= 1`.
      Number of candidates to randomly sample.
    unique: A `bool`.
      If unique is true, we sample with rejection, so that all sampled
      candidates in a batch are unique. This requires some approximation to
      estimate the post-rejection sampling probabilities.
    range_max: An `int` that is `>= 1`.
      The sampler will sample integers from the interval [0, range_max).
    seed: An optional `int`. Defaults to `0`.
      If either seed or seed2 are set to be non-zero, the random number
      generator is seeded by the given seed.  Otherwise, it is seeded by a
      random seed.
    seed2: An optional `int`. Defaults to `0`.
      An second seed to avoid seed collision.
    name: A name for the operation (optional).

  Returns:
    A tuple of `Tensor` objects (sampled_candidates, true_expected_count, sampled_expected_count).

    sampled_candidates: A `Tensor` of type `int64`.
    true_expected_count: A `Tensor` of type `float32`.
    sampled_expected_count: A `Tensor` of type `float32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "ThreadUnsafeUnigramCandidateSampler", name,
                true_classes, "num_true", num_true, "num_sampled", num_sampled,
                "unique", unique, "range_max", range_max, "seed", seed,
                "seed2", seed2)
            _result = _ThreadUnsafeUnigramCandidateSamplerOutput._make(_result)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return thread_unsafe_unigram_candidate_sampler_eager_fallback(
                true_classes,
                num_true=num_true,
                num_sampled=num_sampled,
                unique=unique,
                range_max=range_max,
                seed=seed,
                seed2=seed2,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    num_true = _execute.make_int(num_true, "num_true")
    num_sampled = _execute.make_int(num_sampled, "num_sampled")
    unique = _execute.make_bool(unique, "unique")
    range_max = _execute.make_int(range_max, "range_max")
    if seed is None:
        seed = 0
    seed = _execute.make_int(seed, "seed")
    if seed2 is None:
        seed2 = 0
    seed2 = _execute.make_int(seed2, "seed2")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "ThreadUnsafeUnigramCandidateSampler",
        true_classes=true_classes,
        num_true=num_true,
        num_sampled=num_sampled,
        unique=unique,
        range_max=range_max,
        seed=seed,
        seed2=seed2,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("num_true", _op._get_attr_int("num_true"), "num_sampled",
                  _op._get_attr_int("num_sampled"), "unique",
                  _op._get_attr_bool("unique"), "range_max",
                  _op._get_attr_int("range_max"), "seed",
                  _op._get_attr_int("seed"), "seed2",
                  _op._get_attr_int("seed2"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("ThreadUnsafeUnigramCandidateSampler",
                                 _inputs_flat, _attrs, _result)
    _result = _ThreadUnsafeUnigramCandidateSamplerOutput._make(_result)
    return _result
def stateful_uniform_int(resource,
                         algorithm,
                         shape,
                         minval,
                         maxval,
                         name=None):
    r"""Outputs random integers from a uniform distribution.

  The generated values are uniform integers in the range `[minval, maxval)`.
  The lower bound `minval` is included in the range, while the upper bound
  `maxval` is excluded.

  The random integers are slightly biased unless `maxval - minval` is an exact
  power of two.  The bias is small for values of `maxval - minval` significantly
  smaller than the range of the output (either `2^32` or `2^64`).

  Args:
    resource: A `Tensor` of type `resource`.
      The handle of the resource variable that stores the state of the RNG.
    algorithm: A `Tensor` of type `int64`. The RNG algorithm.
    shape: A `Tensor`. The shape of the output tensor.
    minval: A `Tensor`. Minimum value (inclusive, scalar).
    maxval: A `Tensor`. Must have the same type as `minval`.
      Maximum value (exclusive, scalar).
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `minval`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "StatefulUniformInt", name, resource, algorithm, shape,
                minval, maxval)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return stateful_uniform_int_eager_fallback(resource,
                                                       algorithm,
                                                       shape,
                                                       minval,
                                                       maxval,
                                                       name=name,
                                                       ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "StatefulUniformInt",
        resource=resource,
        algorithm=algorithm,
        shape=shape,
        minval=minval,
        maxval=maxval,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("dtype", _op._get_attr_type("dtype"), "shape_dtype",
                  _op._get_attr_type("shape_dtype"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("StatefulUniformInt", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result
Beispiel #27
0
def load_and_remap_matrix(ckpt_path,
                          old_tensor_name,
                          row_remapping,
                          col_remapping,
                          initializing_values,
                          num_rows,
                          num_cols,
                          max_rows_in_memory=-1,
                          name=None):
    r"""Loads a 2-D (matrix) `Tensor` with name `old_tensor_name` from the checkpoint

  at `ckpt_path` and potentially reorders its rows and columns using the
  specified remappings.

  Most users should use one of the wrapper initializers (such as
  `tf.contrib.framework.load_and_remap_matrix_initializer`) instead of this
  function directly.

  The remappings are 1-D tensors with the following properties:

  * `row_remapping` must have exactly `num_rows` entries. Row `i` of the output
    matrix will be initialized from the row corresponding to index
    `row_remapping[i]` in the old `Tensor` from the checkpoint.
  * `col_remapping` must have either 0 entries (indicating that no column
    reordering is needed) or `num_cols` entries. If specified, column `j` of the
    output matrix will be initialized from the column corresponding to index
    `col_remapping[j]` in the old `Tensor` from the checkpoint.
  * A value of -1 in either of the remappings signifies a "missing" entry. In that
    case, values from the `initializing_values` tensor will be used to fill that
    missing row or column. If `row_remapping` has `r` missing entries and
    `col_remapping` has `c` missing entries, then the following condition must be
    true:

  `(r * num_cols) + (c * num_rows) - (r * c) == len(initializing_values)`

  The remapping tensors can be generated using the GenerateVocabRemapping op.

  As an example, with row_remapping = [1, 0, -1], col_remapping = [0, 2, -1],
  initializing_values = [0.5, -0.5, 0.25, -0.25, 42], and w(i, j) representing
  the value from row i, column j of the old tensor in the checkpoint, the output
  matrix will look like the following:

  [[w(1, 0),  w(1, 2),  0.5],
   [w(0, 0),  w(0, 2), -0.5],
   [0.25,    -0.25,      42]]

  Args:
    ckpt_path: A `Tensor` of type `string`.
      Path to the TensorFlow checkpoint (version 2, `TensorBundle`) from
      which the old matrix `Tensor` will be loaded.
    old_tensor_name: A `Tensor` of type `string`.
      Name of the 2-D `Tensor` to load from checkpoint.
    row_remapping: A `Tensor` of type `int64`.
      An int `Tensor` of row remappings (generally created by
      `generate_vocab_remapping`).  Even if no row remapping is needed, this must
      still be an index-valued Tensor (e.g. [0, 1, 2, ...]), or a shifted
      index-valued `Tensor` (e.g. [8, 9, 10, ...], for partitioned `Variables`).
    col_remapping: A `Tensor` of type `int64`.
      An int `Tensor` of column remappings (generally created by
      `generate_vocab_remapping`).  May be a size-0 `Tensor` if only row remapping
      is to be done (e.g. column ordering is the same).
    initializing_values: A `Tensor` of type `float32`.
      A float `Tensor` containing  values to fill in for cells
      in the output matrix that are not loaded from the checkpoint. Length must be
      exactly the same as the number of missing / new cells.
    num_rows: An `int` that is `>= 0`.
      Number of rows (length of the 1st dimension) in the output matrix.
    num_cols: An `int` that is `>= 1`.
      Number of columns (length of the 2nd dimension) in the output matrix.
    max_rows_in_memory: An optional `int`. Defaults to `-1`.
      The maximum number of rows to load from the checkpoint at
      once. If less than or equal to 0, the entire matrix will be loaded into
      memory. Setting this arg trades increased disk reads for lower memory usage.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `float32`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx, "LoadAndRemapMatrix", name, ckpt_path, old_tensor_name,
                row_remapping, col_remapping, initializing_values, "num_rows",
                num_rows, "num_cols", num_cols, "max_rows_in_memory",
                max_rows_in_memory)
            return _result
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
        except _core._FallbackException:
            pass
        try:
            return load_and_remap_matrix_eager_fallback(
                ckpt_path,
                old_tensor_name,
                row_remapping,
                col_remapping,
                initializing_values,
                num_rows=num_rows,
                num_cols=num_cols,
                max_rows_in_memory=max_rows_in_memory,
                name=name,
                ctx=_ctx)
        except _core._SymbolicException:
            pass  # Add nodes to the TensorFlow graph.
    # Add nodes to the TensorFlow graph.
    num_rows = _execute.make_int(num_rows, "num_rows")
    num_cols = _execute.make_int(num_cols, "num_cols")
    if max_rows_in_memory is None:
        max_rows_in_memory = -1
    max_rows_in_memory = _execute.make_int(max_rows_in_memory,
                                           "max_rows_in_memory")
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "LoadAndRemapMatrix",
        ckpt_path=ckpt_path,
        old_tensor_name=old_tensor_name,
        row_remapping=row_remapping,
        col_remapping=col_remapping,
        initializing_values=initializing_values,
        num_rows=num_rows,
        num_cols=num_cols,
        max_rows_in_memory=max_rows_in_memory,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("num_rows", _op._get_attr_int("num_rows"), "num_cols",
                  _op._get_attr_int("num_cols"), "max_rows_in_memory",
                  _op._get_attr_int("max_rows_in_memory"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("LoadAndRemapMatrix", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result
def eager_py_func(input, token, Tout, is_async=False, name=None):
    r"""Eagerly executes a python function to compute func(input)->output. The

  semantics of the input, output, and attributes are the same as those for
  PyFunc.

  Args:
    input: A list of `Tensor` objects.
    token: A `string`.
    Tout: A list of `tf.DTypes`.
    is_async: An optional `bool`. Defaults to `False`.
    name: A name for the operation (optional).

  Returns:
    A list of `Tensor` objects of type `Tout`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "EagerPyFunc", name,
                tld.op_callbacks, input, "token", token, "is_async", is_async,
                "Tout", Tout)
            return _result
        except _core._FallbackException:
            try:
                return eager_py_func_eager_fallback(input,
                                                    token=token,
                                                    is_async=is_async,
                                                    Tout=Tout,
                                                    name=name,
                                                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    token = _execute.make_str(token, "token")
    if not isinstance(Tout, (list, tuple)):
        raise TypeError("Expected list for 'Tout' argument to "
                        "'eager_py_func' Op, not %r." % Tout)
    Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
    if is_async is None:
        is_async = False
    is_async = _execute.make_bool(is_async, "is_async")
    _, _, _op, _outputs = _op_def_library._apply_op_helper("EagerPyFunc",
                                                           input=input,
                                                           token=token,
                                                           Tout=Tout,
                                                           is_async=is_async,
                                                           name=name)
    _result = _outputs[:]
    if not _result:
        return _op
    if _execute.must_record_gradient():
        _attrs = ("token", _op.get_attr("token"), "is_async",
                  _op._get_attr_bool("is_async"), "Tin", _op.get_attr("Tin"),
                  "Tout", _op.get_attr("Tout"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("EagerPyFunc", _inputs_flat, _attrs, _result)
    return _result
def roll(input, shift, axis, name=None):
    r"""Rolls the elements of a tensor along an axis.

  The elements are shifted positively (towards larger indices) by the offset of
  `shift` along the dimension of `axis`. Negative `shift` values will shift
  elements in the opposite direction. Elements that roll passed the last position
  will wrap around to the first and vice versa. Multiple shifts along multiple
  axes may be specified.

  For example:

  ```
  # 't' is [0, 1, 2, 3, 4]
  roll(t, shift=2, axis=0) ==> [3, 4, 0, 1, 2]

  # shifting along multiple dimensions
  # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
  roll(t, shift=[1, -2], axis=[0, 1]) ==> [[7, 8, 9, 5, 6], [2, 3, 4, 0, 1]]

  # shifting along the same axis multiple times
  # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
  roll(t, shift=[2, -3], axis=[1, 1]) ==> [[1, 2, 3, 4, 0], [6, 7, 8, 9, 5]]
  ```

  Args:
    input: A `Tensor`.
    shift: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      Dimension must be 0-D or 1-D. `shift[i]` specifies the number of places by which
      elements are shifted positively (towards larger indices) along the dimension
      specified by `axis[i]`. Negative shifts will roll the elements in the opposite
      direction.
    axis: A `Tensor`. Must be one of the following types: `int32`, `int64`.
      Dimension must be 0-D or 1-D. `axis[i]` specifies the dimension that the shift
      `shift[i]` should occur. If the same axis is referenced more than once, the
      total shift for that axis will be the sum of all the shifts that belong to that
      axis.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `input`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = _pywrap_tensorflow.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "Roll", name,
                tld.op_callbacks, input, shift, axis)
            return _result
        except _core._FallbackException:
            try:
                return roll_eager_fallback(input,
                                           shift,
                                           axis,
                                           name=name,
                                           ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    _, _, _op, _outputs = _op_def_library._apply_op_helper("Roll",
                                                           input=input,
                                                           shift=shift,
                                                           axis=axis,
                                                           name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("T", _op._get_attr_type("T"), "Tshift",
                  _op._get_attr_type("Tshift"), "Taxis",
                  _op._get_attr_type("Taxis"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("Roll", _inputs_flat, _attrs, _result)
    _result, = _result
    return _result
Beispiel #30
0
def ragged_tensor_to_tensor(shape,
                            values,
                            default_value,
                            row_partition_tensors,
                            row_partition_types,
                            name=None):
    r"""Create a dense tensor from a ragged tensor, possibly altering its shape.

  The `ragged_to_dense` op creates a dense tensor from a list of row partition
  tensors, a value vector, and default values. If the shape is unspecified, the
  minimal shape required to contain all the elements in the ragged tensor (the
  natural shape) will be used. If some dimensions are left unspecified, then the
  size of the natural shape is used in that dimension.

  The default_value will be broadcast to the output shape. After that, the values
  from the ragged tensor overwrite the default values. Note that the default_value
  must have less dimensions than the value.

  The row partition tensors are in the order of the dimensions.
  At present, the types can be:
  * "ROW_SPLITS": the row_splits tensor from the ragged tensor.
  * "VALUE_ROWIDS": the value_rowids tensor from the ragged tensor.
  * "FIRST_DIM_SIZE": if value_rowids is used for the first dimension, then it
    is preceded by "FIRST_DIM_SIZE".

  Args:
    shape: A `Tensor`. Must be one of the following types: `int64`, `int32`.
      The desired shape of the the output tensor. If left unspecified (empty),
      the minimal shape required to contain all the elements in the ragged tensor
      (the natural shape) will be used. If some dimensions are left unspecified, then
      the size of the natural shape is used in that dimension.

      Note that dense dimensions cannot be modified by the shape argument. Trying to
      change the size of a dense dimension will cause the op to fail.
      Examples:
      natural shape: [4, 5, 6]
      shape: -1
      output shape: [4, 5, 6]

      natural shape: [4, 5, 6]
      shape: [3, -1, 2]
      output shape: [3, 5, 2]

      natural shape: [4, 5, 6]
      shape: [3, 7, 2]
      output shape: [3, 7, 2]
    values: A `Tensor`.
      A 1D tensor representing the values of the ragged tensor.
    default_value: A `Tensor`. Must have the same type as `values`.
      The default_value when the shape is larger than the ragged tensor. The
      default_value is broadcast until it is the shape of the output tensor, and
      then overwritten by values in the ragged tensor. The default value must be
      compatible with this broadcast operation, and must have fewer dimensions than
      the value tensor.
    row_partition_tensors: A list of at least 1 `Tensor` objects with the same type in: `int64`, `int32`.
    row_partition_types: A list of `strings`.
      The types of the row partition tensors. At present, these can be:
      * "ROW_SPLITS": the row_splits tensor from the ragged tensor.
      * "VALUE_ROWIDS": the value_rowids tensor from the ragged tensor.
      * "FIRST_DIM_SIZE": if value_rowids is used for the first dimension, then it
        is preceeded by "FIRST_DIM_SIZE".
      The tensors are in the order of the dimensions.
    name: A name for the operation (optional).

  Returns:
    A `Tensor`. Has the same type as `values`.
  """
    _ctx = _context._context or _context.context()
    tld = _ctx._thread_local_data
    if tld.is_eager:
        try:
            _result = pywrap_tfe.TFE_Py_FastPathExecute(
                _ctx._context_handle, tld.device_name, "RaggedTensorToTensor",
                name, tld.op_callbacks, shape, values, default_value,
                row_partition_tensors, "row_partition_types",
                row_partition_types)
            return _result
        except _core._FallbackException:
            try:
                return ragged_tensor_to_tensor_eager_fallback(
                    shape,
                    values,
                    default_value,
                    row_partition_tensors,
                    row_partition_types=row_partition_types,
                    name=name,
                    ctx=_ctx)
            except _core._SymbolicException:
                pass  # Add nodes to the TensorFlow graph.
        except _core._NotOkStatusException as e:
            _ops.raise_from_not_ok_status(e, name)
    # Add nodes to the TensorFlow graph.
    if not isinstance(row_partition_tensors, (list, tuple)):
        raise TypeError(
            "Expected list for 'row_partition_tensors' argument to "
            "'ragged_tensor_to_tensor' Op, not %r." % row_partition_tensors)
    _attr_num_row_partition_tensors = len(row_partition_tensors)
    if not isinstance(row_partition_types, (list, tuple)):
        raise TypeError("Expected list for 'row_partition_types' argument to "
                        "'ragged_tensor_to_tensor' Op, not %r." %
                        row_partition_types)
    row_partition_types = [
        _execute.make_str(_s, "row_partition_types")
        for _s in row_partition_types
    ]
    _, _, _op, _outputs = _op_def_library._apply_op_helper(
        "RaggedTensorToTensor",
        shape=shape,
        values=values,
        default_value=default_value,
        row_partition_tensors=row_partition_tensors,
        row_partition_types=row_partition_types,
        name=name)
    _result = _outputs[:]
    if _execute.must_record_gradient():
        _attrs = ("T", _op._get_attr_type("T"), "Tindex",
                  _op._get_attr_type("Tindex"), "Tshape",
                  _op._get_attr_type("Tshape"), "num_row_partition_tensors",
                  _op._get_attr_int("num_row_partition_tensors"),
                  "row_partition_types", _op.get_attr("row_partition_types"))
        _inputs_flat = _op.inputs
        _execute.record_gradient("RaggedTensorToTensor", _inputs_flat, _attrs,
                                 _result)
    _result, = _result
    return _result