tf.raw_ops.BatchFunction
Stay organized with collections
Save and categorize content based on your preferences.
Batches all the inputs tensors to the computation done by the function.
tf.raw_ops.BatchFunction(
in_tensors,
captured_tensors,
f,
num_batch_threads,
max_batch_size,
batch_timeout_micros,
Tout,
max_enqueued_batches=10,
allowed_batch_sizes=[],
container='',
shared_name='',
batching_queue='',
enable_large_batch_splitting=False,
name=None
)
So, for example, in the following code
# This input will be captured.
y = tf.placeholder_with_default(1.0, shape=[])
@tf.Defun(tf.float32)
def computation(a):
return tf.matmul(a, a) + y
b = gen_batch_ops.batch_function(
f=computation
in_tensors=[a],
captured_tensors=computation.captured_inputs,
Tout=[o.type for o in computation.definition.signature.output_arg],
num_batch_threads=1,
max_batch_size=10,
batch_timeout_micros=100000, # 100ms
allowed_batch_sizes=[3, 10],
batching_queue="")
If more than one session.run call is simultaneously trying to compute b
the values of a
will be gathered, non-deterministically concatenated
along the first axis, and only one thread will run the computation.
Assumes that all arguments of the function are Tensors which will be batched
along their first dimension.
Arguments that are captured, are not batched. The session.run call which does
the concatenation, will use the values of the captured tensors available to it.
Therefore, typical uses of captured tensors should involve values which remain
unchanged across session.run calls. Inference is a good example of this.
SparseTensor is not supported. The return value of the decorated function
must be a Tensor or a list/tuple of Tensors.
Args |
in_tensors
|
A list of Tensor objects. The tensors to be batched.
|
captured_tensors
|
A list of Tensor objects.
The tensors which are captured in the function, and don't need
to be batched.
|
f
|
A function decorated with @Defun.
|
num_batch_threads
|
An int .
Number of scheduling threads for processing batches of work.
Determines the number of batches processed in parallel.
|
max_batch_size
|
An int . Batch sizes will never be bigger than this.
|
batch_timeout_micros
|
An int .
Maximum number of microseconds to wait before outputting
an incomplete batch.
|
Tout
|
A list of tf.DTypes that has length >= 1 .
the types of the output tensors.
|
max_enqueued_batches
|
An optional int . Defaults to 10 .
Maximum number of batches enqueued. Default: 10.
|
allowed_batch_sizes
|
An optional list of ints . Defaults to [] .
Optional list of allowed batch sizes. If left empty, does
nothing. Otherwise, supplies a list of batch sizes, causing the op to pad
batches up to one of those sizes. The entries must increase monotonically.
If enable_large_batch_splitting is false (i.e., large-input-split is not
enabled) the final entry must equal max_batch_size.
|
container
|
An optional string . Defaults to "" .
Controls the scope of sharing of this batch.
|
shared_name
|
An optional string . Defaults to "" .
Concurrently running instances of batch in the same device with the
same container and shared_name will batch their elements together. If left
empty, the op name will be used as the shared name.
|
batching_queue
|
An optional string . Defaults to "" .
|
enable_large_batch_splitting
|
An optional bool . Defaults to False .
input with a large size (i.e., larger than the largest value of
allowed_batch_sizes ) will be splitted into multiple batches with batch size.
|
name
|
A name for the operation (optional).
|
Returns |
A list of Tensor objects of type Tout .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[],null,["# tf.raw_ops.BatchFunction\n\n\u003cbr /\u003e\n\nBatches all the inputs tensors to the computation done by the function.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.BatchFunction`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/BatchFunction)\n\n\u003cbr /\u003e\n\n tf.raw_ops.BatchFunction(\n in_tensors,\n captured_tensors,\n f,\n num_batch_threads,\n max_batch_size,\n batch_timeout_micros,\n Tout,\n max_enqueued_batches=10,\n allowed_batch_sizes=[],\n container='',\n shared_name='',\n batching_queue='',\n enable_large_batch_splitting=False,\n name=None\n )\n\nSo, for example, in the following code \n\n\n # This input will be captured.\n y = tf.placeholder_with_default(1.0, shape=[])\n\n @tf.Defun(tf.float32)\n def computation(a):\n return tf.matmul(a, a) + y\n\n b = gen_batch_ops.batch_function(\n f=computation\n in_tensors=[a],\n captured_tensors=computation.captured_inputs,\n Tout=[o.type for o in computation.definition.signature.output_arg],\n num_batch_threads=1,\n max_batch_size=10,\n batch_timeout_micros=100000, # 100ms\n allowed_batch_sizes=[3, 10],\n batching_queue=\"\")\n\nIf more than one session.run call is simultaneously trying to compute `b`\nthe values of `a` will be gathered, non-deterministically concatenated\nalong the first axis, and only one thread will run the computation.\n\nAssumes that all arguments of the function are Tensors which will be batched\nalong their first dimension.\n\nArguments that are captured, are not batched. The session.run call which does\nthe concatenation, will use the values of the captured tensors available to it.\nTherefore, typical uses of captured tensors should involve values which remain\nunchanged across session.run calls. Inference is a good example of this.\n\nSparseTensor is not supported. The return value of the decorated function\nmust be a Tensor or a list/tuple of Tensors.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `in_tensors` | A list of `Tensor` objects. The tensors to be batched. |\n| `captured_tensors` | A list of `Tensor` objects. The tensors which are captured in the function, and don't need to be batched. |\n| `f` | A function decorated with @Defun. |\n| `num_batch_threads` | An `int`. Number of scheduling threads for processing batches of work. Determines the number of batches processed in parallel. |\n| `max_batch_size` | An `int`. Batch sizes will never be bigger than this. |\n| `batch_timeout_micros` | An `int`. Maximum number of microseconds to wait before outputting an incomplete batch. |\n| `Tout` | A list of `tf.DTypes` that has length `\u003e= 1`. the types of the output tensors. |\n| `max_enqueued_batches` | An optional `int`. Defaults to `10`. Maximum number of batches enqueued. Default: 10. |\n| `allowed_batch_sizes` | An optional list of `ints`. Defaults to `[]`. Optional list of allowed batch sizes. If left empty, does nothing. Otherwise, supplies a list of batch sizes, causing the op to pad batches up to one of those sizes. The entries must increase monotonically. If enable_large_batch_splitting is false (i.e., large-input-split is not enabled) the final entry must equal max_batch_size. |\n| `container` | An optional `string`. Defaults to `\"\"`. Controls the scope of sharing of this batch. |\n| `shared_name` | An optional `string`. Defaults to `\"\"`. Concurrently running instances of batch in the same device with the same container and shared_name will batch their elements together. If left empty, the op name will be used as the shared name. |\n| `batching_queue` | An optional `string`. Defaults to `\"\"`. |\n| `enable_large_batch_splitting` | An optional `bool`. Defaults to `False`. input with a large size (i.e., larger than the largest value of `allowed_batch_sizes`) will be splitted into multiple batches with batch size. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A list of `Tensor` objects of type `Tout`. ||\n\n\u003cbr /\u003e"]]