Stacks a list of rank-R tensors into one rank-(R+1) tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.stack
See also tf.concat, tf.tile, tf.repeat.
Packs the list of tensors in values into a tensor with rank one higher than each tensor in values, by packing them along the axis dimension. Given a list of length N of tensors of shape (A, B, C);
if axis == 0 then the output tensor will have the shape (N, A, B, C). if axis == 1 then the output tensor will have the shape (A, N, B, C). Etc.
This is the opposite of unstack. The numpy equivalent is np.stack


Stops gradient computation.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.stop_gradient
When executed in a graph, this op outputs its input tensor as-is.
When building ops to compute gradients, this op prevents the contribution of its inputs to be taken into account. Normally, the gradient generator adds ops to a graph to compute the derivatives of a specified 'loss' by recursively finding out inputs that contributed to its computation. If you insert this op in the graph it inputs are masked from the gradient generator. They are not taken into account for computing gradients.
This is useful any time you want to compute a value with TensorFlow but need to pretend that the value was a constant. Some examples include:


Extracts a strided slice of a tensor (generalized Python array indexing).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strided_slice
See also tf.slice.
Instead of calling this op directly most users will want to use the NumPy-style slicing syntax (e.g. tensor[..., 3:4:-1, tf.newaxis, 3]), which is supported via tf.Tensor.getitem and tf.Variable.getitem. The interface of this op is a low-level encoding of the slicing syntax.
Roughly speaking, this op extracts a slice of size (end-begin)/stride from the given input_ tensor. Starting at the location specified by begin the slice continues by adding stride to the index until all dimensions are not less than end. Note that a stride can be negative, which causes a reverse slice.
Given a Python slice input[spec0, spec1, ..., specn], this function will be called as follows.
begin, end, and strides will be vectors of length n. n in general is not equal to the rank of the input_ tensor.
In each mask field (begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask) the ith bit will correspond to the ith spec.
If the ith bit of begin_mask is set, begin[i] is ignored and the fullest possible range in that dimension is used instead. end_mask works analogously, except with the end range.
foo[5:,:,:3] on a 7x8x9 tensor is equivalent to foo[5:7,0:8,0:3]. foo[::-1] reverses a tensor with shape 8.
If the ith bit of ellipsis_mask is set, as many unspecified dimensions as needed will be inserted between other dimensions. Only one non-zero bit is allowed in ellipsis_mask.
For example foo[3:5,...,4:5] on a shape 10x3x3x10 tensor is equivalent to foo[3:5,:,:,4:5] and foo[3:5,...] is equivalent to foo[3:5,:,:,:].
If the ith bit of new_axis_mask is set, then begin, end, and stride are ignored and a new length 1 dimension is added at this point in the output tensor.
For example, foo[:4, tf.newaxis, :2] would produce a shape (4, 1, 2) tensor.
If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1, taking on the value at index begin[i]. end[i] and strides[i] are ignored in this case. For example in Python one might do foo[:, 3, :] which would result in shrink_axis_mask equal to 2.


Operations for working with string Tensors.
as_string(...): Converts each entry in the given tensor to strings.
bytes_split(...): Split string elements of input into bytes.
format(...): Formats a string template using a list of tensors.
join(...): Perform element-wise concatenation of a list of string tensors.
length(...): String lengths of input.
lower(...): Converts all uppercase characters into their respective lowercase replacements.
ngrams(...): Create a tensor of n-grams based on data.
reduce_join(...): Joins all strings into a single string, or joins along an axis.
regex_full_match(...): Check if the input matches the regex pattern.
regex_replace(...): Replace elements of input matching regex pattern with rewrite.
split(...): Split elements of input based on sep into a RaggedTensor.
strip(...): Strip leading and trailing whitespaces from the Tensor.
substr(...): Return substrings from Tensor of strings.
to_hash_bucket(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_hash_bucket_fast(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_hash_bucket_strong(...): Converts each string in the input Tensor to its hash mod by a number of buckets.
to_number(...): Converts each string in the input Tensor to the specified numeric type.
unicode_decode(...): Decodes each string in input into a sequence of Unicode code points.
unicode_decode_with_offsets(...): Decodes each string into a sequence of code points with start offsets.
unicode_encode(...): Encodes each sequence of Unicode code points in input into a string.
unicode_script(...): Determine the script codes of a given tensor of Unicode integer code points.
unicode_split(...): Splits each string in input into a sequence of Unicode code points.
unicode_split_with_offsets(...): Splits each string into a sequence of code points with start offsets.
unicode_transcode(...): Transcode the input text from a source encoding to a destination encoding.
unsorted_segment_join(...): Joins the elements of inputs based on segment_ids.
upper(...): Converts all lowercase characters into their respective uppercase replacements.


Converts each entry in the given tensor to strings.
Main aliases
tf.as_string
See Migration guide for more details.
tf.compat.v1.as_string, tf.compat.v1.dtypes.as_string, tf.compat.v1.strings.as_string
Supports many numeric types and boolean.
For Unicode, see the https://www.tensorflow.org/tutorials/representation/unicode tutorial.


Split string elements of input into bytes.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.bytes_split
Note that this op splits strings into bytes, not unicode characters. To split strings into unicode characters, use tf.strings.unicode_split.
See also: tf.io.decode_raw, tf.strings.split, tf.strings.unicode_split.


Formats a string template using a list of tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.format
Formats a string template using a list of tensors, abbreviating tensors by only printing the first and last summarize elements of each dimension (recursively). If formatting only one tensor into a template, the tensor does not have to be wrapped in a list.
Formatting a single-tensor template:
Formatting a multi-tensor template:


Perform element-wise concatenation of a list of string tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.string_join, tf.compat.v1.strings.join
Given a list of string tensors of same shape, performs element-wise concatenation of the strings of the same index in all tensors.


String lengths of input.
Computes the length of each string given in the input tensor.


Converts all uppercase characters into their respective lowercase replacements.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.lower


Create a tensor of n-grams based on data.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.ngrams
Creates a tensor of n-grams based on data. The n-grams are created by joining windows of width adjacent strings from the inner axis of data using separator.
The input data can be padded on both the start and end of the sequence, if desired, using the pad_values argument. If set, pad_values should contain either a tuple of strings or a single string; the 0th element of the tuple will be used to pad the left side of the sequence and the 1st element of the tuple will be used to pad the right side of the sequence. The padding_width arg controls how many padding values are added to each side; it defaults to ngram_width-1.
If this op is configured to not have padding, or if it is configured to add padding with padding_width set to less than ngram_width-1, it is possible that a sequence, or a sequence plus padding, is smaller than the ngram width. In that case, no ngrams will be generated for that sequence. This can be prevented by setting preserve_short_sequences, which will cause the op to always generate at least one ngram per non-empty sequence.


Joins all strings into a single string, or joins along an axis.


Check if the input matches the regex pattern.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.regex_full_match
The input is a string tensor of any shape. The pattern is a scalar string tensor which is applied to every element of the input tensor. The boolean values (True or False) of the output tensor indicate if the input matches the regex pattern provided.
The pattern follows the re2 syntax (https://github.com/google/re2/wiki/Syntax)


Replace elements of input matching regex pattern with rewrite.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.regex_replace, tf.compat.v1.strings.regex_replace


Split elements of input based on sep into a RaggedTensor.
Let N be the size of input (typically N will be the batch size). Split each element of input based on sep and return a RaggedTensor containing the split tokens. Empty tokens are ignored.
If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings. For example, input of "1<>2<><>3" and sep of "<>" returns ["1", "2", "", "3"]. If sep is None or an empty string, consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace.
Note that the above mentioned behavior matches python's str.split.


Strip leading and trailing whitespaces from the Tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.string_strip, tf.compat.v1.strings.strip


Return substrings from Tensor of strings.
For each string in the input Tensor, creates a substring starting at index pos with a total length of len.
If len defines a substring that would extend beyond the length of the input string, or if len is negative, then as many characters as possible are used.
A negative pos indicates distance within the string backwards from the end.
If pos specifies an index which is out of range for any of the input strings, then an InvalidArgumentError is thrown.
pos and len must have the same shape, otherwise a ValueError is thrown on Op creation.
Examples
Using scalar pos and len:
Using pos and len with same shape as input:
Broadcasting pos and len onto input:
Broadcasting input onto pos and len:


Converts each string in the input Tensor to its hash mod by a number of buckets.
The hash function is deterministic on the content of the string within the process.
Note that the hash function may change from time to time. This functionality will be deprecated and it's recommended to use tf.strings.to_hash_bucket_fast() or tf.strings.to_hash_bucket_strong().


Converts each string in the input Tensor to its hash mod by a number of buckets.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.string_to_hash_bucket_fast, tf.compat.v1.strings.to_hash_bucket_fast
The hash function is deterministic on the content of the string within the process and will never change. However, it is not suitable for cryptography. This function may be used when CPU time is scarce and inputs are trusted or unimportant. There is a risk of adversaries constructing inputs that all hash to the same bucket. To prevent this problem, use a strong hash function with tf.string_to_hash_bucket_strong.


Converts each string in the input Tensor to its hash mod by a number of buckets.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.string_to_hash_bucket_strong, tf.compat.v1.strings.to_hash_bucket_strong
The hash function is deterministic on the content of the string within the process. The hash function is a keyed hash function, where attribute key defines the key of the hash function. key is an array of 2 elements.
A strong hash is important when inputs may be malicious, e.g. URLs with additional components. Adversaries could try to make their inputs hash to the same bucket for a denial-of-service attack or to skew the results. A strong hash can be used to make it difficult to find inputs with a skewed hash value distribution over buckets. This requires that the hash function is seeded by a high-entropy (random) "key" unknown to the adversary.
The additional robustness comes at a cost of roughly 4x higher compute time than tf.string_to_hash_bucket_fast.


Converts each string in the input Tensor to the specified numeric type.
(Note that int32 overflow results in an error while float overflow results in a rounded value.)


Decodes each string in input into a sequence of Unicode code points.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_decode
result[i1...iN, j] is the Unicode codepoint for the jth character in input[i1...iN], when decoded using input_encoding.


Decodes each string into a sequence of code points with start offsets.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_decode_with_offsets
This op is similar to tf.strings.decode(...), but it also returns the start offset for each character in its respective string. This information can be used to align the characters with the original byte sequence.
Returns a tuple (codepoints, start_offsets) where:
The returned tensors are tf.Tensors if input is a scalar, or tf.RaggedTensors otherwise.


Encodes each sequence of Unicode code points in input into a string.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_encode
result[i1...iN] is the string formed by concatenating the Unicode codepoints input[1...iN, :], encoded using output_encoding.


Determine the script codes of a given tensor of Unicode integer code points.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_script
This operation converts Unicode code points to script codes corresponding to each code point. Script codes correspond to International Components for Unicode (ICU) UScriptCode values.
See ICU project docs for more details on script codes.
For an example, see the unicode strings guide on unicode scripts.
Returns -1 (USCRIPT_INVALID_CODE) for invalid codepoints. Output shape will match input shape.


Splits each string in input into a sequence of Unicode code points.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_split
result[i1...iN, j] is the substring of input[i1...iN] that encodes its jth character, when decoded using input_encoding.


Splits each string into a sequence of code points with start offsets.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_split_with_offsets
This op is similar to tf.strings.decode(...), but it also returns the start offset for each character in its respective string. This information can be used to align the characters with the original byte sequence.
Returns a tuple (chars, start_offsets) where:
The returned tensors are tf.Tensors if input is a scalar, or tf.RaggedTensors otherwise.


Transcode the input text from a source encoding to a destination encoding.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unicode_transcode
The input is a string tensor of any shape. The output is a string tensor of the same shape containing the transcoded strings. Output strings are always valid unicode. If the input contains invalid encoding positions, the errors attribute sets the policy for how to deal with them. If the default error-handling policy is used, invalid formatting will be substituted in the output by the replacement_char. If the errors policy is to ignore, any invalid encoding positions in the input are skipped and not included in the output. If it set to strict then any invalid formatting will result in an InvalidArgument error.
This operation can be used with output_encoding = input_encoding to enforce correct formatting for inputs even if they are already in the desired encoding.
If the input is prefixed by a Byte Order Mark needed to determine encoding (e.g. if the encoding is UTF-16 and the BOM indicates big-endian), then that BOM will be consumed and not emitted into the output. If the input encoding is marked with an explicit endianness (e.g. UTF-16-BE), then the BOM is interpreted as a non-breaking-space and is preserved in the output (including always for UTF-8).
The end result is that if the input is marked as an explicit endianness the transcoding is faithful to all codepoints in the source. If it is not marked with an explicit endianness, the BOM is not considered part of the string itself but as metadata, and so is not preserved in the output.
Note that for UTF-8, passing a replacement character expressible in 1 byte, such as ' ', will preserve string alignment to the source since invalid bytes will be replaced with a 1-byte replacement. For UTF-16-BE and UTF-16-LE, any 1 or 2 byte replacement character will preserve byte alignment to the source.


Joins the elements of inputs based on segment_ids.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.unsorted_segment_join
Computes the string join along segments of a tensor. Given segment_ids with rank N and data with rank N+M:
where the join is over all [j1...jN] such that segment_ids[j1...jN] = i. Strings are joined in row-major order.


Converts all lowercase characters into their respective uppercase replacements.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.strings.upper


Operations for writing summary data, for use in analysis and visualization.
The tf.summary module provides APIs for writing summary data. This data can be visualized in TensorBoard, the visualization toolkit that comes with TensorFlow. See the TensorBoard website for more detailed tutorials about how to use these APIs, or some quick examples below.
Example usage with eager execution, the default in TF 2.0:
Example usage with tf.function graph execution:
Example usage with legacy TF 1.x graph execution:
experimental module: Public API for tf.summary.experimental namespace.
class SummaryWriter: Interface representing a stateful summary writer object.
audio(...): Write an audio summary.
create_file_writer(...): Creates a summary file writer for the given log directory.
create_noop_writer(...): Returns a summary writer that does nothing.
flush(...): Forces summary writer to send any buffered data to storage.
histogram(...): Write a histogram summary.
image(...): Write an image summary.
record_if(...): Sets summary recording on or off per the provided boolean value.
scalar(...): Write a scalar summary.
should_record_summaries(...): Returns boolean Tensor which is true if summaries should be recorded.
text(...): Write a text summary.
trace_export(...): Stops and exports the active trace as a Summary and/or profile file.
trace_off(...): Stops the current trace and discards any collected information.
trace_on(...): Starts a trace to record computation graphs and profiling information.
write(...): Writes a generic summary to the default SummaryWriter if one exists.


Creates a summary file writer for the given log directory.


Returns a summary writer that does nothing.
This is useful as a placeholder in code that expects a context manager.


Public API for tf.summary.experimental namespace.
get_step(...): Returns the default summary step for the current thread.
set_step(...): Sets the default summary step for the current thread.
summary_scope(...): Experimental context manager for use when defining a custom summary op.
write_raw_pb(...): Writes a summary using raw tf.compat.v1.Summary protocol buffers.


Returns the default summary step for the current thread.


Sets the default summary step for the current thread.
For convenience, this function sets a default value for the step parameter used in summary-writing functions elsewhere in the API so that it need not be explicitly passed in every such invocation. The value can be a constant or a variable, and can be retrieved via tf.summary.experimental.get_step().


Experimental context manager for use when defining a custom summary op.
This behaves similarly to tf.name_scope, except that it returns a generated summary tag in addition to the scope name. The tag is structurally similar to the scope name - derived from the user-provided name, prefixed with enclosing name scopes if any - but we relax the constraint that it be uniquified, as well as the character set limitation (so the user-provided name can contain characters not legal for scope names; in the scope name these are removed).
This makes the summary tag more predictable and consistent for the user.
For example, to define a new summary op called my_op:


Writes a summary using raw tf.compat.v1.Summary protocol buffers.
Experimental: this exists to support the usage of V1-style manual summary writing (via the construction of a tf.compat.v1.Summary protocol buffer) with the V2 summary writing API.


Forces summary writer to send any buffered data to storage.
This operation blocks until that finishes.


Sets summary recording on or off per the provided boolean value.
The provided value can be a python boolean, a scalar boolean Tensor, or or a callable providing such a value; if a callable is passed it will be invoked on-demand to determine whether summary writing will occur.


Returns boolean Tensor which is true if summaries should be recorded.


Interface representing a stateful summary writer object.
View source
Returns a context manager that enables summary writing.
For convenience, if step is not None, this function also sets a default value for the step parameter used in summary-writing functions elsewhere in the API so that it need not be explicitly passed in every such invocation. The value can be a constant or a variable.
For example, step can be used as:
View source
Flushes and closes the summary writer.
View source
Flushes any buffered data.
View source
Initializes the summary writer.
View source
Enables this summary writer for the current thread.
For convenience, if step is not None, this function also sets a default value for the step parameter used in summary-writing functions elsewhere in the API so that it need not be explicitly passed in every such invocation. The value can be a constant or a variable.


Stops and exports the active trace as a Summary and/or profile file.
Stops the trace and exports all metadata collected during the trace to the default SummaryWriter, if one has been set.


Stops the current trace and discards any collected information.


Starts a trace to record computation graphs and profiling information.
Must be invoked in eager mode.
When enabled, TensorFlow runtime will collection information that can later be exported and consumed by TensorBoard. The trace is activated across the entire TensorFlow runtime and affects all threads of execution.
To stop the trace and export the collected information, use tf.summary.trace_export. To stop the trace without exporting, use tf.summary.trace_off.


Writes a generic summary to the default SummaryWriter if one exists.
This exists primarily to support the definition of type-specific summary ops like scalar() and image(), and is not intended for direct use unless defining a new type-specific summary op.


Create a switch/case operation, i.e. an integer-indexed conditional.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.switch_case
See also tf.case.
This op can be substantially more efficient than tf.case when exactly one branch will be selected. tf.switch_case is more like a C++ switch/case statement than tf.case, which is more like an if/elif/elif/else chain.
The branch_fns parameter is either a dict from int to callables, or list of (int, callable) pairs, or simply a list of callables (in which case the index is implicitly the key). The branch_index Tensor is used to select an element in branch_fns with matching int key, falling back to default if none match, or max(keys) if no default is provided. The keys must form a contiguous set from 0 to len(branch_fns) - 1.
tf.switch_case supports nested structures as implemented in tf.nest. All callables must return the same (possibly nested) value structure of lists, tuples, and/or named tuples.
Example:
or


System configuration library.
get_build_info(...): Get a dictionary describing TensorFlow's build environment.
get_compile_flags(...): Get the compilation flags for custom operators.
get_include(...): Get the directory containing the TensorFlow C++ header files.
get_lib(...): Get the directory containing the TensorFlow framework library.
get_link_flags(...): Get the link flags for custom operators.


Get a dictionary describing TensorFlow's build environment.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sysconfig.get_build_info
Values are generated when TensorFlow is compiled, and are static for each TensorFlow package. The return value is a dictionary with string keys such as:
Note that the actual keys and values returned by this function is subject to change across different versions of TensorFlow or across platforms.


Get the compilation flags for custom operators.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sysconfig.get_compile_flags


Get the directory containing the TensorFlow C++ header files.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sysconfig.get_include


Get the directory containing the TensorFlow framework library.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sysconfig.get_lib


Get the link flags for custom operators.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.sysconfig.get_link_flags


A tensor is a multidimensional array of elements represented by a
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.Tensor
tf.Tensor object. All elements are of a single known data type.
When writing a TensorFlow program, the main object that is manipulated and passed around is the tf.Tensor.
A tf.Tensor has the following properties:
TensorFlow supports eager execution and graph execution. In eager execution, operations are evaluated immediately. In graph execution, a computational graph is constructed for later evaluation.
TensorFlow defaults to eager execution. In the example below, the matrix multiplication results are calculated immediately.
Note that during eager execution, you may discover your Tensors are actually of type EagerTensor. This is an internal detail, but it does give you access to a useful function, numpy:
In TensorFlow, tf.functions are a common way to define graph execution.
A Tensor's shape (that is, the rank of the Tensor and the size of each dimension) may not always be fully known. In tf.function definitions, the shape may only be partially known.
Most operations produce tensors of fully-known shapes if the shapes of their inputs are also fully known, but in some cases it's only possible to find the shape of a tensor at execution time.
A number of specialized tensors are available: see tf.Variable, tf.constant, tf.placeholder, tf.sparse.SparseTensor, and tf.RaggedTensor.
For more on Tensors, see the guide.
tf.Tensor.shape is equivalent to tf.Tensor.get_shape().
In a tf.function or when building a model using tf.keras.Input, they return the build-time shape of the tensor, which may be partially unknown.
A tf.TensorShape is not a tensor. Use tf.shape(t) to get a tensor containing the shape, calculated at runtime.
See tf.Tensor.get_shape(), and tf.TensorShape for details and examples.
View source
Returns a list of Operations that consume this tensor.
View source
Evaluates this tensor in a Session.
Calling this method will execute all preceding operations that produce the inputs needed for the operation that produces this tensor.
View source
DEPRECATED FUNCTION
View source
Returns a tf.TensorShape that represents the shape of this tensor.
In eager execution the shape is always fully-known.
tf.Tensor.get_shape() is equivalent to tf.Tensor.shape.
When executing in a tf.function or building a model using tf.keras.Input, Tensor.shape may return a partial shape (including None for unknown dimensions). See tf.TensorShape for more details.
The shape is computed using shape inference functions that are registered for each tf.Operation.
The returned tf.TensorShape is determined at build time, without executing the underlying kernel. It is not a tf.Tensor. If you need a shape tensor, either convert the tf.TensorShape to a tf.constant, or use the tf.shape(tensor) function, which returns the tensor's shape at execution time.
This is useful for debugging and providing early errors. For example, when tracing a tf.function, no ops are being executed, shapes may be unknown (See the Concrete Functions Guide for details).
The shape inference functions propagate shapes to the extent possible:
Tracing may fail if a shape missmatch can be detected:
In some cases, the inferred shape may have unknown dimensions. If the caller has additional information about the values of these dimensions, tf.ensure_shape or Tensor.set_shape() can be used to augment the inferred shape.
View source
Returns a hashable reference object to this Tensor.
The primary use case for this API is to put tensors in a set/dictionary. We can't put tensors in a set/dictionary as tensor.__hash__() is no longer available starting Tensorflow 2.0.
The following will raise an exception starting 2.0
Instead, we can use tensor.ref().
Also, the reference object provides .deref() function that returns the original Tensor.
View source
Updates the shape of this tensor.
With eager execution this operates as a shape assertion. Here the shapes match:
Passing a None in the new shape allows any value for that axis:
An error is raised if an incompatible shape is passed.
When executing in a tf.function, or building a model using tf.keras.Input, Tensor.set_shape will merge the given shape with the current shape of this tensor, and set the tensor's shape to the merged value (see tf.TensorShape.merge_with for details):
Dimensions set to None are not updated:
The main use case for this is to provide additional shape information that cannot be inferred from the graph alone.
For example if you know all the images in a dataset have shape [28,28,3] you can set it with tf.set_shape:
Trace the function, see the Concrete Functions Guide for details.
Similarly the tf.io.parse_tensor function could return a tensor with any shape, even the tf.rank is unknown. If you know that all your serialized tensors will be 2d, set it with set_shape:
Trace the function
View source
Computes the absolute value of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Given a tensor x of complex numbers, this operation returns a tensor of type float32 or float64 that is the absolute value of each element in x. For a complex number \(a + bj\), its absolute value is computed as \(\sqrt{a^2 + b^2}\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)
View source
The operation invoked by the Tensor.add operator.
Purpose in the API:
View source
View source
Dummy method to prevent a tensor from being used as a Python bool.
This overload raises a TypeError when the user inadvertently treats a Tensor as a boolean (most commonly in an if or while statement), in code that was not converted by AutoGraph. For example:
View source
Divides x / y elementwise (using Python 2 division operator semantics). (deprecated)
This function divides x and y, forcing Python 2 semantics. That is, if x and y are both integers then the result will be an integer. This is in contrast to Python 3, where division with / is always a float while division with // is always an integer.
View source
The operation invoked by the Tensor.eq operator.
Compares two tensors element-wise for equality if they are broadcast-compatible; or returns False if they are not broadcast-compatible. (Note that this behavior differs from tf.math.equal, which raises an exception if the two tensors are not broadcast-compatible.)
This method is exposed in TensorFlow's API so that library developers can register dispatching for Tensor.eq to allow it to handle custom composite tensors & other custom objects.
The API symbol is not intended to be called by users directly and does appear in TensorFlow's generated documentation.
View source
Divides x / y elementwise, rounding toward the most negative integer.
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.
x and y must have the same type, and the result will have the same type as well.
Returns the truth value of (x >= y) element-wise.
View source
Overload for Tensor.getitem.
This operation extracts the specified region from the tensor. The notation is similar to NumPy with the restriction that currently only support basic indexing. That means that using a non-scalar tensor as input is not currently allowed.
This method is exposed in TensorFlow's API so that library developers can register dispatching for Tensor.getitem to allow it to handle custom composite tensors & other custom objects.
The API symbol is not intended to be called by users directly and does appear in TensorFlow's generated documentation.
Returns the truth value of (x > y) element-wise.
View source
View source
Returns the truth value of (x <= y) element-wise.
View source
Returns the truth value of (x < y) element-wise.
View source
Multiplies matrix a by matrix b, producing a * b.
The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication dimensions, and any further outer dimensions specify matching batch size.
Both matrices must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.
Either matrix can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.
If one or both of the matrices contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices (rank-2 tensors) with datatypes bfloat16 or float32.
A simple 2-D tensor matrix multiplication:
A batch matrix multiplication with batch shape [2]:
Since python >= 3.5 the @ operator is supported (see PEP 465). In TensorFlow, it simply calls the tf.matmul() function, so the following lines are equivalent:
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
View source
Returns element-wise remainder of division. When x < 0 xor y < 0 is
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.
View source
Dispatches cwise mul for "DenseDense" and "DenseSparse".
View source
The operation invoked by the Tensor.ne operator.
Compares two tensors element-wise for inequality if they are broadcast-compatible; or returns True if they are not broadcast-compatible. (Note that this behavior differs from tf.math.not_equal, which raises an exception if the two tensors are not broadcast-compatible.)
This method is exposed in TensorFlow's API so that library developers can register dispatching for Tensor.ne to allow it to handle custom composite tensors & other custom objects.
The API symbol is not intended to be called by users directly and does appear in TensorFlow's generated documentation.
Computes numerical negative value element-wise.
I.e., \(y = -x\).
If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.negative(x.values, ...), x.dense_shape)
View source
Dummy method to prevent a tensor from being used as a Python bool.
This is the Python 2.x counterpart to __bool__() above.
View source
View source
Computes the power of one value to another.
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example:
View source
The operation invoked by the Tensor.add operator.
Purpose in the API:
View source
View source
Divides x / y elementwise (using Python 2 division operator semantics). (deprecated)
This function divides x and y, forcing Python 2 semantics. That is, if x and y are both integers then the result will be an integer. This is in contrast to Python 3, where division with / is always a float while division with // is always an integer.
View source
Divides x / y elementwise, rounding toward the most negative integer.
The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.
x and y must have the same type, and the result will have the same type as well.
View source
Multiplies matrix a by matrix b, producing a * b.
The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication dimensions, and any further outer dimensions specify matching batch size.
Both matrices must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.
Either matrix can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.
If one or both of the matrices contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices (rank-2 tensors) with datatypes bfloat16 or float32.
A simple 2-D tensor matrix multiplication:
A batch matrix multiplication with batch shape [2]:
Since python >= 3.5 the @ operator is supported (see PEP 465). In TensorFlow, it simply calls the tf.matmul() function, so the following lines are equivalent:
output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.
View source
Returns element-wise remainder of division. When x < 0 xor y < 0 is
true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.
View source
Dispatches cwise mul for "DenseDense" and "DenseSparse".
View source
View source
Computes the power of one value to another.
Given a tensor x and a tensor y, this operation computes \(x^y\) for corresponding elements in x and y. For example:
View source
Returns x - y element-wise.
View source
Divides x / y elementwise (using Python 3 division operator semantics).
This function forces Python 3 division operator semantics where all integer arguments are cast to floating types first. This op is generated by normal x / y division in Python 3 and in Python 2.7 with from __future__ import division. If you want integer division that rounds down, use x // y or tf.math.floordiv.
x and y must have the same numeric type. If the inputs are floating point, the output will have the same type. If the inputs are integral, the inputs are cast to float32 for int8 and int16 and float64 for int32 and int64 (matching the behavior of Numpy).
View source
View source
Returns x - y element-wise.
View source
Divides x / y elementwise (using Python 3 division operator semantics).
This function forces Python 3 division operator semantics where all integer arguments are cast to floating types first. This op is generated by normal x / y division in Python 3 and in Python 2.7 with from __future__ import division. If you want integer division that rounds down, use x // y or tf.math.floordiv.
x and y must have the same numeric type. If the inputs are floating point, the output will have the same type. If the inputs are integral, the inputs are cast to float32 for int8 and int16 and float64 for int32 and int64 (matching the behavior of Numpy).
View source


Class wrapping dynamic-sized, per-time-step, write-once Tensor arrays.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.TensorArray
This class is meant to be used with dynamic iteration primitives such as while_loop and map_fn. It supports gradient back-propagation via special "flow" control flow dependencies.
Example 1: Plain reading and writing.
Example 2: Fibonacci sequence algorithm that writes in a loop then returns.
Example 3: A simple loop interacting with a tf.Variable.
View source
Close the current TensorArray.
View source
Return the values in the TensorArray as a concatenated Tensor.
All of the values must have been written, their ranks must match, and and their shapes must all match for all dimensions except the first.
View source
Return selected values in the TensorArray as a packed Tensor.
All of selected values must have been written and their shapes must all match.
View source
View source
Returns a TensorArray with the same content and properties.
View source
Read the value at location index in the TensorArray.
View source
Scatter the values of a Tensor in specific indices of a TensorArray.
View source
Return the size of the TensorArray.
View source
Split the values of a Tensor into the TensorArray.
View source
Return the values in the TensorArray as a stacked Tensor.
All of the values must have been written and their shapes must all match. If input shapes have rank-R, then output shape will have rank-(R+1).
View source
Unstack the values of a Tensor in the TensorArray.
If input value shapes have rank-R, then the output TensorArray will contain elements whose shapes are rank-(R-1).
View source
Write value into index index of the TensorArray.


Type specification for a tf.TensorArray.
Inherits From: TypeSpec
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.TensorArraySpec
View source
View source
Returns true if spec_or_value is compatible with this TypeSpec.
View source
Returns the most specific TypeSpec compatible with self and other.
View source
Return self==value.
View source
Return self!=value.


Tensor contraction of a and b along specified axes and outer product.
Main aliases
tf.linalg.tensordot
See Migration guide for more details.
tf.compat.v1.linalg.tensordot, tf.compat.v1.tensordot
Tensordot (also known as tensor contraction) sums the product of elements from a and b over the indices specified by a_axes and b_axes. The lists a_axes and b_axes specify those pairs of axes along which to contract the tensors. The axis a_axes[i] of a must have the same dimension as axis b_axes[i] of b for all i in range(0, len(a_axes)). The lists a_axes and b_axes must have identical length and consist of unique integers that specify valid axes for each of the tensors. Additionally outer product is supported by passing axes=0.
This operation corresponds to numpy.tensordot(a, b, axes).
Example 1: When a and b are matrices (order 2), the case axes = 1 is equivalent to matrix multiplication.
Example 2: When a and b are matrices (order 2), the case axes = [[1], [0]] is equivalent to matrix multiplication.
Example 3: When a and b are matrices (order 2), the case axes=0 gives the outer product, a tensor of order 4.
Example 4: Suppose that \(a_{ijk}\) and \(b_{lmn}\) represent two tensors of order 3. Then, contract(a, b, [[0], [2]]) is the order 4 tensor \(c_{jklm}\) whose entry corresponding to the indices \((j,k,l,m)\) is given by:
\( c_{jklm} = \sum_i a_{ijk} b_{lmi} \).
In general, order(c) = order(a) + order(b) - 2*len(axes[0]).


Represents the shape of a Tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.TensorShape
A TensorShape represents a possibly-partial shape specification for a Tensor. It may be one of the following:
If a tensor is produced by an operation of type "Foo", its shape may be inferred if there is a registered shape function for "Foo". See Shape functions for details of shape functions and how to register them. Alternatively, the shape may be set explicitly using tf.Tensor.set_shape.
Suggest TensorShape.as_list instead.
View source
Returns a list of integers or None for each dimension.
View source
Returns this shape as a TensorShapeProto.
View source
Raises an exception if self is not compatible with the given rank.
View source
Raises exception if self and other do not represent the same shape.
This method can be used to assert that there exists a shape that both self and other represent.
View source
Raises an exception if self is not fully defined in every dimension.
View source
Raises an exception if self and other do not have compatible ranks.
View source
Returns the concatenation of the dimension in self and other.
View source
Returns True iff self is compatible with other.
Two possibly-partially-defined shapes are compatible if there exists a fully-defined shape that both shapes can represent. Thus, compatibility allows the shape inference code to reason about partially-defined shapes. For example:
TensorShape(None) is compatible with all shapes.
TensorShape([None, None]) is compatible with all two-dimensional shapes, such as TensorShape([32, 784]), and also TensorShape(None). It is not compatible with, for example, TensorShape([None]) or TensorShape([None, None, None]).
TensorShape([32, None]) is compatible with all two-dimensional shapes with size 32 in the 0th dimension, and also TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32]), TensorShape([32, None, 1]) or TensorShape([64, None]).
TensorShape([32, 784]) is compatible with itself, and also TensorShape([32, None]), TensorShape([None, 784]), TensorShape([None, None]) and TensorShape(None). It is not compatible with, for example, TensorShape([32, 1, 784]) or TensorShape([None]).
The compatibility relation is reflexive and symmetric, but not transitive. For example, TensorShape([32, 784]) is compatible with TensorShape(None), and TensorShape(None) is compatible with TensorShape([4, 4]), but TensorShape([32, 784]) is not compatible with TensorShape([4, 4]).
View source
Returns True iff self is fully defined in every dimension.
View source
Returns a TensorShape combining the information in self and other.
The dimensions in self and other are merged elementwise, according to the rules defined for Dimension.merge_with().
View source
Returns the most specific TensorShape compatible with self and other.
TensorShape([None, 1]) is the most specific TensorShape compatible with both TensorShape([2, 1]) and TensorShape([5, 1]). Note that TensorShape(None) is also compatible with above mentioned TensorShapes.
TensorShape([1, 2, 3]) is the most specific TensorShape compatible with both TensorShape([1, 2, 3]) and TensorShape([1, 2, 3]). There are more less specific TensorShapes compatible with above mentioned TensorShapes, e.g. TensorShape([1, 2, None]), TensorShape(None).
View source
Returns the total number of elements, or none for incomplete shapes.
View source
Returns a shape based on self with the given rank.
This method promotes a completely unknown shape to one with a known rank.
View source
Returns a shape based on self with at least the given rank.
View source
Returns a shape based on self with at most the given rank.
View source
View source
Returns True if this shape contains non-zero information.
View source
View source
Returns True if self is equivalent to other.
View source
Returns the value of a dimension or a shape, depending on the key.
View source
Returns self.dims if the rank is known, otherwise raises ValueError.
View source
Returns the rank of this shape, or raises ValueError if unspecified.
View source
Returns True if self is known to be different from other.
View source
Returns True if this shape contains non-zero information.
View source


Describes a tf.Tensor.
Inherits From: TypeSpec
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.TensorSpec
Metadata for describing the tf.Tensor objects accepted or returned by some TensorFlow APIs.
View source
View source
View source
Returns True if spec_or_tensor is compatible with this TensorSpec.
Two tensors are considered compatible if they have the same dtype and their shapes are compatible (see tf.TensorShape.is_compatible_with).
View source
Returns the most specific TypeSpec compatible with self and other.
View source
Return self==value.
View source
Return self!=value.


Adds sparse updates to an existing tensor according to indices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tensor_scatter_add, tf.compat.v1.tensor_scatter_nd_add
This operation creates a new tensor by adding sparse updates to the passed in tensor. This operation is very similar to tf.scatter_nd_add, except that the updates are added onto an existing tensor (as opposed to a variable). If the memory for the existing tensor cannot be re-used, a copy is made and updated.
indices is an integer tensor containing indices into a new tensor of shape tensor.shape. The last dimension of indices can be at most the rank of tensor.shape:
The last dimension of indices corresponds to indices into elements (if indices.shape[-1] = tensor.shape.rank) or slices (if indices.shape[-1] < tensor.shape.rank) along dimension indices.shape[-1] of tensor.shape. updates is a tensor with shape
The simplest form of tensor_scatter_add is to add individual elements to a tensor by index. For example, say we want to add 4 elements in a rank-1 tensor with 8 elements.
In Python, this scatter add operation would look like this:
The resulting tensor would look like this:
We can also, insert entire slices of a higher rank tensor all at once. For example, if we wanted to insert two slices in the first dimension of a rank-3 tensor with two matrices of new values.
In Python, this scatter add operation would look like this:
The resulting tensor would look like this:
Note that on CPU, if an out of bound index is found, an error is returned. On GPU, if an out of bound index is found, the index is ignored.


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tensor_scatter_nd_max


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tensor_scatter_nd_min


Subtracts sparse updates from an existing tensor according to indices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tensor_scatter_nd_sub, tf.compat.v1.tensor_scatter_sub
This operation creates a new tensor by subtracting sparse updates from the passed in tensor. This operation is very similar to tf.scatter_nd_sub, except that the updates are subtracted from an existing tensor (as opposed to a variable). If the memory for the existing tensor cannot be re-used, a copy is made and updated.
indices is an integer tensor containing indices into a new tensor of shape shape. The last dimension of indices can be at most the rank of shape:
The last dimension of indices corresponds to indices into elements (if indices.shape[-1] = shape.rank) or slices (if indices.shape[-1] < shape.rank) along dimension indices.shape[-1] of shape. updates is a tensor with shape
The simplest form of tensor_scatter_sub is to subtract individual elements from a tensor by index. For example, say we want to insert 4 scattered elements in a rank-1 tensor with 8 elements.
In Python, this scatter subtract operation would look like this:
The resulting tensor would look like this:
We can also, insert entire slices of a higher rank tensor all at once. For example, if we wanted to insert two slices in the first dimension of a rank-3 tensor with two matrices of new values.
In Python, this scatter add operation would look like this:
The resulting tensor would look like this:
Note that on CPU, if an out of bound index is found, an error is returned. On GPU, if an out of bound index is found, the index is ignored.


"Scatter updates into an existing tensor according to indices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tensor_scatter_nd_update, tf.compat.v1.tensor_scatter_update
This operation creates a new tensor by applying sparse updates to the input tensor. This is similar to an index assignment.
If an out of bound index is found on CPU, an error is returned.
This operation is very similar to tf.scatter_nd, except that the updates are scattered onto an existing tensor (as opposed to a zero-tensor). If the memory for the existing tensor cannot be re-used, a copy is made and updated.
Overall this leads to the following shape constraints:
Typical usage is often much simpler than this general form, and it can be better understood starting with simple examples:
The simplest usage inserts scalar elements into a tensor by index. In this case, the index_depth must equal the rank of the input tensor, slice each column of indices is an index into an axis of the input tensor.
In this simplest case the shape constraints are:
For example, to insert 4 scattered elements in a rank-1 tensor with 8 elements.
This scatter operation would look like this:
The length (first axis) of updates must equal the length of the indices: num_updates. This is the the number of updates being inserted. Each scalar update is inserted into tensor at the indexed location.
For a higher rank input tensor scalar updates can be inserted by using an index_depth that matches tf.rank(tensor):
When the input tensor has more than one axis scatter can be used to update entire slices.
In this case it's helpful to think of the input tensor as being a two level array-of-arrays. The shape of this two level array is split into the outer_shape and the inner_shape.
indices indexes into the outer level of the input tensor (outer_shape). and replaces the sub-array at that location with the coresponding item from the updates list. The shape of each update is inner_shape.
When updating a list of slices the shape constraints are:
For example, to update rows of a (6, 3) tensor:
Use an index depth of one.
The outer_shape is 6, the inner shape is 3:
2 rows are being indexed so 2 updates must be supplied. Each update must be shaped to match the inner_shape.
Alltogether this gives:
A tensor representing a batch of uniformly sized video clips naturally has 5 axes: [batch_size, time, width, height, channels].
To replace a selection of video clips:
To relace the first two clips with ones:
To replace a selection of frames in the videos:
To replace the first frame of the first three video clips:
In simple cases it's convienient to think of indices and updates as lists, but this is not a strict requirement. Instead of a flat num_updates, the indices and updates can be folded into a batch_shape. This batch_shape is all axes of the indices, except for the innermost index_depth axis.
updates must have a matching batch_shape (the axes before inner_shape).
With this generalization the full shape constraints are:
For example, to draw an X on a (5,5) matrix start with these indices:
Here the indices do not have a shape of [num_updates, index_depth], but a shape of batch_shape+[index_depth].
Since the index_depth is equal to the rank of tensor:
Putting this together gives:


Testing.
class Benchmark: Abstract class that provides helpers for TensorFlow benchmarks.
class TestCase: Base class for tests that need to test TensorFlow.
assert_equal_graph_def(...): Asserts that two GraphDefs are (mostly) the same.
benchmark_config(...): Returns a tf.compat.v1.ConfigProto for disabling the dependency optimizer.
compute_gradient(...): Computes the theoretical and numeric Jacobian of f.
create_local_cluster(...): Create and start local servers and return the associated Server objects.
gpu_device_name(...): Returns the name of a GPU device if available or the empty string.
is_built_with_cuda(...): Returns whether TensorFlow was built with CUDA (GPU) support.
is_built_with_gpu_support(...): Returns whether TensorFlow was built with GPU (i.e. CUDA or ROCm) support.
is_built_with_rocm(...): Returns whether TensorFlow was built with ROCm (GPU) support.
is_built_with_xla(...): Returns whether TensorFlow was built with XLA support.
is_gpu_available(...): Returns whether TensorFlow can access a GPU. (deprecated)
main(...): Runs all unit tests.


Asserts that two GraphDefs are (mostly) the same.
Compares two GraphDef protos for equality, ignoring versions and ordering of nodes, attrs, and control inputs. Node names are used to match up nodes between the graphs, so the naming of nodes must be consistent. This function ignores randomized attribute values that may appear in V2 checkpoints.


Abstract class that provides helpers for TensorFlow benchmarks.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.Benchmark
View source
Evaluates tensors and returns numpy values.
View source
View source
Report a benchmark.
View source
Run an op or tensor in the given session. Report the results.


Returns a tf.compat.v1.ConfigProto for disabling the dependency optimizer.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.benchmark_config


Computes the theoretical and numeric Jacobian of f.
With y = f(x), computes the theoretical and numeric Jacobian dy/dx.


Create and start local servers and return the associated Server objects.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.create_local_cluster
"PS" stands for "parameter server": a task responsible for storing and updating the model's parameters. Other tasks send updates to these parameters as they work on optimizing the parameters. This particular division of labor between tasks is not required, but is common for distributed training.
Read more at https://www.tensorflow.org/guide/extend/architecture
Figure illustrates the interaction of these components. "/job:worker/task:0" and "/job:ps/task:0" are both tasks with worker services.


Returns the name of a GPU device if available or the empty string.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.gpu_device_name


Returns whether TensorFlow was built with CUDA (GPU) support.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.is_built_with_cuda


Returns whether TensorFlow was built with GPU (i.e. CUDA or ROCm) support.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.is_built_with_gpu_support


Returns whether TensorFlow was built with ROCm (GPU) support.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.is_built_with_rocm


Returns whether TensorFlow was built with XLA support.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.is_built_with_xla


Returns whether TensorFlow can access a GPU. (deprecated)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.is_gpu_available
Note that the keyword arg name "cuda_only" is misleading (since routine will return true when a GPU device is available irrespective of whether TF was built with CUDA support or ROCm support. However no changes here because
++ Changing the name "cuda_only" to something more generic would break backward compatibility
++ Adding an equivalent "rocm_only" would require the implementation check the build type. This in turn would require doing the same for CUDA and thus potentially break backward compatibility
++ Adding a new "cuda_or_rocm_only" would not break backward compatibility, but would require most (if not all) callers to update the call to use "cuda_or_rocm_only" instead of "cuda_only"


Runs all unit tests.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.main


Base class for tests that need to test TensorFlow.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.TestCase
class failureException
Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown).
Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.
View source
Asserts that two structures of numpy arrays or Tensors, have near values.
a and b can be arbitrarily nested structures. A layer of a nested structure can be a dict, namedtuple, tuple or list.
View source
Like assertAllClose, but also suitable for comparing fp16 arrays.
In particular, the tolerance is reduced to 1e-3 if at least one of the arguments is of type float16.
View source
Asserts that two numpy arrays or Tensors have the same values.
View source
Assert element values are all greater than a target value.
View source
Assert element values are all greater than or equal to a target value.
View source
Assert that elements in a Tensor are all in a given range.
View source
Assert that elements of a Tensor are all in a given closed set.
View source
Assert element values are all less than a target value.
View source
Assert element values are all less than or equal to a target value.
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically compare almost equal.
View source
Asserts that two float arrays are near each other.
Checks that for all elements of farray1 and farray2 |f1 - f2| < err. Asserts a test failure if not.
Asserts that value is between minv and maxv (inclusive).
Asserts a shell command fails and the error matches a regex in a list.
Asserts that a shell command succeeds (i.e. exits with code 0).
Asserts that "container" contains "subsequence" as an exact subsequence.
Asserts that "container" contains all the elements of "subsequence", in order, and without other elements interspersed. For example, [1, 2, 3] is an exact subsequence of [0, 0, 1, 2, 3, 0] but not of [0, 0, 1, 2, 0, 3, 0].
Asserts that the strings provided are found in the target in order.
This may be useful for checking HTML output.
Asserts that "container" contains "subsequence" as a subsequence.
Asserts that "container" contains all the elements of "subsequence", in order, but possibly with other elements interspersed. For example, [1, 2, 3] is a subsequence of [0, 0, 1, 2, 0, 3, 0] but not of [0, 0, 1, 3, 0, 2, 0].
Checks whether actual iterable is a superset of expected iterable.
An unordered sequence comparison asserting that the same elements, regardless of order. If the same element occurs more than once, it verifies that the elements occur the same number of times.
Example:
View source
Assert ndarray data type is equal to expected.
View source
Asserts that the two given devices are the same.
Checks whether dictionary is a superset of subset.
Raises AssertionError if a and b are not equal dictionaries.
Asserts that an object has zero length.
Asserts that actual.endswith(expected_end) is True.
Fail if the two objects are unequal as determined by the '==' operator.
Check that the expression is false.
Just like self.assertTrue(a > b), but with a nicer default message.
Just like self.assertTrue(a >= b), but with a nicer default message.
Just like self.assertTrue(a in b), but with a nicer default message.
Just like self.assertTrue(a is b), but with a nicer default message.
Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
Same as self.assertTrue(obj is None), with a nicer default message.
Just like self.assertTrue(a is not b), but with a nicer default message.
Included for symmetry with assertIsNone.
An unordered sequence comparison asserting that the same elements, regardless of order. If the same element occurs more than once, it verifies that the elements occur the same number of times.
Example:
Asserts that the JSON objects defined in two strings are equal.
A summary of the differences will be included in the failure message using assertSameStructure.
Asserts that an object has the expected length.
Just like self.assertTrue(a < b), but with a nicer default message.
Just like self.assertTrue(a <= b), but with a nicer default message.
A list-specific equality assertion.
Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.
This method must be used as a context manager, and will yield a recording object with two attributes: output and records. At the end of the context manager, the output attribute will be a list of the matching formatted log messages and the records attribute will be a list of the corresponding LogRecord objects.
Example::
Asserts that two multi-line strings are equal.
View source
Asserts that two numpy arrays have near values.
View source
Asserts that two floats are near each other.
Checks that |f1 - f2| < err and asserts a test failure if not.
Checks whether actual iterable and expected iterable are disjoint.
View source
Assert that two numpy arrays, or Tensors, do not have near values.
View source
Asserts that two numpy arrays or Tensors do not have the same values.
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
Asserts that an object has non-zero length.
Asserts that actual.endswith(unexpected_end) is False.
Fail if the two objects are equal as determined by the '!=' operator.
Just like self.assertTrue(a not in b), but with a nicer default message.
Included for symmetry with assertIsInstance.
Fail the test if the text matches the regular expression.
Asserts that actual.startswith(unexpected_start) is False.
View source
Asserts that message is same as parsed expected_message_ascii.
Creates another prototype of message, reads the ascii message into it and then compares them using self._AssertProtoEqual().
View source
Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.
If called with the callable and arguments omitted, will return a context object used like this::
An optional keyword argument 'msg' can be provided when assertRaises is used as a context object.
The context manager keeps a reference to the exception as the 'exception' attribute. This allows you to inspect the exception after the assertion::
View source
Asserts that the message in a raised exception matches a regex.
Asserts that the message in a raised exception matches a regex.
Asserts that the message in a raised exception equals the given string.
Unlike assertRaisesRegex, this method takes a literal string, not a regular expression.
with self.assertRaisesWithLiteralMatch(ExType, 'message'): DoSomething()
View source
Returns a context manager to enclose code expected to raise an exception.
If the exception is an OpError, the op stack is also included in the message predicate search.
Fail the test unless the text matches the regular expression.
Asserts that at least one regex in regexes matches str.
If possible you should use assertRegex, which is a simpler version of this method. assertRegex takes a single regular expression (a string or re compiled object) instead of a list.
This function uses substring matching, i.e. the matching succeeds if any substring of the error message matches any regex in the list. This is more convenient for the user than full-string matching.
If regexes is the empty list, the matching will always fail.
Use regexes=[''] for a regex that will always pass.
'.' matches any single character except the newline. To match any character, use '(.|\n)'.
'^' matches the beginning of each line, not just the beginning of the string. Similarly, '$' matches the end of each line.
An exception will be thrown if regexes contains an invalid regex.
Asserts that two sequences have the same elements (in any order).
This method, unlike assertCountEqual, doesn't care about any duplicates in the expected and actual sequences.
assertSameElements([1, 1, 1, 0, 0, 0], [0, 1]) # Doesn't raise an AssertionError
If possible, you should use assertCountEqual instead of assertSameElements.
Asserts that two values contain the same structural content.
The two arguments should be data trees consisting of trees of dicts and lists. They will be deeply compared by walking into the contents of dicts and lists; other items will be compared using the == operator. If the two structures differ in content, the failure message will indicate the location within the structures where the first difference is found. This may be helpful when comparing large structures.
Mixed Sequence and Set types are supported. Mixed Mapping types are supported, but the order of the keys will not be considered in the comparison.
An approximate equality assertion for ordered sequences.
Fail if the two sequences are unequal as determined by their value differences rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between each value in the two sequences is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two sequences compare equal then they will automatically compare almost equal.
An equality assertion for ordered sequences (like lists and tuples).
For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.
An equality assertion for the beginning of ordered sequences.
If prefix is an empty sequence, it will raise an error unless whole is also an empty sequence.
If prefix is not a sequence, it will raise an error if the first element of whole does not match.
A set-specific equality assertion.
assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).
View source
Asserts that a Numpy ndarray and a TensorFlow tensor have the same shape.
View source
Assert that actual.startswith(expected_start) is True.
Asserts that total ordering has been implemented correctly.
For example, say you have a class A that compares only on its attribute x. Comparators other than lt are omitted for brevity.
class A(object): def init(self, x, y): self.x = x self.y = y
def hash(self): return hash(self.x)
def lt(self, other): try: return self.x < other.x except AttributeError: return NotImplemented
assertTotallyOrdered will check that instances can be ordered correctly. For example,
self.assertTotallyOrdered( [None], # None should come before everything else. [1], # Integers sort earlier. [A(1, 'a')], [A(2, 'b')], # 2 is after 1. [A(3, 'c'), A(3, 'd')], # The second argument is irrelevant. [A(4, 'z')], ['foo']) # Strings sort last.
Check that the expression is true.
A tuple-specific equality assertion.
Asserts that urls are equal, ignoring ordering of query params.
Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception.
If called with the callable and arguments omitted, will return a context object used like this::
An optional keyword argument 'msg' can be provided when assertWarns is used as a context object.
The context manager keeps a reference to the first matching warning as the 'warning' attribute; similarly, the 'filename' and 'lineno' attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion::
Asserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches.
View source
Returns a TensorFlow Session for use in executing tests.
This method behaves differently than self.session(): for performance reasons cached_session will by default reuse the same session within the same test. The session returned by this function will only be closed at the end of the test (in the TearDown function).
Use the use_gpu and force_gpu options to control where ops are run. If force_gpu is True, all ops are pinned to /device:GPU:0. Otherwise, if use_gpu is True, TensorFlow tries to run as many ops on the GPU as possible. If both force_gpu anduse_gpu` are False, all ops are pinned to the CPU.
View source
A context manager that captures the writes to a given stream.
This context manager captures all writes to a given stream inside of a CapturedWrites object. When this context manager is created, it yields the CapturedWrites object. The captured contents can be accessed by calling .contents() on the CapturedWrites.
For this function to work, the stream must have a file descriptor that can be modified using os.dup and os.dup2, and the stream must support a .flush() method. The default python sys.stdout and sys.stderr are examples of this. Note that this does not work in Colab or Jupyter notebooks, because those use alternate stdout streams.
View source
Returns a Thread wrapper that asserts 'target' completes successfully.
This method should be used to create all threads in test cases, as otherwise there is a risk that a thread will silently fail, and/or assertions made in the thread will not be respected.
Create a temporary directory specific to the test.
This creates a named directory on disk that is isolated to this test, and will be properly cleaned up by the test. This avoids several pitfalls of creating temporary directories for test purposes, as well as makes it easier to setup directories and verify their contents. For example:
See also: create_tempfile() for creating temporary files.
Create a temporary file specific to the test.
This creates a named file on disk that is isolated to this test, and will be properly cleaned up by the test. This avoids several pitfalls of creating temporary files for test purposes, as well as makes it easier to setup files, their data, read them back, and inspect them when a test fails. For example:
See also: create_tempdir() for creating temporary directories, and _TempDir.create_file for creating files within a temporary directory.
Run the test without collecting errors in a TestResult
Execute all cleanup functions. Normally called for you after tearDown.
Returns the CM's value after registering it with the exit stack.
Entering a context pushes it onto a stack of contexts. The context is exited when the test completes. Contexts are are exited in the reverse order of entering. They will always be exited, regardless of test failure/success. The context stack is specific to the test being run.
This is useful to eliminate per-test boilerplate when context managers are used. For example, instead of decorating every test with @mock.patch, simply do self.foo = self.enter_context(mock.patch(...))' insetUp()`.
View source
Evaluates tensors and returns numpy values.
Fail immediately with the given message, optionally prefixed.
View source
Returns a unique temporary directory for the test to use.
If you call this method multiple times during in a test, it will return the same folder. However, across different runs the directories will be different. This will ensure that across different runs tests will not be able to pollute each others environment. If you need multiple unique directories within a single test, you should use tempfile.mkdtemp as follows: tempfile.mkdtemp(dir=self.get_temp_dir()):
View source
A context manager for a TensorFlow Session for use in executing tests.
Note that this will set this session and the graph as global defaults.
Use the use_gpu and force_gpu options to control where ops are run. If force_gpu is True, all ops are pinned to /device:GPU:0. Otherwise, if use_gpu is True, TensorFlow tries to run as many ops on the GPU as possible. If both force_gpu anduse_gpu` are False, all ops are pinned to the CPU.
View source
Hook method for setting up the test fixture before exercising it.
Hook method for setting up class fixture before running tests in the class.
Formats both the test method name and the first line of its docstring.
If no docstring is given, only returns the method name.
This method overrides unittest.TestCase.shortDescription(), which only returns the first line of the docstring, obscuring the name of the test upon failure.
Skip this test.
Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed.
View source
Hook method for deconstructing the test fixture after testing it.
Hook method for deconstructing the class fixture after running all tests in the class.
View source
Use cached_session instead. (deprecated)
Call self as a function.
Return self==value.


Assertion failed.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.test.TestCase.failureException


Constructs a tensor by tiling a given tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.manip.tile, tf.compat.v1.tile
This operation creates a new tensor by replicating input multiples times. The output tensor's i'th dimension has input.dims(i) * multiples[i] elements, and the values of input are replicated multiples[i] times along the 'i'th dimension. For example, tiling [a b c d] by [2] produces [a b c d a b c d].


Provides the time since epoch in seconds.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.timestamp
Returns the timestamp as a float64 for seconds since the Unix epoch.


Ops related to Tensor Processing Units.
experimental module: Public API for tf.tpu.experimental namespace.


Public API for tf.tpu.experimental namespace.
embedding module: Public API for tf.tpu.experimental.embedding namespace.
class DeviceAssignment: Mapping from logical cores in a computation to the physical TPU topology.
class TPUSystemMetadata: Describes some metadata about the TPU system.
class Topology: Describes a set of TPU devices.
initialize_tpu_system(...): Initialize the TPU devices.
shutdown_tpu_system(...): Shuts down the TPU devices.


Mapping from logical cores in a computation to the physical TPU topology.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.DeviceAssignment
Prefer to use the DeviceAssignment.build() helper to construct a DeviceAssignment; it is easier if less flexible than constructing a DeviceAssignment directly.
View source
View source
Returns the physical topology coordinates of a logical core.
View source
Returns the CPU device attached to a logical core.
View source
Lookup replica ids by task number and logical core.
View source
Returns the name of the TPU device assigned to a logical core.
View source
Returns the ordinal of the TPU device assigned to a logical core.


Public API for tf.tpu.experimental.embedding namespace.
class Adagrad: Optimization parameters for Adagrad with TPU embeddings.
class Adam: Optimization parameters for Adam with TPU embeddings.
class FeatureConfig: Configuration data for one embedding feature.
class SGD: Optimization parameters for stochastic gradient descent for TPU embeddings.
class TPUEmbedding: The TPUEmbedding mid level API.
class TableConfig: Configuration data for one embedding table.
serving_embedding_lookup(...): Apply standard lookup ops with tf.tpu.experimental.embedding configs.


Optimization parameters for Adagrad with TPU embeddings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.Adagrad
Pass this to tf.tpu.experimental.embedding.TPUEmbedding via the optimizer argument to set the global optimizer and its parameters:
This can also be used in a tf.tpu.experimental.embedding.TableConfig as the optimizer parameter to set a table specific optimizer. This will override the optimizer and parameters for global embedding optimizer defined above:
In the above example, the first feature will be looked up in a table that has a learning rate of 0.2 while the second feature will be looked up in a table that has a learning rate of 0.1.
See 'tensorflow/core/protobuf/tpu/optimization_parameters.proto' for a complete description of these parameters and their impacts on the optimizer algorithm.


Optimization parameters for Adam with TPU embeddings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.Adam
Pass this to tf.tpu.experimental.embedding.TPUEmbedding via the optimizer argument to set the global optimizer and its parameters:
This can also be used in a tf.tpu.experimental.embedding.TableConfig as the optimizer parameter to set a table specific optimizer. This will override the optimizer and parameters for global embedding optimizer defined above:
In the above example, the first feature will be looked up in a table that has a learning rate of 0.2 while the second feature will be looked up in a table that has a learning rate of 0.1.
See 'tensorflow/core/protobuf/tpu/optimization_parameters.proto' for a complete description of these parameters and their impacts on the optimizer algorithm.


Configuration data for one embedding feature.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.FeatureConfig
This class holds the configuration data for a single embedding feature. The main use is to assign features to tf.tpu.experimental.embedding.TableConfigs via the table parameter:
The above configuration has 2 tables, and three features. The first two features will be looked up in the first table and the third feature will be looked up in the second table.
When feeding features into embedding.enqueue they can be tf.Tensors, tf.SparseTensors or tf.RaggedTensors. When the argument max_sequence_length is 0, the default, you should expect a output of embedding.dequeue for this feature of shape (batch_size, dim). If max_sequence_length is greater than 0, the feature is embedded as a sequence and padded up to the given length. The shape of the output for this feature will be (batch_size, max_sequence_length, dim).


Apply standard lookup ops with tf.tpu.experimental.embedding configs.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.serving_embedding_lookup
This function is a utility which allows using the tf.tpu.experimental.embedding config objects with standard lookup functions. This can be used when exporting a model which uses tf.tpu.experimental.embedding.TPUEmbedding for serving on CPU. In particular tf.tpu.experimental.embedding.TPUEmbedding only supports lookups on TPUs and should not be part of your serving graph.
Note that TPU specific options (such as max_sequence_length) in the configuration objects will be ignored.
In the following example we take take a trained model (see the documentation for tf.tpu.experimental.embedding.TPUEmbedding for the context) and create a saved model with a serving function that will perform the embedding lookup and pass the results to your model:


Optimization parameters for stochastic gradient descent for TPU embeddings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.SGD
Pass this to tf.tpu.experimental.embedding.TPUEmbedding via the optimizer argument to set the global optimizer and its parameters:
This can also be used in a tf.tpu.experimental.embedding.TableConfig as the optimizer parameter to set a table specific optimizer. This will override the optimizer and parameters for global embedding optimizer defined above:
In the above example, the first feature will be looked up in a table that has a learning rate of 0.2 while the second feature will be looked up in a table that has a learning rate of 0.1.
See 'tensorflow/core/protobuf/tpu/optimization_parameters.proto' for a complete description of these parameters and their impacts on the optimizer algorithm.


Configuration data for one embedding table.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.TableConfig
This class holds the configuration data for a single embedding table. It is used as the table parameter of a tf.tpu.experimental.embedding.FeatureConfig. Multiple tf.tpu.experimental.embedding.FeatureConfig objects can use the same tf.tpu.experimental.embedding.TableConfig object. In this case a shared table will be created for those feature lookups.
The above configuration has 2 tables, and three features. The first two features will be looked up in the first table and the third feature will be looked up in the second table.


The TPUEmbedding mid level API.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.embedding.TPUEmbedding
This class can be used to support training large embeddings on TPU. When creating an instance of this class, you must specify the complete set of tables and features you expect to lookup in those tables. See the documentation of tf.tpu.experimental.embedding.TableConfig and tf.tpu.experimental.embedding.FeatureConfig for more details on the complete set of options. We will cover the basic usage here.
There are two modes under which the TPUEmbedding class can used. This depends on if the class was created under a TPUStrategy scope or not.
Under TPUStrategy, we allow access to the method enqueue, dequeue and apply_gradients. We will show examples below of how to use these to train and evaluate your model. Under CPU, we only access to the embedding_tables property which allow access to the embedding tables so that you can use them to run model evaluation/prediction on CPU.
First lets look at the TPUStrategy mode. Initial setup looks like:
When creating a distributed dataset that is to be passed to the enqueue operation a special input option must be specified:
To use this API on TPU you should use a custom training loop. Below is an example of a training and evaluation step:
In the above examples, we assume that the user has a dataset which returns a tuple where the first element of the tuple matches the structure of what was passed as the feature_config argument to the object initializer. Also we utilize tf.range to get a tf.while_loop in order to increase performance.
When checkpointing your model, you should include your tf.tpu.experimental.embedding.TPUEmbedding object in the checkpoint. It is a trackable object and saving it will save the embedding tables and their optimizer slot variables:
On CPU, only the embedding_table property is usable. This will allow you to restore a checkpoint to the object and have access to the table variables:
You can now use table in functions like tf.nn.embedding_lookup to perform your embedding lookup and pass to your model.
This property only works when the TPUEmbedding object is created under a non-TPU strategy. This is intended to be used to for CPU based lookup when creating a serving checkpoint.
View source
Applies the gradient update to the embedding tables.
If a gradient of None is passed in any position of the nested structure, then an gradient update with a zero gradient is applied for that feature. For optimizers like SGD or Adagrad, this is the same as applying no update at all. For lazy Adam and other sparsely applied optimizers with decay, ensure you understand the effect of applying a zero gradient.
View source
Create the underlying variables and initializes the TPU for embeddings.
This method creates the underlying variables (including slot variables). If created under a TPUStrategy, this will also initialize the TPU for embeddings.
This function will automatically get called by enqueue, which will try to determine your batch size automatically. If this fails, you must manually call this method before you call enqueue.
View source
Get the embedding results.
Returns a nested structure of tf.Tensor objects, matching the structure of the feature_config argument to the TPUEmbedding class. The output shape of the tensors is (batch_size, dim), where batch_size is the per core batch size, dim is the dimension of the corresponding TableConfig. If the feature's corresponding FeatureConfig has max_sequence_length greater than 0, the output will be a sequence of shape (batch_size, max_sequence_length, dim) instead.
passed to this instance of the TPUEmbedding object.
View source
Enqueues id tensors for embedding lookup.
This function enqueues a structure of features to be looked up in the embedding tables. We expect that the batch size of each of the tensors in features matches the per core batch size. This will automatically happen if your input dataset is batched to the global batch size and you use tf.distribute.TPUStrategy's experimental_distribute_dataset or if you use distribute_datasets_from_function and batch to the per core batch size computed by the context passed to your input function.


Initialize the TPU devices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.initialize_tpu_system


Shuts down the TPU devices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.shutdown_tpu_system
This will clear all caches, even those that are maintained through sequential calls to tf.tpu.experimental.initialize_tpu_system, such as the compilation cache.


Describes a set of TPU devices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.Topology
Represents both the shape of the physical mesh, and the mapping between TensorFlow TPU devices to physical mesh coordinates.
View source
Returns the CPU device attached to a logical core.
View source
Returns the serialized form of the topology.
View source
Returns the TensorFlow task number attached to device_coordinates.
View source
Returns the name of the TPU device assigned to a logical core.
View source
Returns the TensorFlow device number at device_coordinates.


Describes some metadata about the TPU system.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.tpu.experimental.TPUSystemMetadata


Support for training models.
See the Training guide.
experimental module: Public API for tf.train.experimental namespace.
class BytesList: A ProtocolMessage
class Checkpoint: Manages saving/restoring trackable values to disk.
class CheckpointManager: Manages multiple checkpoints by keeping some and deleting unneeded ones.
class CheckpointOptions: Options for constructing a Checkpoint.
class ClusterDef: A ProtocolMessage
class ClusterSpec: Represents a cluster as a set of "tasks", organized into "jobs".
class Coordinator: A coordinator for threads.
class Example: A ProtocolMessage
class ExponentialMovingAverage: Maintains moving averages of variables by employing an exponential decay.
class Feature: A ProtocolMessage
class FeatureList: A ProtocolMessage
class FeatureLists: A ProtocolMessage
class Features: A ProtocolMessage
class FloatList: A ProtocolMessage
class Int64List: A ProtocolMessage
class JobDef: A ProtocolMessage
class SequenceExample: A ProtocolMessage
class ServerDef: A ProtocolMessage
checkpoints_iterator(...): Continuously yield new checkpoint files as they appear.
get_checkpoint_state(...): Returns CheckpointState proto from the "checkpoint" file.
latest_checkpoint(...): Finds the filename of latest saved checkpoint file.
list_variables(...): Lists the checkpoint keys and shapes of variables in a checkpoint.
load_checkpoint(...): Returns CheckpointReader for checkpoint found in ckpt_dir_or_file.
load_variable(...): Returns the tensor value of the given variable in the checkpoint.


A ProtocolMessage
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.train.BytesList