id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
227,800 | tensorflow/mesh | mesh_tensorflow/transformer/transformer_layers.py | attention_params | def attention_params(context,
kv_dim,
num_heads,
num_memory_heads=0,
shared_kv=False):
"""Attention Parameters for Transformer Layers.
The num_heads argument indicates the number of read-heads.
For the familiar behavior describe... | python | def attention_params(context,
kv_dim,
num_heads,
num_memory_heads=0,
shared_kv=False):
"""Attention Parameters for Transformer Layers.
The num_heads argument indicates the number of read-heads.
For the familiar behavior describe... | [
"def",
"attention_params",
"(",
"context",
",",
"kv_dim",
",",
"num_heads",
",",
"num_memory_heads",
"=",
"0",
",",
"shared_kv",
"=",
"False",
")",
":",
"if",
"num_heads",
"==",
"1",
":",
"query_heads_dims",
"=",
"None",
"memory_heads_dims",
"=",
"None",
"el... | Attention Parameters for Transformer Layers.
The num_heads argument indicates the number of read-heads.
For the familiar behavior described in "Attention Is All You Need", set
num_memory_heads=0.
If num_memory_heads==1, then there is only a single write-head, and multiple
read-heads. This leads to faster ... | [
"Attention",
"Parameters",
"for",
"Transformer",
"Layers",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/transformer_layers.py#L62-L116 |
227,801 | tensorflow/mesh | mesh_tensorflow/transformer/metric_utils.py | get_metric_fns | def get_metric_fns(metric_names, labels, outputs):
"""Generate a dictionary of metric name to metric function.
Args:
metric_names: list of strings in the format "prefix/metric_function_name".
metric_function_name should refer to a function name in metrics.py. The
prefix will be included in the key ... | python | def get_metric_fns(metric_names, labels, outputs):
"""Generate a dictionary of metric name to metric function.
Args:
metric_names: list of strings in the format "prefix/metric_function_name".
metric_function_name should refer to a function name in metrics.py. The
prefix will be included in the key ... | [
"def",
"get_metric_fns",
"(",
"metric_names",
",",
"labels",
",",
"outputs",
")",
":",
"metric_fns",
"=",
"{",
"}",
"for",
"metric_name",
"in",
"metric_names",
":",
"metric_fn_name",
"=",
"metric_name",
".",
"split",
"(",
"\"/\"",
")",
"[",
"-",
"1",
"]",
... | Generate a dictionary of metric name to metric function.
Args:
metric_names: list of strings in the format "prefix/metric_function_name".
metric_function_name should refer to a function name in metrics.py. The
prefix will be included in the key in the returned dict.
labels: a tensor where batch i... | [
"Generate",
"a",
"dictionary",
"of",
"metric",
"name",
"to",
"metric",
"function",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/metric_utils.py#L28-L50 |
227,802 | tensorflow/mesh | mesh_tensorflow/auto_mtf/scheduler.py | minimize_peak_memory | def minimize_peak_memory(graph, scheduler_alg):
"""Computes a schedule to minimize peak memory.
Args:
graph: an mtf.auto_mtf.graph_interface.GraphInterface.
scheduler_alg: a string, one of 'NAIVE' or 'LIST'
Returns:
an iterable of integers representing the schedule.
"""
if scheduler_alg == 'NAIV... | python | def minimize_peak_memory(graph, scheduler_alg):
"""Computes a schedule to minimize peak memory.
Args:
graph: an mtf.auto_mtf.graph_interface.GraphInterface.
scheduler_alg: a string, one of 'NAIVE' or 'LIST'
Returns:
an iterable of integers representing the schedule.
"""
if scheduler_alg == 'NAIV... | [
"def",
"minimize_peak_memory",
"(",
"graph",
",",
"scheduler_alg",
")",
":",
"if",
"scheduler_alg",
"==",
"'NAIVE'",
":",
"return",
"_minimize_peak_memory_naive",
"(",
"graph",
")",
"elif",
"scheduler_alg",
"==",
"'LIST'",
":",
"return",
"_minimize_peak_memory_list",
... | Computes a schedule to minimize peak memory.
Args:
graph: an mtf.auto_mtf.graph_interface.GraphInterface.
scheduler_alg: a string, one of 'NAIVE' or 'LIST'
Returns:
an iterable of integers representing the schedule. | [
"Computes",
"a",
"schedule",
"to",
"minimize",
"peak",
"memory",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/scheduler.py#L35-L52 |
227,803 | tensorflow/mesh | mesh_tensorflow/auto_mtf/scheduler.py | _minimize_peak_memory_list | def _minimize_peak_memory_list(graph):
"""Computes schedule according to the greedy list heuristic.
Greedy list heuristic: schedule the operation which results in the most bytes
of memory being (immediately) freed.
TODO(joshuawang): Experiment with tiebreaking by preferring more successors.
Args:
graph:... | python | def _minimize_peak_memory_list(graph):
"""Computes schedule according to the greedy list heuristic.
Greedy list heuristic: schedule the operation which results in the most bytes
of memory being (immediately) freed.
TODO(joshuawang): Experiment with tiebreaking by preferring more successors.
Args:
graph:... | [
"def",
"_minimize_peak_memory_list",
"(",
"graph",
")",
":",
"schedule",
"=",
"[",
"]",
"bytes_freed",
"=",
"{",
"}",
"# {operation_name: bytes freed}",
"users_of",
"=",
"collections",
".",
"defaultdict",
"(",
"set",
")",
"# {tensor_name: set(operation_name)}",
"in_de... | Computes schedule according to the greedy list heuristic.
Greedy list heuristic: schedule the operation which results in the most bytes
of memory being (immediately) freed.
TODO(joshuawang): Experiment with tiebreaking by preferring more successors.
Args:
graph: an mtf.auto_mtf.graph_interface.GraphInterf... | [
"Computes",
"schedule",
"according",
"to",
"the",
"greedy",
"list",
"heuristic",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/scheduler.py#L67-L154 |
227,804 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout.py | layout | def layout(mtf_graph, mesh_shape, mtf_outputs=()):
"""Compute layout rules based on a computational graph and mesh shape.
Args:
mtf_graph: a mtf.Graph.
mesh_shape: an mtf.Shape, str, or listlike of mtf.Dimension.
mtf_outputs: an optional iterable of mtf.Tensor, representing the outputs
of the c... | python | def layout(mtf_graph, mesh_shape, mtf_outputs=()):
"""Compute layout rules based on a computational graph and mesh shape.
Args:
mtf_graph: a mtf.Graph.
mesh_shape: an mtf.Shape, str, or listlike of mtf.Dimension.
mtf_outputs: an optional iterable of mtf.Tensor, representing the outputs
of the c... | [
"def",
"layout",
"(",
"mtf_graph",
",",
"mesh_shape",
",",
"mtf_outputs",
"=",
"(",
")",
")",
":",
"mesh_shape",
"=",
"mtf",
".",
"convert_to_shape",
"(",
"mesh_shape",
")",
"estimator",
"=",
"memory_estimator",
".",
"MemoryEstimator",
"(",
"mtf_graph",
",",
... | Compute layout rules based on a computational graph and mesh shape.
Args:
mtf_graph: a mtf.Graph.
mesh_shape: an mtf.Shape, str, or listlike of mtf.Dimension.
mtf_outputs: an optional iterable of mtf.Tensor, representing the outputs
of the computation.
Returns:
a mtf.LayoutRules | [
"Compute",
"layout",
"rules",
"based",
"on",
"a",
"computational",
"graph",
"and",
"mesh",
"shape",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout.py#L47-L63 |
227,805 | tensorflow/mesh | mesh_tensorflow/optimize.py | Optimizer.apply_grads | def apply_grads(self, grads, variables):
"""Apply gradients to variables.
Call this function externally instead of apply_grad(). This causes the
operations to be combined, which is necessary for stacking variables
see mtf.rewrite_stack_variables().
Args:
grads: a list of Tensor
variab... | python | def apply_grads(self, grads, variables):
"""Apply gradients to variables.
Call this function externally instead of apply_grad(). This causes the
operations to be combined, which is necessary for stacking variables
see mtf.rewrite_stack_variables().
Args:
grads: a list of Tensor
variab... | [
"def",
"apply_grads",
"(",
"self",
",",
"grads",
",",
"variables",
")",
":",
"ops",
"=",
"[",
"]",
"for",
"grad",
",",
"var",
"in",
"zip",
"(",
"grads",
",",
"variables",
")",
":",
"ops",
".",
"extend",
"(",
"self",
".",
"apply_grad",
"(",
"grad",
... | Apply gradients to variables.
Call this function externally instead of apply_grad(). This causes the
operations to be combined, which is necessary for stacking variables
see mtf.rewrite_stack_variables().
Args:
grads: a list of Tensor
variables: a list of Variables
Returns:
a li... | [
"Apply",
"gradients",
"to",
"variables",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/optimize.py#L39-L57 |
227,806 | tensorflow/mesh | mesh_tensorflow/optimize.py | AdafactorOptimizer._factored_dims | def _factored_dims(self, shape):
"""Should we use a factored second moment estimator.
Based on the shape of the variable.
If we factor the accumulator, then this function returns a list of two
mtf.Dimensions to reduce over. We always pick the two largest dimensions.
If there are not two dimensions... | python | def _factored_dims(self, shape):
"""Should we use a factored second moment estimator.
Based on the shape of the variable.
If we factor the accumulator, then this function returns a list of two
mtf.Dimensions to reduce over. We always pick the two largest dimensions.
If there are not two dimensions... | [
"def",
"_factored_dims",
"(",
"self",
",",
"shape",
")",
":",
"if",
"not",
"self",
".",
"_factored",
"or",
"shape",
".",
"ndims",
"<",
"2",
":",
"return",
"None",
"sorted_dims",
"=",
"sorted",
"(",
"shape",
".",
"dims",
",",
"key",
"=",
"lambda",
"d"... | Should we use a factored second moment estimator.
Based on the shape of the variable.
If we factor the accumulator, then this function returns a list of two
mtf.Dimensions to reduce over. We always pick the two largest dimensions.
If there are not two dimensions of size >= min_dim_size_to_factor, then... | [
"Should",
"we",
"use",
"a",
"factored",
"second",
"moment",
"estimator",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/optimize.py#L139-L158 |
227,807 | tensorflow/mesh | mesh_tensorflow/auto_mtf/valid_layouts.py | LayoutValidator.is_valid_assignment | def is_valid_assignment(self, mtf_dimension_name, mesh_dimension_name):
"""Whether this MTF dimension may be assigned to this mesh dimension.
Args:
mtf_dimension_name: string, the name of a Mesh TensorFlow dimension.
mesh_dimension_name: string, the name of a mesh dimension.
Returns:
A b... | python | def is_valid_assignment(self, mtf_dimension_name, mesh_dimension_name):
"""Whether this MTF dimension may be assigned to this mesh dimension.
Args:
mtf_dimension_name: string, the name of a Mesh TensorFlow dimension.
mesh_dimension_name: string, the name of a mesh dimension.
Returns:
A b... | [
"def",
"is_valid_assignment",
"(",
"self",
",",
"mtf_dimension_name",
",",
"mesh_dimension_name",
")",
":",
"return",
"(",
"(",
"mtf_dimension_name",
"in",
"self",
".",
"_splittable_mtf_dimension_names",
")",
"and",
"(",
"self",
".",
"_mtf_dimension_name_to_size_gcd",
... | Whether this MTF dimension may be assigned to this mesh dimension.
Args:
mtf_dimension_name: string, the name of a Mesh TensorFlow dimension.
mesh_dimension_name: string, the name of a mesh dimension.
Returns:
A boolean indicating whether the assignment is valid. | [
"Whether",
"this",
"MTF",
"dimension",
"may",
"be",
"assigned",
"to",
"this",
"mesh",
"dimension",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/valid_layouts.py#L83-L95 |
227,808 | tensorflow/mesh | mesh_tensorflow/auto_mtf/valid_layouts.py | LayoutValidator._initialize_splittable_dimensions | def _initialize_splittable_dimensions(self, mtf_graph):
"""Initializer for self._splittable_mtf_dimension_names.
Args:
mtf_graph: an mtf.Graph.
Returns:
A set(string) of the names of Mesh TensorFlow dimensions that may be
assigned in a layout.
"""
all_mtf_dimension_names = set() ... | python | def _initialize_splittable_dimensions(self, mtf_graph):
"""Initializer for self._splittable_mtf_dimension_names.
Args:
mtf_graph: an mtf.Graph.
Returns:
A set(string) of the names of Mesh TensorFlow dimensions that may be
assigned in a layout.
"""
all_mtf_dimension_names = set() ... | [
"def",
"_initialize_splittable_dimensions",
"(",
"self",
",",
"mtf_graph",
")",
":",
"all_mtf_dimension_names",
"=",
"set",
"(",
")",
"# set(string)",
"for",
"mtf_operation",
"in",
"mtf_graph",
".",
"operations",
":",
"for",
"mtf_tensor",
"in",
"mtf_operation",
".",... | Initializer for self._splittable_mtf_dimension_names.
Args:
mtf_graph: an mtf.Graph.
Returns:
A set(string) of the names of Mesh TensorFlow dimensions that may be
assigned in a layout. | [
"Initializer",
"for",
"self",
".",
"_splittable_mtf_dimension_names",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/valid_layouts.py#L97-L118 |
227,809 | tensorflow/mesh | mesh_tensorflow/auto_mtf/valid_layouts.py | LayoutValidator._initialize_mtf_dimension_name_to_size_gcd | def _initialize_mtf_dimension_name_to_size_gcd(self, mtf_graph):
"""Initializer for self._mtf_dimension_name_to_size_gcd.
Args:
mtf_graph: an mtf.Graph.
Returns:
A {string: int}, mapping the name of an MTF dimension to the greatest
common divisor of all the sizes it has. All these sizes ... | python | def _initialize_mtf_dimension_name_to_size_gcd(self, mtf_graph):
"""Initializer for self._mtf_dimension_name_to_size_gcd.
Args:
mtf_graph: an mtf.Graph.
Returns:
A {string: int}, mapping the name of an MTF dimension to the greatest
common divisor of all the sizes it has. All these sizes ... | [
"def",
"_initialize_mtf_dimension_name_to_size_gcd",
"(",
"self",
",",
"mtf_graph",
")",
":",
"mtf_dimension_name_to_size_gcd",
"=",
"{",
"}",
"for",
"mtf_operation",
"in",
"mtf_graph",
".",
"operations",
":",
"for",
"mtf_tensor",
"in",
"mtf_operation",
".",
"outputs"... | Initializer for self._mtf_dimension_name_to_size_gcd.
Args:
mtf_graph: an mtf.Graph.
Returns:
A {string: int}, mapping the name of an MTF dimension to the greatest
common divisor of all the sizes it has. All these sizes being evenly
divisible by some x is equivalent to the GCD being di... | [
"Initializer",
"for",
"self",
".",
"_mtf_dimension_name_to_size_gcd",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/valid_layouts.py#L120-L140 |
227,810 | tensorflow/mesh | mesh_tensorflow/auto_mtf/valid_layouts.py | LayoutValidator._initialize_mesh_dimension_name_to_size | def _initialize_mesh_dimension_name_to_size(self, mesh_shape):
"""Initializer for self._mesh_dimension_name_to_size.
Args:
mesh_shape: an mtf.Shape.
Returns:
A {string: int} mapping mesh dimension names to their sizes.
"""
mesh_dimension_name_to_size = {} # {string: int}
for mesh_... | python | def _initialize_mesh_dimension_name_to_size(self, mesh_shape):
"""Initializer for self._mesh_dimension_name_to_size.
Args:
mesh_shape: an mtf.Shape.
Returns:
A {string: int} mapping mesh dimension names to their sizes.
"""
mesh_dimension_name_to_size = {} # {string: int}
for mesh_... | [
"def",
"_initialize_mesh_dimension_name_to_size",
"(",
"self",
",",
"mesh_shape",
")",
":",
"mesh_dimension_name_to_size",
"=",
"{",
"}",
"# {string: int}",
"for",
"mesh_dimension",
"in",
"mesh_shape",
".",
"dims",
":",
"mesh_dimension_name_to_size",
"[",
"mesh_dimension"... | Initializer for self._mesh_dimension_name_to_size.
Args:
mesh_shape: an mtf.Shape.
Returns:
A {string: int} mapping mesh dimension names to their sizes. | [
"Initializer",
"for",
"self",
".",
"_mesh_dimension_name_to_size",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/valid_layouts.py#L142-L154 |
227,811 | tensorflow/mesh | mesh_tensorflow/placement_mesh_impl.py | allconcat_ring | def allconcat_ring(xs, devices, concat_axis):
"""Concatenate all Tensors everywhere.
Performance-optimized for a ring of devices.
Args:
xs: a list of n tf.Tensors
devices: a list of n strings
concat_axis: an integer
Returns:
a list of n Tensors
"""
n = len(xs)
if n == 1:
return xs
... | python | def allconcat_ring(xs, devices, concat_axis):
"""Concatenate all Tensors everywhere.
Performance-optimized for a ring of devices.
Args:
xs: a list of n tf.Tensors
devices: a list of n strings
concat_axis: an integer
Returns:
a list of n Tensors
"""
n = len(xs)
if n == 1:
return xs
... | [
"def",
"allconcat_ring",
"(",
"xs",
",",
"devices",
",",
"concat_axis",
")",
":",
"n",
"=",
"len",
"(",
"xs",
")",
"if",
"n",
"==",
"1",
":",
"return",
"xs",
"# [target, source]",
"parts",
"=",
"[",
"[",
"xs",
"[",
"target",
"]",
"if",
"target",
"=... | Concatenate all Tensors everywhere.
Performance-optimized for a ring of devices.
Args:
xs: a list of n tf.Tensors
devices: a list of n strings
concat_axis: an integer
Returns:
a list of n Tensors | [
"Concatenate",
"all",
"Tensors",
"everywhere",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/placement_mesh_impl.py#L462-L491 |
227,812 | tensorflow/mesh | mesh_tensorflow/placement_mesh_impl.py | PlacementMeshImpl.Print | def Print(self, x, data, message, **kwargs): # pylint: disable=invalid-name
"""call tf.Print.
Args:
x: a LaidOutTensor
data: a list of LaidOutTensor
message: a string
**kwargs: keyword arguments to tf.print
Returns:
a LaidOutTensor
"""
tf.logging.info("PlacementMeshIm... | python | def Print(self, x, data, message, **kwargs): # pylint: disable=invalid-name
"""call tf.Print.
Args:
x: a LaidOutTensor
data: a list of LaidOutTensor
message: a string
**kwargs: keyword arguments to tf.print
Returns:
a LaidOutTensor
"""
tf.logging.info("PlacementMeshIm... | [
"def",
"Print",
"(",
"self",
",",
"x",
",",
"data",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=invalid-name",
"tf",
".",
"logging",
".",
"info",
"(",
"\"PlacementMeshImpl::Print\"",
")",
"new_slices",
"=",
"x",
".",
"tensor_list",
... | call tf.Print.
Args:
x: a LaidOutTensor
data: a list of LaidOutTensor
message: a string
**kwargs: keyword arguments to tf.print
Returns:
a LaidOutTensor | [
"call",
"tf",
".",
"Print",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/placement_mesh_impl.py#L185-L202 |
227,813 | tensorflow/mesh | mesh_tensorflow/placement_mesh_impl.py | PlacementMeshImpl.alltoall | def alltoall(self, x, mesh_axis, split_axis, concat_axis):
"""Grouped alltoall.
Args:
x: a LaidOutTensor
mesh_axis: an integer the mesh axis along which to group
split_axis: an integer (the Tensor axis along which to split)
concat_axis: an integer (the Tensor axis along which to concate... | python | def alltoall(self, x, mesh_axis, split_axis, concat_axis):
"""Grouped alltoall.
Args:
x: a LaidOutTensor
mesh_axis: an integer the mesh axis along which to group
split_axis: an integer (the Tensor axis along which to split)
concat_axis: an integer (the Tensor axis along which to concate... | [
"def",
"alltoall",
"(",
"self",
",",
"x",
",",
"mesh_axis",
",",
"split_axis",
",",
"concat_axis",
")",
":",
"return",
"self",
".",
"_collective_with_groups",
"(",
"x",
",",
"[",
"mesh_axis",
"]",
",",
"functools",
".",
"partial",
"(",
"alltoall_ring",
","... | Grouped alltoall.
Args:
x: a LaidOutTensor
mesh_axis: an integer the mesh axis along which to group
split_axis: an integer (the Tensor axis along which to split)
concat_axis: an integer (the Tensor axis along which to concatenate)
Returns:
a LaidOutTensor | [
"Grouped",
"alltoall",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/placement_mesh_impl.py#L232-L246 |
227,814 | tensorflow/mesh | mesh_tensorflow/placement_mesh_impl.py | PlacementMeshImpl.import_tf_tensor | def import_tf_tensor(self, x, tf_x):
"""Import a tf.Tensor, producing a LaidOutTensor.
Args:
x: a Tensor
tf_x: a tf.Tensor
Returns:
a LaidOutTensor
"""
return self.LaidOutTensor(self.make_slices(tf_x, x.shape)) | python | def import_tf_tensor(self, x, tf_x):
"""Import a tf.Tensor, producing a LaidOutTensor.
Args:
x: a Tensor
tf_x: a tf.Tensor
Returns:
a LaidOutTensor
"""
return self.LaidOutTensor(self.make_slices(tf_x, x.shape)) | [
"def",
"import_tf_tensor",
"(",
"self",
",",
"x",
",",
"tf_x",
")",
":",
"return",
"self",
".",
"LaidOutTensor",
"(",
"self",
".",
"make_slices",
"(",
"tf_x",
",",
"x",
".",
"shape",
")",
")"
] | Import a tf.Tensor, producing a LaidOutTensor.
Args:
x: a Tensor
tf_x: a tf.Tensor
Returns:
a LaidOutTensor | [
"Import",
"a",
"tf",
".",
"Tensor",
"producing",
"a",
"LaidOutTensor",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/placement_mesh_impl.py#L350-L359 |
227,815 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | attention | def attention(q,
k,
v,
memory_length_dim,
key_dim,
value_dim,
mask=None,
dropout_rate=0.0,
dropout_broadcast_dims=None,
extra_logit=None):
"""Dot-product attention - doesn't use positional dim... | python | def attention(q,
k,
v,
memory_length_dim,
key_dim,
value_dim,
mask=None,
dropout_rate=0.0,
dropout_broadcast_dims=None,
extra_logit=None):
"""Dot-product attention - doesn't use positional dim... | [
"def",
"attention",
"(",
"q",
",",
"k",
",",
"v",
",",
"memory_length_dim",
",",
"key_dim",
",",
"value_dim",
",",
"mask",
"=",
"None",
",",
"dropout_rate",
"=",
"0.0",
",",
"dropout_broadcast_dims",
"=",
"None",
",",
"extra_logit",
"=",
"None",
")",
":"... | Dot-product attention - doesn't use positional dimensions.
key_dim is a Dimension representing the channels in the queries and keys
value_dim is a Dimension representing the channels in values
memory_length_dim is a Dimension representing the different key/value pairs.
Dimensions of q: other_query_dims + {key... | [
"Dot",
"-",
"product",
"attention",
"-",
"doesn",
"t",
"use",
"positional",
"dimensions",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L27-L76 |
227,816 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | attention_params_simple | def attention_params_simple(
mesh, io_dim, kv_dim, heads_dim, variable_dtype):
"""Common case attention parameters.
Args:
mesh: a Mesh
io_dim: a Dimension (channels dimension of inputs and outputs)
kv_dim: a Dimension (channels in keys and values)
heads_dim: a Dimension (number of attention "he... | python | def attention_params_simple(
mesh, io_dim, kv_dim, heads_dim, variable_dtype):
"""Common case attention parameters.
Args:
mesh: a Mesh
io_dim: a Dimension (channels dimension of inputs and outputs)
kv_dim: a Dimension (channels in keys and values)
heads_dim: a Dimension (number of attention "he... | [
"def",
"attention_params_simple",
"(",
"mesh",
",",
"io_dim",
",",
"kv_dim",
",",
"heads_dim",
",",
"variable_dtype",
")",
":",
"return",
"AttentionParams",
"(",
"mesh",
",",
"query_input_dim",
"=",
"io_dim",
",",
"memory_input_dim",
"=",
"io_dim",
",",
"output_... | Common case attention parameters.
Args:
mesh: a Mesh
io_dim: a Dimension (channels dimension of inputs and outputs)
kv_dim: a Dimension (channels in keys and values)
heads_dim: a Dimension (number of attention "heads")
variable_dtype: a mtf.VariableDType
Returns:
an AttentionParams | [
"Common",
"case",
"attention",
"parameters",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L264-L286 |
227,817 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | local_attention_1d | def local_attention_1d(q,
k,
v,
length_dim,
key_dim,
value_dim,
autoregressive=True,
length_dim_num_splits=1,
radius=128,
... | python | def local_attention_1d(q,
k,
v,
length_dim,
key_dim,
value_dim,
autoregressive=True,
length_dim_num_splits=1,
radius=128,
... | [
"def",
"local_attention_1d",
"(",
"q",
",",
"k",
",",
"v",
",",
"length_dim",
",",
"key_dim",
",",
"value_dim",
",",
"autoregressive",
"=",
"True",
",",
"length_dim_num_splits",
"=",
"1",
",",
"radius",
"=",
"128",
",",
"sequence_id",
"=",
"1",
",",
"att... | Attention to the a neighborood around the source.
If autoregressive, then query position p can only see memory positions
in the range (p - radius, p].
If not autoregressive, then query position p can only see memory positions
in the range (p - window_size, p + radius].
Args:
q: a Tensor containing leng... | [
"Attention",
"to",
"the",
"a",
"neighborood",
"around",
"the",
"source",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L289-L377 |
227,818 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | AttentionParams.compute_q | def compute_q(self, query_antecedent):
"""Compute query Tensor q.
Args:
query_antecedent: a Tensor with dimensions
{query_input_dim} + other_dims
Returns:
a Tensor with dimensions
query_heads_dims + {key_dim} + other_dims
"""
ret = mtf.einsum(
[query_antecedent... | python | def compute_q(self, query_antecedent):
"""Compute query Tensor q.
Args:
query_antecedent: a Tensor with dimensions
{query_input_dim} + other_dims
Returns:
a Tensor with dimensions
query_heads_dims + {key_dim} + other_dims
"""
ret = mtf.einsum(
[query_antecedent... | [
"def",
"compute_q",
"(",
"self",
",",
"query_antecedent",
")",
":",
"ret",
"=",
"mtf",
".",
"einsum",
"(",
"[",
"query_antecedent",
",",
"self",
".",
"wq",
"]",
",",
"reduced_dims",
"=",
"[",
"self",
".",
"query_input_dim",
"]",
")",
"if",
"self",
".",... | Compute query Tensor q.
Args:
query_antecedent: a Tensor with dimensions
{query_input_dim} + other_dims
Returns:
a Tensor with dimensions
query_heads_dims + {key_dim} + other_dims | [
"Compute",
"query",
"Tensor",
"q",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L153-L167 |
227,819 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | AttentionParams.compute_k | def compute_k(self, memory_antecedent):
"""Compute key Tensor k.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {key_dim} + other_dims
"""
if self.shared_kv:
raise ValueError("... | python | def compute_k(self, memory_antecedent):
"""Compute key Tensor k.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {key_dim} + other_dims
"""
if self.shared_kv:
raise ValueError("... | [
"def",
"compute_k",
"(",
"self",
",",
"memory_antecedent",
")",
":",
"if",
"self",
".",
"shared_kv",
":",
"raise",
"ValueError",
"(",
"\"compute_k cannot be called with shared_kv\"",
")",
"ret",
"=",
"mtf",
".",
"einsum",
"(",
"[",
"memory_antecedent",
",",
"sel... | Compute key Tensor k.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {key_dim} + other_dims | [
"Compute",
"key",
"Tensor",
"k",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L187-L203 |
227,820 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | AttentionParams.compute_v | def compute_v(self, memory_antecedent):
"""Compute value Tensor v.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {value_dim} + other_dims
"""
if self.shared_kv:
raise ValueErr... | python | def compute_v(self, memory_antecedent):
"""Compute value Tensor v.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {value_dim} + other_dims
"""
if self.shared_kv:
raise ValueErr... | [
"def",
"compute_v",
"(",
"self",
",",
"memory_antecedent",
")",
":",
"if",
"self",
".",
"shared_kv",
":",
"raise",
"ValueError",
"(",
"\"compute_v cannot be called with shared_kv\"",
")",
"ret",
"=",
"mtf",
".",
"einsum",
"(",
"[",
"memory_antecedent",
",",
"sel... | Compute value Tensor v.
Args:
memory_antecedent: a Tensor with dimensions
{memory_input_dim} + other_dims
Returns:
a Tensor with dimensions
memory_heads_dims + {value_dim} + other_dims | [
"Compute",
"value",
"Tensor",
"v",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L205-L221 |
227,821 | tensorflow/mesh | mesh_tensorflow/transformer/attention.py | AttentionParams.compute_output | def compute_output(self, o, output_shape=None):
"""Compute output of multihead attention.
Args:
o: a Tensor with dimensions
query_heads_dims + {value_dim} + other_dims
output_shape: an optional Shape
Returns:
a Tensor with shape:
{output_dim} + other_dims
"""
if ... | python | def compute_output(self, o, output_shape=None):
"""Compute output of multihead attention.
Args:
o: a Tensor with dimensions
query_heads_dims + {value_dim} + other_dims
output_shape: an optional Shape
Returns:
a Tensor with shape:
{output_dim} + other_dims
"""
if ... | [
"def",
"compute_output",
"(",
"self",
",",
"o",
",",
"output_shape",
"=",
"None",
")",
":",
"if",
"self",
".",
"combine_dims",
":",
"o",
"=",
"mtf",
".",
"transpose",
"(",
"o",
",",
"o",
".",
"shape",
"-",
"self",
".",
"o_dims",
"+",
"self",
".",
... | Compute output of multihead attention.
Args:
o: a Tensor with dimensions
query_heads_dims + {value_dim} + other_dims
output_shape: an optional Shape
Returns:
a Tensor with shape:
{output_dim} + other_dims | [
"Compute",
"output",
"of",
"multihead",
"attention",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/attention.py#L223-L241 |
227,822 | tensorflow/mesh | mesh_tensorflow/transformer/t2t_vocabulary.py | T2tVocabulary.encode_tf | def encode_tf(self, s):
"""Encode a tf.Scalar string to a tf.Tensor.
This will be necessary for on-the-fly tokenization.
Args:
s: a tf.Scalar with dtype tf.string
Returns:
a 1d tf.Tensor with dtype tf.int32
"""
ids = subword_text_encoder_ops.subword_text_encoder_encode(
s, ... | python | def encode_tf(self, s):
"""Encode a tf.Scalar string to a tf.Tensor.
This will be necessary for on-the-fly tokenization.
Args:
s: a tf.Scalar with dtype tf.string
Returns:
a 1d tf.Tensor with dtype tf.int32
"""
ids = subword_text_encoder_ops.subword_text_encoder_encode(
s, ... | [
"def",
"encode_tf",
"(",
"self",
",",
"s",
")",
":",
"ids",
"=",
"subword_text_encoder_ops",
".",
"subword_text_encoder_encode",
"(",
"s",
",",
"self",
".",
"_filepath",
")",
"# the c++ op apppends 1=EOS - drop it.",
"return",
"ids",
"[",
":",
"-",
"1",
"]"
] | Encode a tf.Scalar string to a tf.Tensor.
This will be necessary for on-the-fly tokenization.
Args:
s: a tf.Scalar with dtype tf.string
Returns:
a 1d tf.Tensor with dtype tf.int32 | [
"Encode",
"a",
"tf",
".",
"Scalar",
"string",
"to",
"a",
"tf",
".",
"Tensor",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/t2t_vocabulary.py#L79-L92 |
227,823 | tensorflow/mesh | mesh_tensorflow/transformer/model_builder.py | simple_layer_stack | def simple_layer_stack(include_encdec_attention,
num_layers=6,
d_ff=2048,
num_heads=8,
d_kv=128,
dropout_rate=0.1):
"""Create a layer stack.
Args:
include_encdec_attention: a boolean
num_layer... | python | def simple_layer_stack(include_encdec_attention,
num_layers=6,
d_ff=2048,
num_heads=8,
d_kv=128,
dropout_rate=0.1):
"""Create a layer stack.
Args:
include_encdec_attention: a boolean
num_layer... | [
"def",
"simple_layer_stack",
"(",
"include_encdec_attention",
",",
"num_layers",
"=",
"6",
",",
"d_ff",
"=",
"2048",
",",
"num_heads",
"=",
"8",
",",
"d_kv",
"=",
"128",
",",
"dropout_rate",
"=",
"0.1",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"_",
"in",... | Create a layer stack.
Args:
include_encdec_attention: a boolean
num_layers: an integer
d_ff: an integer
num_heads: an integer
d_kv: an integer
dropout_rate: a float
Returns:
a LayerStack | [
"Create",
"a",
"layer",
"stack",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/model_builder.py#L30-L66 |
227,824 | tensorflow/mesh | examples/toy_model_tpu.py | toy_model | def toy_model(features, mesh):
"""A toy model implemented by mesh tensorlfow."""
batch_dim = mtf.Dimension('batch', FLAGS.batch_size)
io_dim = mtf.Dimension('io', FLAGS.io_size)
master_dtype = tf.as_dtype(FLAGS.master_dtype)
slice_dtype = tf.as_dtype(FLAGS.slice_dtype)
activation_dtype = tf.as_dtype(FLAGS.... | python | def toy_model(features, mesh):
"""A toy model implemented by mesh tensorlfow."""
batch_dim = mtf.Dimension('batch', FLAGS.batch_size)
io_dim = mtf.Dimension('io', FLAGS.io_size)
master_dtype = tf.as_dtype(FLAGS.master_dtype)
slice_dtype = tf.as_dtype(FLAGS.slice_dtype)
activation_dtype = tf.as_dtype(FLAGS.... | [
"def",
"toy_model",
"(",
"features",
",",
"mesh",
")",
":",
"batch_dim",
"=",
"mtf",
".",
"Dimension",
"(",
"'batch'",
",",
"FLAGS",
".",
"batch_size",
")",
"io_dim",
"=",
"mtf",
".",
"Dimension",
"(",
"'io'",
",",
"FLAGS",
".",
"io_size",
")",
"master... | A toy model implemented by mesh tensorlfow. | [
"A",
"toy",
"model",
"implemented",
"by",
"mesh",
"tensorlfow",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/examples/toy_model_tpu.py#L103-L142 |
227,825 | tensorflow/mesh | examples/toy_model_tpu.py | run_toy_model_tpu | def run_toy_model_tpu():
"""Run a toy model on TPU."""
tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(
FLAGS.tpu, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project)
iterations_per_loop = FLAGS.iterations
mesh_shape = mtf.convert_to_shape(FLAGS.mesh_shape)
config = tpu_config.RunConf... | python | def run_toy_model_tpu():
"""Run a toy model on TPU."""
tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(
FLAGS.tpu, zone=FLAGS.tpu_zone, project=FLAGS.gcp_project)
iterations_per_loop = FLAGS.iterations
mesh_shape = mtf.convert_to_shape(FLAGS.mesh_shape)
config = tpu_config.RunConf... | [
"def",
"run_toy_model_tpu",
"(",
")",
":",
"tpu_cluster_resolver",
"=",
"tf",
".",
"contrib",
".",
"cluster_resolver",
".",
"TPUClusterResolver",
"(",
"FLAGS",
".",
"tpu",
",",
"zone",
"=",
"FLAGS",
".",
"tpu_zone",
",",
"project",
"=",
"FLAGS",
".",
"gcp_pr... | Run a toy model on TPU. | [
"Run",
"a",
"toy",
"model",
"on",
"TPU",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/examples/toy_model_tpu.py#L243-L282 |
227,826 | tensorflow/mesh | examples/mnist.py | mnist_model | def mnist_model(image, labels, mesh):
"""The model.
Args:
image: tf.Tensor with shape [batch, 28*28]
labels: a tf.Tensor with shape [batch] and dtype tf.int32
mesh: a mtf.Mesh
Returns:
logits: a mtf.Tensor with shape [batch, 10]
loss: a mtf.Tensor with shape []
"""
batch_dim = mtf.Dimens... | python | def mnist_model(image, labels, mesh):
"""The model.
Args:
image: tf.Tensor with shape [batch, 28*28]
labels: a tf.Tensor with shape [batch] and dtype tf.int32
mesh: a mtf.Mesh
Returns:
logits: a mtf.Tensor with shape [batch, 10]
loss: a mtf.Tensor with shape []
"""
batch_dim = mtf.Dimens... | [
"def",
"mnist_model",
"(",
"image",
",",
"labels",
",",
"mesh",
")",
":",
"batch_dim",
"=",
"mtf",
".",
"Dimension",
"(",
"\"batch\"",
",",
"FLAGS",
".",
"batch_size",
")",
"row_blocks_dim",
"=",
"mtf",
".",
"Dimension",
"(",
"\"row_blocks\"",
",",
"4",
... | The model.
Args:
image: tf.Tensor with shape [batch, 28*28]
labels: a tf.Tensor with shape [batch] and dtype tf.int32
mesh: a mtf.Mesh
Returns:
logits: a mtf.Tensor with shape [batch, 10]
loss: a mtf.Tensor with shape [] | [
"The",
"model",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/examples/mnist.py#L50-L118 |
227,827 | tensorflow/mesh | examples/mnist.py | run_mnist | def run_mnist():
"""Run MNIST training and eval loop."""
mnist_classifier = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=FLAGS.model_dir)
# Set up training and evaluation input functions.
def train_input_fn():
"""Prepare data for training."""
# When choosing shuffle buffer sizes, l... | python | def run_mnist():
"""Run MNIST training and eval loop."""
mnist_classifier = tf.estimator.Estimator(
model_fn=model_fn,
model_dir=FLAGS.model_dir)
# Set up training and evaluation input functions.
def train_input_fn():
"""Prepare data for training."""
# When choosing shuffle buffer sizes, l... | [
"def",
"run_mnist",
"(",
")",
":",
"mnist_classifier",
"=",
"tf",
".",
"estimator",
".",
"Estimator",
"(",
"model_fn",
"=",
"model_fn",
",",
"model_dir",
"=",
"FLAGS",
".",
"model_dir",
")",
"# Set up training and evaluation input functions.",
"def",
"train_input_fn... | Run MNIST training and eval loop. | [
"Run",
"MNIST",
"training",
"and",
"eval",
"loop",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/examples/mnist.py#L207-L236 |
227,828 | tensorflow/mesh | mesh_tensorflow/transformer/moe.py | MoE2D.call | def call(self, context, x, losses=None):
"""Call the layer."""
has_length_dim = context.length_dim in x.shape.dims
if not has_length_dim:
x_shape = x.shape
shape_with_length = mtf.Shape(
x_shape.dims[:-1] + [mtf.Dimension("length", 1)]
+ x_shape.dims[-1:])
x = mtf.resha... | python | def call(self, context, x, losses=None):
"""Call the layer."""
has_length_dim = context.length_dim in x.shape.dims
if not has_length_dim:
x_shape = x.shape
shape_with_length = mtf.Shape(
x_shape.dims[:-1] + [mtf.Dimension("length", 1)]
+ x_shape.dims[-1:])
x = mtf.resha... | [
"def",
"call",
"(",
"self",
",",
"context",
",",
"x",
",",
"losses",
"=",
"None",
")",
":",
"has_length_dim",
"=",
"context",
".",
"length_dim",
"in",
"x",
".",
"shape",
".",
"dims",
"if",
"not",
"has_length_dim",
":",
"x_shape",
"=",
"x",
".",
"shap... | Call the layer. | [
"Call",
"the",
"layer",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/moe.py#L123-L145 |
227,829 | tensorflow/mesh | mesh_tensorflow/auto_mtf/print_cp_model_solution.py | print_solution | def print_solution(model, solver):
"""Prints the solution associated with solver.
If solver has already had Solve() called on it, prints the solution. This
includes each variable and its assignment, along with the objective function
and its optimal value.
If solver has not had Solve() called on it, or there ... | python | def print_solution(model, solver):
"""Prints the solution associated with solver.
If solver has already had Solve() called on it, prints the solution. This
includes each variable and its assignment, along with the objective function
and its optimal value.
If solver has not had Solve() called on it, or there ... | [
"def",
"print_solution",
"(",
"model",
",",
"solver",
")",
":",
"model_proto",
"=",
"model",
".",
"Proto",
"(",
")",
"response_proto",
"=",
"solver",
".",
"ResponseProto",
"(",
")",
"variables_in_objective_map",
"=",
"{",
"}",
"maximization",
"=",
"False",
"... | Prints the solution associated with solver.
If solver has already had Solve() called on it, prints the solution. This
includes each variable and its assignment, along with the objective function
and its optimal value.
If solver has not had Solve() called on it, or there is no feasible solution,
this will pro... | [
"Prints",
"the",
"solution",
"associated",
"with",
"solver",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/print_cp_model_solution.py#L32-L84 |
227,830 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | _local_var_name | def _local_var_name(splittable_dimensions, assignment):
"""Name for a local variable.
Args:
splittable_dimensions: frozenset of names of splittable dimensions.
assignment: dict from names of splittable dimensions to names of mesh
dimensions.
Returns:
A string, the variable name.
"""
assign... | python | def _local_var_name(splittable_dimensions, assignment):
"""Name for a local variable.
Args:
splittable_dimensions: frozenset of names of splittable dimensions.
assignment: dict from names of splittable dimensions to names of mesh
dimensions.
Returns:
A string, the variable name.
"""
assign... | [
"def",
"_local_var_name",
"(",
"splittable_dimensions",
",",
"assignment",
")",
":",
"assignment_string",
"=",
"[",
"]",
"for",
"splittable",
"in",
"sorted",
"(",
"splittable_dimensions",
")",
":",
"if",
"splittable",
"in",
"assignment",
":",
"assignment_string",
... | Name for a local variable.
Args:
splittable_dimensions: frozenset of names of splittable dimensions.
assignment: dict from names of splittable dimensions to names of mesh
dimensions.
Returns:
A string, the variable name. | [
"Name",
"for",
"a",
"local",
"variable",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L383-L401 |
227,831 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | _generate_assignments | def _generate_assignments(splittable_dimensions, mesh_dimension_to_size):
"""Generates all ways to map splittable dimensions to mesh dimensions.
Args:
splittable_dimensions: a frozenset of the names of splittable dimensions.
mesh_dimension_to_size: a dictionary from mesh dimension name to size.
Returns:... | python | def _generate_assignments(splittable_dimensions, mesh_dimension_to_size):
"""Generates all ways to map splittable dimensions to mesh dimensions.
Args:
splittable_dimensions: a frozenset of the names of splittable dimensions.
mesh_dimension_to_size: a dictionary from mesh dimension name to size.
Returns:... | [
"def",
"_generate_assignments",
"(",
"splittable_dimensions",
",",
"mesh_dimension_to_size",
")",
":",
"assignments",
"=",
"[",
"]",
"for",
"assignment_size",
"in",
"six",
".",
"moves",
".",
"xrange",
"(",
"1",
"+",
"min",
"(",
"len",
"(",
"splittable_dimensions... | Generates all ways to map splittable dimensions to mesh dimensions.
Args:
splittable_dimensions: a frozenset of the names of splittable dimensions.
mesh_dimension_to_size: a dictionary from mesh dimension name to size.
Returns:
A list of the valid assignments. Each assignment is a dict keyed by every
... | [
"Generates",
"all",
"ways",
"to",
"map",
"splittable",
"dimensions",
"to",
"mesh",
"dimensions",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L404-L423 |
227,832 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer._preprocess_input | def _preprocess_input(self):
"""Computing useful input data structures to ease IP construction."""
# Compute the sets of MTF dimensions used in operations/tensors.
# a {string: frozenset(string)}, mapping operation name to MTF dimension
# names.
self._operation_name_to_mtf_dimension_set = {}
# ... | python | def _preprocess_input(self):
"""Computing useful input data structures to ease IP construction."""
# Compute the sets of MTF dimensions used in operations/tensors.
# a {string: frozenset(string)}, mapping operation name to MTF dimension
# names.
self._operation_name_to_mtf_dimension_set = {}
# ... | [
"def",
"_preprocess_input",
"(",
"self",
")",
":",
"# Compute the sets of MTF dimensions used in operations/tensors.",
"# a {string: frozenset(string)}, mapping operation name to MTF dimension",
"# names.",
"self",
".",
"_operation_name_to_mtf_dimension_set",
"=",
"{",
"}",
"# a {strin... | Computing useful input data structures to ease IP construction. | [
"Computing",
"useful",
"input",
"data",
"structures",
"to",
"ease",
"IP",
"construction",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L123-L152 |
227,833 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer._initialize_variables | def _initialize_variables(self):
"""Initializing the variables of the IP."""
# Initialize global variables.
self._global_vars = {} # Indexed by (MTF dimension, mesh dimension)
for mtf_dimension_name in (
self._layout_validator.splittable_mtf_dimension_names):
for mesh_dimension_name in (
... | python | def _initialize_variables(self):
"""Initializing the variables of the IP."""
# Initialize global variables.
self._global_vars = {} # Indexed by (MTF dimension, mesh dimension)
for mtf_dimension_name in (
self._layout_validator.splittable_mtf_dimension_names):
for mesh_dimension_name in (
... | [
"def",
"_initialize_variables",
"(",
"self",
")",
":",
"# Initialize global variables.",
"self",
".",
"_global_vars",
"=",
"{",
"}",
"# Indexed by (MTF dimension, mesh dimension)",
"for",
"mtf_dimension_name",
"in",
"(",
"self",
".",
"_layout_validator",
".",
"splittable_... | Initializing the variables of the IP. | [
"Initializing",
"the",
"variables",
"of",
"the",
"IP",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L154-L187 |
227,834 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer._add_constraints | def _add_constraints(self):
"""Adding constraints to the IP."""
# Add operation constraints.
for mesh_dimension_name in (
self._layout_validator.mesh_dimension_name_to_size):
for mtf_dimension_set in self._operation_mtf_dimension_sets:
self._model.Add(
sum(self._global_vars... | python | def _add_constraints(self):
"""Adding constraints to the IP."""
# Add operation constraints.
for mesh_dimension_name in (
self._layout_validator.mesh_dimension_name_to_size):
for mtf_dimension_set in self._operation_mtf_dimension_sets:
self._model.Add(
sum(self._global_vars... | [
"def",
"_add_constraints",
"(",
"self",
")",
":",
"# Add operation constraints.",
"for",
"mesh_dimension_name",
"in",
"(",
"self",
".",
"_layout_validator",
".",
"mesh_dimension_name_to_size",
")",
":",
"for",
"mtf_dimension_set",
"in",
"self",
".",
"_operation_mtf_dime... | Adding constraints to the IP. | [
"Adding",
"constraints",
"to",
"the",
"IP",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L189-L262 |
227,835 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer._get_memory_contents | def _get_memory_contents(self):
"""Runs the scheduler to determine memory contents at every point in time.
Returns:
a list of frozenset of strings, where the ith entry describes the tensors
in memory when executing operation i (where schedule[i] is an index into
GetAllOperationNames()).
"... | python | def _get_memory_contents(self):
"""Runs the scheduler to determine memory contents at every point in time.
Returns:
a list of frozenset of strings, where the ith entry describes the tensors
in memory when executing operation i (where schedule[i] is an index into
GetAllOperationNames()).
"... | [
"def",
"_get_memory_contents",
"(",
"self",
")",
":",
"if",
"self",
".",
"_memory_contents",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_memory_contents",
"schedule",
"=",
"scheduler",
".",
"minimize_peak_memory",
"(",
"self",
".",
"_graph",
",",
"self"... | Runs the scheduler to determine memory contents at every point in time.
Returns:
a list of frozenset of strings, where the ith entry describes the tensors
in memory when executing operation i (where schedule[i] is an index into
GetAllOperationNames()). | [
"Runs",
"the",
"scheduler",
"to",
"determine",
"memory",
"contents",
"at",
"every",
"point",
"in",
"time",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L268-L283 |
227,836 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer.solve | def solve(self, print_solution=False):
"""Solves the current integer program and returns the computed layout.
Args:
print_solution: An optional boolean indicating whether to print the full
solution in human-readable format.
Returns:
The computed layout (as a string).
Raises:
... | python | def solve(self, print_solution=False):
"""Solves the current integer program and returns the computed layout.
Args:
print_solution: An optional boolean indicating whether to print the full
solution in human-readable format.
Returns:
The computed layout (as a string).
Raises:
... | [
"def",
"solve",
"(",
"self",
",",
"print_solution",
"=",
"False",
")",
":",
"# Solve and see how well the solver did.",
"self",
".",
"_cp_solver",
"=",
"cp_model",
".",
"CpSolver",
"(",
")",
"status",
"=",
"self",
".",
"_cp_solver",
".",
"Solve",
"(",
"self",
... | Solves the current integer program and returns the computed layout.
Args:
print_solution: An optional boolean indicating whether to print the full
solution in human-readable format.
Returns:
The computed layout (as a string).
Raises:
SolverError: the internal solver could not fi... | [
"Solves",
"the",
"current",
"integer",
"program",
"and",
"returns",
"the",
"computed",
"layout",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L285-L326 |
227,837 | tensorflow/mesh | mesh_tensorflow/auto_mtf/layout_optimizer.py | LayoutOptimizer.evaluate_layout | def evaluate_layout(self, layout):
"""The current objective value for the given layout.
TODO(joshuawang): The current function does not check that the given
layout is valid.
Args:
layout: a string, representing a layout to evaluate (e.g.
"d_ff:m1;heads:m2").
Returns:
A float... | python | def evaluate_layout(self, layout):
"""The current objective value for the given layout.
TODO(joshuawang): The current function does not check that the given
layout is valid.
Args:
layout: a string, representing a layout to evaluate (e.g.
"d_ff:m1;heads:m2").
Returns:
A float... | [
"def",
"evaluate_layout",
"(",
"self",
",",
"layout",
")",
":",
"layout_dict",
"=",
"{",
"}",
"if",
"layout",
":",
"for",
"pair",
"in",
"layout",
".",
"split",
"(",
"\";\"",
")",
":",
"mtf_dimension_name",
",",
"mesh_dimension_name",
"=",
"pair",
".",
"s... | The current objective value for the given layout.
TODO(joshuawang): The current function does not check that the given
layout is valid.
Args:
layout: a string, representing a layout to evaluate (e.g.
"d_ff:m1;heads:m2").
Returns:
A float, the objective value. | [
"The",
"current",
"objective",
"value",
"for",
"the",
"given",
"layout",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/auto_mtf/layout_optimizer.py#L328-L367 |
227,838 | tensorflow/mesh | mesh_tensorflow/utils.py | BalancedVariablePlacer.device_function | def device_function(self, var):
"""Choose a device for the input variable.
Args:
var: an Variable.
Returns:
The device for placing the var.
"""
if var.type not in ('Variable', 'VariableV2', 'VarHandleOp'):
tf.logging.debug('Place {} on last device: {}.'.format(
var.name... | python | def device_function(self, var):
"""Choose a device for the input variable.
Args:
var: an Variable.
Returns:
The device for placing the var.
"""
if var.type not in ('Variable', 'VariableV2', 'VarHandleOp'):
tf.logging.debug('Place {} on last device: {}.'.format(
var.name... | [
"def",
"device_function",
"(",
"self",
",",
"var",
")",
":",
"if",
"var",
".",
"type",
"not",
"in",
"(",
"'Variable'",
",",
"'VariableV2'",
",",
"'VarHandleOp'",
")",
":",
"tf",
".",
"logging",
".",
"debug",
"(",
"'Place {} on last device: {}.'",
".",
"for... | Choose a device for the input variable.
Args:
var: an Variable.
Returns:
The device for placing the var. | [
"Choose",
"a",
"device",
"for",
"the",
"input",
"variable",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/utils.py#L45-L70 |
227,839 | tensorflow/mesh | mesh_tensorflow/beam_search.py | greedy_decode | def greedy_decode(logits_fn,
initial_ids,
temperature=0.0,
initial_states=None,
eos_id=EOS_ID,
forced_ids=None,
use_tpu=True):
"""Greedy decoding.
Args:
logits_fn: Interface to the model, to provide logi... | python | def greedy_decode(logits_fn,
initial_ids,
temperature=0.0,
initial_states=None,
eos_id=EOS_ID,
forced_ids=None,
use_tpu=True):
"""Greedy decoding.
Args:
logits_fn: Interface to the model, to provide logi... | [
"def",
"greedy_decode",
"(",
"logits_fn",
",",
"initial_ids",
",",
"temperature",
"=",
"0.0",
",",
"initial_states",
"=",
"None",
",",
"eos_id",
"=",
"EOS_ID",
",",
"forced_ids",
"=",
"None",
",",
"use_tpu",
"=",
"True",
")",
":",
"length_dim",
"=",
"initi... | Greedy decoding.
Args:
logits_fn: Interface to the model, to provide logits.
Shoud take:
step_num - mtf Scalar
ids - mtf Tensor with shape [..., length]
states - list of mtf.Tensor
Should return:
logits - [batch, vocab_size]
new_states - list of m... | [
"Greedy",
"decoding",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/beam_search.py#L577-L642 |
227,840 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | pack_and_batch | def pack_and_batch(dataset, batch_size, length, pack=True):
"""Create a tf.data.Dataset which emits training batches.
The input dataset emits feature-dictionaries where each feature is a vector
of integers ending in EOS=1
The tensors in the returned tf.data.Dataset have shape
[batch_size, length]. Zeros in... | python | def pack_and_batch(dataset, batch_size, length, pack=True):
"""Create a tf.data.Dataset which emits training batches.
The input dataset emits feature-dictionaries where each feature is a vector
of integers ending in EOS=1
The tensors in the returned tf.data.Dataset have shape
[batch_size, length]. Zeros in... | [
"def",
"pack_and_batch",
"(",
"dataset",
",",
"batch_size",
",",
"length",
",",
"pack",
"=",
"True",
")",
":",
"if",
"pack",
":",
"dataset",
"=",
"pack_dataset",
"(",
"dataset",
",",
"length",
"=",
"length",
")",
"# Pad/trim length of each example to length",
... | Create a tf.data.Dataset which emits training batches.
The input dataset emits feature-dictionaries where each feature is a vector
of integers ending in EOS=1
The tensors in the returned tf.data.Dataset have shape
[batch_size, length]. Zeros indicate padding.
length indicates the length of the emitted exa... | [
"Create",
"a",
"tf",
".",
"data",
".",
"Dataset",
"which",
"emits",
"training",
"batches",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L98-L150 |
227,841 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | encode_dataset | def encode_dataset(dataset, vocabulary):
"""Encode from strings to token ids.
Args:
dataset: a tf.data.Dataset with string values.
vocabulary: a mesh_tensorflow.transformer.Vocabulary
Returns:
a tf.data.Dataset with integer-vector values ending in EOS=1
"""
def encode(features):
return {k: vo... | python | def encode_dataset(dataset, vocabulary):
"""Encode from strings to token ids.
Args:
dataset: a tf.data.Dataset with string values.
vocabulary: a mesh_tensorflow.transformer.Vocabulary
Returns:
a tf.data.Dataset with integer-vector values ending in EOS=1
"""
def encode(features):
return {k: vo... | [
"def",
"encode_dataset",
"(",
"dataset",
",",
"vocabulary",
")",
":",
"def",
"encode",
"(",
"features",
")",
":",
"return",
"{",
"k",
":",
"vocabulary",
".",
"encode_tf",
"(",
"v",
")",
"for",
"k",
",",
"v",
"in",
"features",
".",
"items",
"(",
")",
... | Encode from strings to token ids.
Args:
dataset: a tf.data.Dataset with string values.
vocabulary: a mesh_tensorflow.transformer.Vocabulary
Returns:
a tf.data.Dataset with integer-vector values ending in EOS=1 | [
"Encode",
"from",
"strings",
"to",
"token",
"ids",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L153-L164 |
227,842 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | packed_parallel_tsv_dataset | def packed_parallel_tsv_dataset(filenames=gin.REQUIRED,
dataset_split=gin.REQUIRED,
batch_size=gin.REQUIRED,
sequence_length=gin.REQUIRED,
vocabulary=gin.REQUIRED,
... | python | def packed_parallel_tsv_dataset(filenames=gin.REQUIRED,
dataset_split=gin.REQUIRED,
batch_size=gin.REQUIRED,
sequence_length=gin.REQUIRED,
vocabulary=gin.REQUIRED,
... | [
"def",
"packed_parallel_tsv_dataset",
"(",
"filenames",
"=",
"gin",
".",
"REQUIRED",
",",
"dataset_split",
"=",
"gin",
".",
"REQUIRED",
",",
"batch_size",
"=",
"gin",
".",
"REQUIRED",
",",
"sequence_length",
"=",
"gin",
".",
"REQUIRED",
",",
"vocabulary",
"=",... | Reads parallel tab-separated text file. One example per line. | [
"Reads",
"parallel",
"tab",
"-",
"separated",
"text",
"file",
".",
"One",
"example",
"per",
"line",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L213-L250 |
227,843 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | supervised_to_dict | def supervised_to_dict(dataset, text2self):
"""Turns a supervised dataset into a dataset with a feature dictionary.
if text2self, then the features dictionary contains a "targets" key.
else, the features dictionary contains "inputs" and "targets" keys.
Args:
dataset: a tf.data.Dataset
text2self: a boo... | python | def supervised_to_dict(dataset, text2self):
"""Turns a supervised dataset into a dataset with a feature dictionary.
if text2self, then the features dictionary contains a "targets" key.
else, the features dictionary contains "inputs" and "targets" keys.
Args:
dataset: a tf.data.Dataset
text2self: a boo... | [
"def",
"supervised_to_dict",
"(",
"dataset",
",",
"text2self",
")",
":",
"def",
"my_fn",
"(",
"inputs",
",",
"targets",
")",
":",
"if",
"text2self",
":",
"return",
"{",
"\"targets\"",
":",
"targets",
"}",
"else",
":",
"return",
"{",
"\"inputs\"",
":",
"i... | Turns a supervised dataset into a dataset with a feature dictionary.
if text2self, then the features dictionary contains a "targets" key.
else, the features dictionary contains "inputs" and "targets" keys.
Args:
dataset: a tf.data.Dataset
text2self: a boolean
Returns:
a tf.data.Dataset | [
"Turns",
"a",
"supervised",
"dataset",
"into",
"a",
"dataset",
"with",
"a",
"feature",
"dictionary",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L291-L308 |
227,844 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | encode_all_features | def encode_all_features(dataset, vocabulary):
"""Encode all features.
Args:
dataset: a tf.data.Dataset
vocabulary: a vocabulary.Vocabulary
Returns:
a tf.data.Dataset
"""
def my_fn(features):
ret = {}
for k, v in features.items():
v = vocabulary.encode_tf(v)
v = tf.concat([tf.t... | python | def encode_all_features(dataset, vocabulary):
"""Encode all features.
Args:
dataset: a tf.data.Dataset
vocabulary: a vocabulary.Vocabulary
Returns:
a tf.data.Dataset
"""
def my_fn(features):
ret = {}
for k, v in features.items():
v = vocabulary.encode_tf(v)
v = tf.concat([tf.t... | [
"def",
"encode_all_features",
"(",
"dataset",
",",
"vocabulary",
")",
":",
"def",
"my_fn",
"(",
"features",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"features",
".",
"items",
"(",
")",
":",
"v",
"=",
"vocabulary",
".",
"encode_tf",... | Encode all features.
Args:
dataset: a tf.data.Dataset
vocabulary: a vocabulary.Vocabulary
Returns:
a tf.data.Dataset | [
"Encode",
"all",
"features",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L311-L327 |
227,845 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | pretokenized_tfrecord_dataset | def pretokenized_tfrecord_dataset(filenames,
text2self,
eos_included,
repeat,
batch_size,
sequence_length):
"""Reads tensor2tensor-style data files.... | python | def pretokenized_tfrecord_dataset(filenames,
text2self,
eos_included,
repeat,
batch_size,
sequence_length):
"""Reads tensor2tensor-style data files.... | [
"def",
"pretokenized_tfrecord_dataset",
"(",
"filenames",
",",
"text2self",
",",
"eos_included",
",",
"repeat",
",",
"batch_size",
",",
"sequence_length",
")",
":",
"dataset",
"=",
"tf",
".",
"data",
".",
"TFRecordDataset",
"(",
"filenames",
",",
"buffer_size",
... | Reads tensor2tensor-style data files.
The dataset is defined by sets of TFRecord files of TFExample protos.
There should be a "targets" feature (a 1d tensor of integers)
If not text2self, there should also be an "inputs" feature.
Other features get ignored.
eos_included specifies whether the inputs and targ... | [
"Reads",
"tensor2tensor",
"-",
"style",
"data",
"files",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L330-L376 |
227,846 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | pretokenized_t2t_dataset | def pretokenized_t2t_dataset(dataset_name=gin.REQUIRED,
text2self=False,
data_dir=gin.REQUIRED,
dataset_split="train",
batch_size=gin.REQUIRED,
sequence_length=gin.REQUIRED,
... | python | def pretokenized_t2t_dataset(dataset_name=gin.REQUIRED,
text2self=False,
data_dir=gin.REQUIRED,
dataset_split="train",
batch_size=gin.REQUIRED,
sequence_length=gin.REQUIRED,
... | [
"def",
"pretokenized_t2t_dataset",
"(",
"dataset_name",
"=",
"gin",
".",
"REQUIRED",
",",
"text2self",
"=",
"False",
",",
"data_dir",
"=",
"gin",
".",
"REQUIRED",
",",
"dataset_split",
"=",
"\"train\"",
",",
"batch_size",
"=",
"gin",
".",
"REQUIRED",
",",
"s... | Loads the Tensor2tensor dataset specified by dataset_name.
Args:
dataset_name: TensorFlow Datasets dataset name.
text2self: a boolean
data_dir: string, data_dir for TensorFlow Datasets
dataset_split: a string - "train" or "dev"
batch_size: an integer
sequence_length: an integer
vocabulary... | [
"Loads",
"the",
"Tensor2tensor",
"dataset",
"specified",
"by",
"dataset_name",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L380-L417 |
227,847 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | pack_dataset | def pack_dataset(dataset, length, keys=None, use_custom_ops=False):
"""Creates a 'packed' version of a dataset on-the-fly.
Borrowed from the tensor2tensor library.
TODO(noam): make this faster
This is meant to replace the irritation of having to create a separate
"packed" version of a dataset to train effic... | python | def pack_dataset(dataset, length, keys=None, use_custom_ops=False):
"""Creates a 'packed' version of a dataset on-the-fly.
Borrowed from the tensor2tensor library.
TODO(noam): make this faster
This is meant to replace the irritation of having to create a separate
"packed" version of a dataset to train effic... | [
"def",
"pack_dataset",
"(",
"dataset",
",",
"length",
",",
"keys",
"=",
"None",
",",
"use_custom_ops",
"=",
"False",
")",
":",
"shapes",
"=",
"dataset",
".",
"output_shapes",
"if",
"keys",
"is",
"None",
":",
"keys",
"=",
"shapes",
".",
"keys",
"(",
")"... | Creates a 'packed' version of a dataset on-the-fly.
Borrowed from the tensor2tensor library.
TODO(noam): make this faster
This is meant to replace the irritation of having to create a separate
"packed" version of a dataset to train efficiently on TPU.
Each example in the output dataset represents several e... | [
"Creates",
"a",
"packed",
"version",
"of",
"a",
"dataset",
"on",
"-",
"the",
"-",
"fly",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L421-L490 |
227,848 | tensorflow/mesh | mesh_tensorflow/transformer/dataset.py | trim_and_pad_all_features | def trim_and_pad_all_features(features, length):
"""Trim and pad first dimension of all features to size length."""
return {k: _trim_and_pad(v, length) for k, v in features.items()} | python | def trim_and_pad_all_features(features, length):
"""Trim and pad first dimension of all features to size length."""
return {k: _trim_and_pad(v, length) for k, v in features.items()} | [
"def",
"trim_and_pad_all_features",
"(",
"features",
",",
"length",
")",
":",
"return",
"{",
"k",
":",
"_trim_and_pad",
"(",
"v",
",",
"length",
")",
"for",
"k",
",",
"v",
"in",
"features",
".",
"items",
"(",
")",
"}"
] | Trim and pad first dimension of all features to size length. | [
"Trim",
"and",
"pad",
"first",
"dimension",
"of",
"all",
"features",
"to",
"size",
"length",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/transformer/dataset.py#L667-L669 |
227,849 | tensorflow/mesh | mesh_tensorflow/ops.py | convert_to_dimension | def convert_to_dimension(d):
"""Converts input to a Dimension.
Args:
d: Dimension, tuple (string, int), or None.
Returns:
Dimension or None.
Raises:
ValueError: If d cannot be converted to a Dimension.
"""
if d is None:
return None
if isinstance(d, Dimension):
if not isinstance(d.na... | python | def convert_to_dimension(d):
"""Converts input to a Dimension.
Args:
d: Dimension, tuple (string, int), or None.
Returns:
Dimension or None.
Raises:
ValueError: If d cannot be converted to a Dimension.
"""
if d is None:
return None
if isinstance(d, Dimension):
if not isinstance(d.na... | [
"def",
"convert_to_dimension",
"(",
"d",
")",
":",
"if",
"d",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"d",
",",
"Dimension",
")",
":",
"if",
"not",
"isinstance",
"(",
"d",
".",
"name",
",",
"str",
")",
"or",
"not",
"isinstance",... | Converts input to a Dimension.
Args:
d: Dimension, tuple (string, int), or None.
Returns:
Dimension or None.
Raises:
ValueError: If d cannot be converted to a Dimension. | [
"Converts",
"input",
"to",
"a",
"Dimension",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L38-L60 |
227,850 | tensorflow/mesh | mesh_tensorflow/ops.py | convert_to_shape | def convert_to_shape(x):
"""Converts input to a Shape.
Args:
x: Shape, str, or None.
Returns:
Shape or None.
Raises:
ValueError: If x cannot be converted to a Shape.
"""
if x is None:
return None
if isinstance(x, Shape):
return x
if isinstance(x, str):
x = _parse_string_to_lis... | python | def convert_to_shape(x):
"""Converts input to a Shape.
Args:
x: Shape, str, or None.
Returns:
Shape or None.
Raises:
ValueError: If x cannot be converted to a Shape.
"""
if x is None:
return None
if isinstance(x, Shape):
return x
if isinstance(x, str):
x = _parse_string_to_lis... | [
"def",
"convert_to_shape",
"(",
"x",
")",
":",
"if",
"x",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"x",
",",
"Shape",
")",
":",
"return",
"x",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"x",
"=",
"_parse_string_to_list_o... | Converts input to a Shape.
Args:
x: Shape, str, or None.
Returns:
Shape or None.
Raises:
ValueError: If x cannot be converted to a Shape. | [
"Converts",
"input",
"to",
"a",
"Shape",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L182-L200 |
227,851 | tensorflow/mesh | mesh_tensorflow/ops.py | convert_to_layout_rules | def convert_to_layout_rules(x):
"""Converts input to a LayoutRules.
Args:
x: LayoutRules, str, or set-like of string pairs.
Returns:
LayoutRules.
"""
if isinstance(x, LayoutRules):
return x
if isinstance(x, str):
x = _parse_string_to_list_of_pairs(x)
return LayoutRules(x) | python | def convert_to_layout_rules(x):
"""Converts input to a LayoutRules.
Args:
x: LayoutRules, str, or set-like of string pairs.
Returns:
LayoutRules.
"""
if isinstance(x, LayoutRules):
return x
if isinstance(x, str):
x = _parse_string_to_list_of_pairs(x)
return LayoutRules(x) | [
"def",
"convert_to_layout_rules",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"LayoutRules",
")",
":",
"return",
"x",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
":",
"x",
"=",
"_parse_string_to_list_of_pairs",
"(",
"x",
")",
"return",
"Lay... | Converts input to a LayoutRules.
Args:
x: LayoutRules, str, or set-like of string pairs.
Returns:
LayoutRules. | [
"Converts",
"input",
"to",
"a",
"LayoutRules",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L271-L284 |
227,852 | tensorflow/mesh | mesh_tensorflow/ops.py | convert_args_to_laid_out_tensors | def convert_args_to_laid_out_tensors(xs):
"""Convert list elements to laid-out-tensors when possible.
Args:
xs: a list
Returns:
a list
"""
ret = []
for x in xs:
if hasattr(x, "to_laid_out_tensor"):
ret.append(x.to_laid_out_tensor())
else:
ret.append(x)
return ret | python | def convert_args_to_laid_out_tensors(xs):
"""Convert list elements to laid-out-tensors when possible.
Args:
xs: a list
Returns:
a list
"""
ret = []
for x in xs:
if hasattr(x, "to_laid_out_tensor"):
ret.append(x.to_laid_out_tensor())
else:
ret.append(x)
return ret | [
"def",
"convert_args_to_laid_out_tensors",
"(",
"xs",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"x",
"in",
"xs",
":",
"if",
"hasattr",
"(",
"x",
",",
"\"to_laid_out_tensor\"",
")",
":",
"ret",
".",
"append",
"(",
"x",
".",
"to_laid_out_tensor",
"(",
")",
... | Convert list elements to laid-out-tensors when possible.
Args:
xs: a list
Returns:
a list | [
"Convert",
"list",
"elements",
"to",
"laid",
"-",
"out",
"-",
"tensors",
"when",
"possible",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L1254-L1268 |
227,853 | tensorflow/mesh | mesh_tensorflow/ops.py | slicewise | def slicewise(tf_fn,
xs,
output_shape=None,
output_dtype=None,
splittable_dims=None,
grad_function=None,
name=None):
"""Slice-wise call to any tensorflow function.
The output shape and dtype default to those of the first input.
s... | python | def slicewise(tf_fn,
xs,
output_shape=None,
output_dtype=None,
splittable_dims=None,
grad_function=None,
name=None):
"""Slice-wise call to any tensorflow function.
The output shape and dtype default to those of the first input.
s... | [
"def",
"slicewise",
"(",
"tf_fn",
",",
"xs",
",",
"output_shape",
"=",
"None",
",",
"output_dtype",
"=",
"None",
",",
"splittable_dims",
"=",
"None",
",",
"grad_function",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"multiple_outputs",
"=",
"isinstanc... | Slice-wise call to any tensorflow function.
The output shape and dtype default to those of the first input.
splittable_dims is a list of Dimensions which can be split while keeping the
computation valid.
Args:
tf_fn: a function taking n tf.Tensors and returning a tf.Tensor
xs: a list of n Tensors
... | [
"Slice",
"-",
"wise",
"call",
"to",
"any",
"tensorflow",
"function",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L1568-L1605 |
227,854 | tensorflow/mesh | mesh_tensorflow/ops.py | cwise | def cwise(tf_fn, xs, output_dtype=None, grad_function=None, name=None):
"""Component-wise operation with no broadcasting.
Args:
tf_fn: a component-wise function taking n tf.Tensor inputs and producing
a tf.Tensor output
xs: n Tensors
output_dtype: an optional dtype
grad_function: an optional ... | python | def cwise(tf_fn, xs, output_dtype=None, grad_function=None, name=None):
"""Component-wise operation with no broadcasting.
Args:
tf_fn: a component-wise function taking n tf.Tensor inputs and producing
a tf.Tensor output
xs: n Tensors
output_dtype: an optional dtype
grad_function: an optional ... | [
"def",
"cwise",
"(",
"tf_fn",
",",
"xs",
",",
"output_dtype",
"=",
"None",
",",
"grad_function",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"return",
"slicewise",
"(",
"tf_fn",
",",
"xs",
",",
"output_dtype",
"=",
"output_dtype",
",",
"splittable_d... | Component-wise operation with no broadcasting.
Args:
tf_fn: a component-wise function taking n tf.Tensor inputs and producing
a tf.Tensor output
xs: n Tensors
output_dtype: an optional dtype
grad_function: an optional python function
name: an optional string
Returns:
a Tensor | [
"Component",
"-",
"wise",
"operation",
"with",
"no",
"broadcasting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L1608-L1624 |
227,855 | tensorflow/mesh | mesh_tensorflow/ops.py | binary_arguments_to_tensors | def binary_arguments_to_tensors(x1, x2):
"""Convert argument of a binary operation to Tensors.
Args:
x1: a Tensor or something convertible to a tf Scalar
x2: a Tensor or something convertible to a tf Scalar
Returns:
new_x1: a Tensor
new_x2: a Tensor
Raises:
ValueError: on failure
"""
... | python | def binary_arguments_to_tensors(x1, x2):
"""Convert argument of a binary operation to Tensors.
Args:
x1: a Tensor or something convertible to a tf Scalar
x2: a Tensor or something convertible to a tf Scalar
Returns:
new_x1: a Tensor
new_x2: a Tensor
Raises:
ValueError: on failure
"""
... | [
"def",
"binary_arguments_to_tensors",
"(",
"x1",
",",
"x2",
")",
":",
"if",
"not",
"isinstance",
"(",
"x1",
",",
"Tensor",
")",
"and",
"not",
"isinstance",
"(",
"x2",
",",
"Tensor",
")",
":",
"raise",
"ValueError",
"(",
"\"at least one of x1 and x2 must be an ... | Convert argument of a binary operation to Tensors.
Args:
x1: a Tensor or something convertible to a tf Scalar
x2: a Tensor or something convertible to a tf Scalar
Returns:
new_x1: a Tensor
new_x2: a Tensor
Raises:
ValueError: on failure | [
"Convert",
"argument",
"of",
"a",
"binary",
"operation",
"to",
"Tensors",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L1845-L1868 |
227,856 | tensorflow/mesh | mesh_tensorflow/ops.py | minimum | def minimum(x1, x2, output_shape=None, name=None):
"""Binary minimum with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
with tf.name_scope(name, default_name="mini... | python | def minimum(x1, x2, output_shape=None, name=None):
"""Binary minimum with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
with tf.name_scope(name, default_name="mini... | [
"def",
"minimum",
"(",
"x1",
",",
"x2",
",",
"output_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"output_shape",
"=",
"convert_to_shape",
"(",
"output_shape",
")",
"with",
"tf",
".",
"name_scope",
"(",
"name",
",",
"default_name",
"=",
"\"mi... | Binary minimum with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor | [
"Binary",
"minimum",
"with",
"broadcsting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L1960-L1976 |
227,857 | tensorflow/mesh | mesh_tensorflow/ops.py | split | def split(x, split_dim, num_or_size_splits, name=None):
"""Like tf.split.
Args:
x: a Tensor
split_dim: a Dimension in x.shape.dims
num_or_size_splits: either an integer dividing split_dim.size
or a list of integers adding up to split_dim.size
name: an optional string
Returns:
a list of... | python | def split(x, split_dim, num_or_size_splits, name=None):
"""Like tf.split.
Args:
x: a Tensor
split_dim: a Dimension in x.shape.dims
num_or_size_splits: either an integer dividing split_dim.size
or a list of integers adding up to split_dim.size
name: an optional string
Returns:
a list of... | [
"def",
"split",
"(",
"x",
",",
"split_dim",
",",
"num_or_size_splits",
",",
"name",
"=",
"None",
")",
":",
"return",
"SplitOperation",
"(",
"x",
",",
"split_dim",
",",
"num_or_size_splits",
",",
"name",
"=",
"name",
")",
".",
"outputs"
] | Like tf.split.
Args:
x: a Tensor
split_dim: a Dimension in x.shape.dims
num_or_size_splits: either an integer dividing split_dim.size
or a list of integers adding up to split_dim.size
name: an optional string
Returns:
a list of Tensors. | [
"Like",
"tf",
".",
"split",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L2215-L2227 |
227,858 | tensorflow/mesh | mesh_tensorflow/ops.py | stack | def stack(xs, dim_name, axis=0, name=None):
"""Stack multiple Tensors to make a new dimension.
Args:
xs: a list of Tensors with identical shapes.
dim_name: a string (name of the new dimension)
axis: an integer (index of the new dimension in the output shape)
name: an optional string
Returns:
... | python | def stack(xs, dim_name, axis=0, name=None):
"""Stack multiple Tensors to make a new dimension.
Args:
xs: a list of Tensors with identical shapes.
dim_name: a string (name of the new dimension)
axis: an integer (index of the new dimension in the output shape)
name: an optional string
Returns:
... | [
"def",
"stack",
"(",
"xs",
",",
"dim_name",
",",
"axis",
"=",
"0",
",",
"name",
"=",
"None",
")",
":",
"ret",
"=",
"StackOperation",
"(",
"xs",
",",
"dim_name",
",",
"axis",
",",
"name",
")",
".",
"outputs",
"[",
"0",
"]",
"return",
"ret"
] | Stack multiple Tensors to make a new dimension.
Args:
xs: a list of Tensors with identical shapes.
dim_name: a string (name of the new dimension)
axis: an integer (index of the new dimension in the output shape)
name: an optional string
Returns:
a Tensor | [
"Stack",
"multiple",
"Tensors",
"to",
"make",
"a",
"new",
"dimension",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L2264-L2277 |
227,859 | tensorflow/mesh | mesh_tensorflow/ops.py | cumsum | def cumsum(x, dim, exclusive=False):
"""Cumulative sum.
Args:
x: a Tensor
dim: a Dimension
exclusive: a boolean
Returns:
a Tensor with the same shape as x.
"""
with tf.variable_scope("cumsum"):
new_name = "tmp_dim_cumsum"
new_dim = Dimension(new_name, dim.size)
new_shape = x.shap... | python | def cumsum(x, dim, exclusive=False):
"""Cumulative sum.
Args:
x: a Tensor
dim: a Dimension
exclusive: a boolean
Returns:
a Tensor with the same shape as x.
"""
with tf.variable_scope("cumsum"):
new_name = "tmp_dim_cumsum"
new_dim = Dimension(new_name, dim.size)
new_shape = x.shap... | [
"def",
"cumsum",
"(",
"x",
",",
"dim",
",",
"exclusive",
"=",
"False",
")",
":",
"with",
"tf",
".",
"variable_scope",
"(",
"\"cumsum\"",
")",
":",
"new_name",
"=",
"\"tmp_dim_cumsum\"",
"new_dim",
"=",
"Dimension",
"(",
"new_name",
",",
"dim",
".",
"size... | Cumulative sum.
Args:
x: a Tensor
dim: a Dimension
exclusive: a boolean
Returns:
a Tensor with the same shape as x. | [
"Cumulative",
"sum",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L2324-L2344 |
227,860 | tensorflow/mesh | mesh_tensorflow/ops.py | shift | def shift(x, offset, dim, wrap, name=None):
"""Shift operation.
Shift x right by +offset in dimension dim.
Args:
x: a Tensor
offset: an integer. If negative, shift left instead of right.
dim: a Dimension of x
wrap: a boolean - whether to wrap (True) or pad with zeros (False).
name: an option... | python | def shift(x, offset, dim, wrap, name=None):
"""Shift operation.
Shift x right by +offset in dimension dim.
Args:
x: a Tensor
offset: an integer. If negative, shift left instead of right.
dim: a Dimension of x
wrap: a boolean - whether to wrap (True) or pad with zeros (False).
name: an option... | [
"def",
"shift",
"(",
"x",
",",
"offset",
",",
"dim",
",",
"wrap",
",",
"name",
"=",
"None",
")",
":",
"return",
"ShiftOperation",
"(",
"x",
",",
"offset",
",",
"dim",
",",
"wrap",
",",
"name",
"=",
"name",
")",
".",
"outputs",
"[",
"0",
"]"
] | Shift operation.
Shift x right by +offset in dimension dim.
Args:
x: a Tensor
offset: an integer. If negative, shift left instead of right.
dim: a Dimension of x
wrap: a boolean - whether to wrap (True) or pad with zeros (False).
name: an optional string
Returns:
a Tensor with the same ... | [
"Shift",
"operation",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L2755-L2770 |
227,861 | tensorflow/mesh | mesh_tensorflow/ops.py | import_laid_out_tensor | def import_laid_out_tensor(mesh, laid_out_tensor, shape, name=None):
"""Import a laid_out_tensor.
For expert users.
The input must be laid out appropriately given the eventual MeshImpl,
and layout.
Args:
mesh: a Mesh
laid_out_tensor: a LaidOutTensor
shape: a mtf.Shape
name: an optional strin... | python | def import_laid_out_tensor(mesh, laid_out_tensor, shape, name=None):
"""Import a laid_out_tensor.
For expert users.
The input must be laid out appropriately given the eventual MeshImpl,
and layout.
Args:
mesh: a Mesh
laid_out_tensor: a LaidOutTensor
shape: a mtf.Shape
name: an optional strin... | [
"def",
"import_laid_out_tensor",
"(",
"mesh",
",",
"laid_out_tensor",
",",
"shape",
",",
"name",
"=",
"None",
")",
":",
"return",
"ImportLaidOutTensorOperation",
"(",
"mesh",
",",
"laid_out_tensor",
",",
"convert_to_shape",
"(",
"shape",
")",
",",
"name",
"=",
... | Import a laid_out_tensor.
For expert users.
The input must be laid out appropriately given the eventual MeshImpl,
and layout.
Args:
mesh: a Mesh
laid_out_tensor: a LaidOutTensor
shape: a mtf.Shape
name: an optional string
Returns:
a mtf.Tensor | [
"Import",
"a",
"laid_out_tensor",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L2972-L2989 |
227,862 | tensorflow/mesh | mesh_tensorflow/ops.py | get_variable | def get_variable(mesh, name, shape, dtype=tf.float32,
master_dtype=None, slice_dtype=None, activation_dtype=None,
initializer=None, trainable=True,
**kwargs):
"""Create a new variable or retrieve an already-created one.
Args:
mesh: a Mesh
name: a string (u... | python | def get_variable(mesh, name, shape, dtype=tf.float32,
master_dtype=None, slice_dtype=None, activation_dtype=None,
initializer=None, trainable=True,
**kwargs):
"""Create a new variable or retrieve an already-created one.
Args:
mesh: a Mesh
name: a string (u... | [
"def",
"get_variable",
"(",
"mesh",
",",
"name",
",",
"shape",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"master_dtype",
"=",
"None",
",",
"slice_dtype",
"=",
"None",
",",
"activation_dtype",
"=",
"None",
",",
"initializer",
"=",
"None",
",",
"traina... | Create a new variable or retrieve an already-created one.
Args:
mesh: a Mesh
name: a string (uses the existing tf.variable_scope())
shape: a Shape
dtype: a VariableDType or a tf.DType
master_dtype: an optional tf.DType (deprecated - use dtype arg)
slice_dtype: an optional tf.DType (deprecated... | [
"Create",
"a",
"new",
"variable",
"or",
"retrieve",
"an",
"already",
"-",
"created",
"one",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3210-L3253 |
227,863 | tensorflow/mesh | mesh_tensorflow/ops.py | assign | def assign(var, new_val, assign_fn=assign_slice):
"""Assign a new value to a variable.
Args:
var: either a Variable operation or its output Tensor.
new_val: a Tensor
assign_fn: a function from
(mtf.Variable, tf.Variable, tf.Tensor) -> tf.Operation
Returns:
an Operation
Raises:
Value... | python | def assign(var, new_val, assign_fn=assign_slice):
"""Assign a new value to a variable.
Args:
var: either a Variable operation or its output Tensor.
new_val: a Tensor
assign_fn: a function from
(mtf.Variable, tf.Variable, tf.Tensor) -> tf.Operation
Returns:
an Operation
Raises:
Value... | [
"def",
"assign",
"(",
"var",
",",
"new_val",
",",
"assign_fn",
"=",
"assign_slice",
")",
":",
"if",
"isinstance",
"(",
"var",
",",
"Tensor",
")",
":",
"var",
"=",
"var",
".",
"operation",
"if",
"not",
"isinstance",
"(",
"var",
",",
"Variable",
")",
"... | Assign a new value to a variable.
Args:
var: either a Variable operation or its output Tensor.
new_val: a Tensor
assign_fn: a function from
(mtf.Variable, tf.Variable, tf.Tensor) -> tf.Operation
Returns:
an Operation
Raises:
ValueError: if var is not a Variable and var.operation is no... | [
"Assign",
"a",
"new",
"value",
"to",
"a",
"variable",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3304-L3321 |
227,864 | tensorflow/mesh | mesh_tensorflow/ops.py | Print | def Print(x, data, message, **kwargs): # pylint: disable=invalid-name
"""Call tf.Print.
Args:
x: a Tensor.
data: a list of Tensor
message: a string
**kwargs: keyword arguments to tf.Print
Returns:
a Tensor which is identical in value to x
"""
return PrintOperation(x, data, message, **kwa... | python | def Print(x, data, message, **kwargs): # pylint: disable=invalid-name
"""Call tf.Print.
Args:
x: a Tensor.
data: a list of Tensor
message: a string
**kwargs: keyword arguments to tf.Print
Returns:
a Tensor which is identical in value to x
"""
return PrintOperation(x, data, message, **kwa... | [
"def",
"Print",
"(",
"x",
",",
"data",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=invalid-name",
"return",
"PrintOperation",
"(",
"x",
",",
"data",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
".",
"outputs",
"[",
"0",
"]"
] | Call tf.Print.
Args:
x: a Tensor.
data: a list of Tensor
message: a string
**kwargs: keyword arguments to tf.Print
Returns:
a Tensor which is identical in value to x | [
"Call",
"tf",
".",
"Print",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3450-L3461 |
227,865 | tensorflow/mesh | mesh_tensorflow/ops.py | rename_dimension | def rename_dimension(x, old_name, new_name):
"""Reshape a Tensor, renaming one dimension.
Args:
x: a Tensor
old_name: a string
new_name: a string
Returns:
a Tensor
"""
return reshape(x, x.shape.rename_dimension(old_name, new_name)) | python | def rename_dimension(x, old_name, new_name):
"""Reshape a Tensor, renaming one dimension.
Args:
x: a Tensor
old_name: a string
new_name: a string
Returns:
a Tensor
"""
return reshape(x, x.shape.rename_dimension(old_name, new_name)) | [
"def",
"rename_dimension",
"(",
"x",
",",
"old_name",
",",
"new_name",
")",
":",
"return",
"reshape",
"(",
"x",
",",
"x",
".",
"shape",
".",
"rename_dimension",
"(",
"old_name",
",",
"new_name",
")",
")"
] | Reshape a Tensor, renaming one dimension.
Args:
x: a Tensor
old_name: a string
new_name: a string
Returns:
a Tensor | [
"Reshape",
"a",
"Tensor",
"renaming",
"one",
"dimension",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3576-L3587 |
227,866 | tensorflow/mesh | mesh_tensorflow/ops.py | replace_dimensions | def replace_dimensions(tensor_or_shape, old_dim_or_dims, new_dim_or_dims):
"""Replace dimensions in a Tensor or Shape.
old_dim_or_dims consists of a single dimension or a list of dimensions
that must occur consecutively in the input shape. They are replaced
by the dimensions in new_dim_or_dims.
Args:
t... | python | def replace_dimensions(tensor_or_shape, old_dim_or_dims, new_dim_or_dims):
"""Replace dimensions in a Tensor or Shape.
old_dim_or_dims consists of a single dimension or a list of dimensions
that must occur consecutively in the input shape. They are replaced
by the dimensions in new_dim_or_dims.
Args:
t... | [
"def",
"replace_dimensions",
"(",
"tensor_or_shape",
",",
"old_dim_or_dims",
",",
"new_dim_or_dims",
")",
":",
"if",
"isinstance",
"(",
"tensor_or_shape",
",",
"Tensor",
")",
":",
"return",
"reshape",
"(",
"tensor_or_shape",
",",
"replace_dimensions",
"(",
"tensor_o... | Replace dimensions in a Tensor or Shape.
old_dim_or_dims consists of a single dimension or a list of dimensions
that must occur consecutively in the input shape. They are replaced
by the dimensions in new_dim_or_dims.
Args:
tensor_or_shape: a Tensor or a Shape
old_dim_or_dims: a Dimension or a list o... | [
"Replace",
"dimensions",
"in",
"a",
"Tensor",
"or",
"Shape",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3590-L3634 |
227,867 | tensorflow/mesh | mesh_tensorflow/ops.py | einsum | def einsum(xs, output_shape=None, reduced_dims=None, name=None):
"""Einstein summation.
einsum(xs, output_shape) is equivalent to broadcasting all inputs
to the union of all of their shapes, multiplying them componentwise,
and finally reduce_summing down to output_shape.
One common case of this is matrix mu... | python | def einsum(xs, output_shape=None, reduced_dims=None, name=None):
"""Einstein summation.
einsum(xs, output_shape) is equivalent to broadcasting all inputs
to the union of all of their shapes, multiplying them componentwise,
and finally reduce_summing down to output_shape.
One common case of this is matrix mu... | [
"def",
"einsum",
"(",
"xs",
",",
"output_shape",
"=",
"None",
",",
"reduced_dims",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"output_shape",
"=",
"convert_to_shape",
"(",
"output_shape",
")",
"input_dim_count",
"=",
"collections",
".",
"defaultdict",
... | Einstein summation.
einsum(xs, output_shape) is equivalent to broadcasting all inputs
to the union of all of their shapes, multiplying them componentwise,
and finally reduce_summing down to output_shape.
One common case of this is matrix multiplication:
x has shape [a, b]
y has shape [b, c]
... | [
"Einstein",
"summation",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3637-L3700 |
227,868 | tensorflow/mesh | mesh_tensorflow/ops.py | _reduction_output_shape | def _reduction_output_shape(x, output_shape, reduced_dim):
"""Helper function to reduce_sum, etc."""
if output_shape is None:
if reduced_dim is None:
return Shape([])
else:
if reduced_dim not in x.shape.dims:
raise ValueError(
"reduced_dim=%s not in x.shape.dims=%s" % (reduce... | python | def _reduction_output_shape(x, output_shape, reduced_dim):
"""Helper function to reduce_sum, etc."""
if output_shape is None:
if reduced_dim is None:
return Shape([])
else:
if reduced_dim not in x.shape.dims:
raise ValueError(
"reduced_dim=%s not in x.shape.dims=%s" % (reduce... | [
"def",
"_reduction_output_shape",
"(",
"x",
",",
"output_shape",
",",
"reduced_dim",
")",
":",
"if",
"output_shape",
"is",
"None",
":",
"if",
"reduced_dim",
"is",
"None",
":",
"return",
"Shape",
"(",
"[",
"]",
")",
"else",
":",
"if",
"reduced_dim",
"not",
... | Helper function to reduce_sum, etc. | [
"Helper",
"function",
"to",
"reduce_sum",
"etc",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3709-L3725 |
227,869 | tensorflow/mesh | mesh_tensorflow/ops.py | top_1 | def top_1(x, reduced_dim, dtype=tf.int32, name=None):
"""Argmax and Max.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims
dtype: a tf.dtype (for the output)
name: an optional string
Returns:
indices: a Tensor with given dtype
values: optional Tensor equal to mtf.reduce_max(x, re... | python | def top_1(x, reduced_dim, dtype=tf.int32, name=None):
"""Argmax and Max.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims
dtype: a tf.dtype (for the output)
name: an optional string
Returns:
indices: a Tensor with given dtype
values: optional Tensor equal to mtf.reduce_max(x, re... | [
"def",
"top_1",
"(",
"x",
",",
"reduced_dim",
",",
"dtype",
"=",
"tf",
".",
"int32",
",",
"name",
"=",
"None",
")",
":",
"reduced_dim",
"=",
"convert_to_dimension",
"(",
"reduced_dim",
")",
"with",
"tf",
".",
"name_scope",
"(",
"name",
",",
"default_name... | Argmax and Max.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims
dtype: a tf.dtype (for the output)
name: an optional string
Returns:
indices: a Tensor with given dtype
values: optional Tensor equal to mtf.reduce_max(x, reduced_dim=reduced_dim) | [
"Argmax",
"and",
"Max",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3875-L3894 |
227,870 | tensorflow/mesh | mesh_tensorflow/ops.py | top_k | def top_k(x, reduced_dim, new_dim, dtype=tf.int32, name=None):
"""Like tf.top_k.
This operation returns two tensors with the same shape. The output shape
is identical to the shape of x, except that reduced_dim is replaced by
new_dim.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims.
n... | python | def top_k(x, reduced_dim, new_dim, dtype=tf.int32, name=None):
"""Like tf.top_k.
This operation returns two tensors with the same shape. The output shape
is identical to the shape of x, except that reduced_dim is replaced by
new_dim.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims.
n... | [
"def",
"top_k",
"(",
"x",
",",
"reduced_dim",
",",
"new_dim",
",",
"dtype",
"=",
"tf",
".",
"int32",
",",
"name",
"=",
"None",
")",
":",
"reduced_dim",
"=",
"convert_to_dimension",
"(",
"reduced_dim",
")",
"new_dim",
"=",
"convert_to_dimension",
"(",
"new_... | Like tf.top_k.
This operation returns two tensors with the same shape. The output shape
is identical to the shape of x, except that reduced_dim is replaced by
new_dim.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims.
new_dim: a Dimension. The size determines k.
dtype: optional dty... | [
"Like",
"tf",
".",
"top_k",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3902-L3932 |
227,871 | tensorflow/mesh | mesh_tensorflow/ops.py | add | def add(x1, x2, output_shape=None, name=None):
"""Binary addition with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return Scal... | python | def add(x1, x2, output_shape=None, name=None):
"""Binary addition with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return Scal... | [
"def",
"add",
"(",
"x1",
",",
"x2",
",",
"output_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"output_shape",
"=",
"convert_to_shape",
"(",
"output_shape",
")",
"if",
"not",
"isinstance",
"(",
"x2",
",",
"Tensor",
")",
":",
"return",
"Scala... | Binary addition with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor | [
"Binary",
"addition",
"with",
"broadcsting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3968-L3986 |
227,872 | tensorflow/mesh | mesh_tensorflow/ops.py | sub | def sub(x1, x2, output_shape=None, name=None):
"""Binary subtraction with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return S... | python | def sub(x1, x2, output_shape=None, name=None):
"""Binary subtraction with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return S... | [
"def",
"sub",
"(",
"x1",
",",
"x2",
",",
"output_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"output_shape",
"=",
"convert_to_shape",
"(",
"output_shape",
")",
"if",
"not",
"isinstance",
"(",
"x2",
",",
"Tensor",
")",
":",
"return",
"Scala... | Binary subtraction with broadcsting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor | [
"Binary",
"subtraction",
"with",
"broadcsting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L3995-L4011 |
227,873 | tensorflow/mesh | mesh_tensorflow/ops.py | multiply | def multiply(x1, x2, output_shape=None, name=None):
"""Binary multiplication with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
if not isinstance(x2, Tensor):
return ScalarMultiplyOperation(x1, x2).outputs[... | python | def multiply(x1, x2, output_shape=None, name=None):
"""Binary multiplication with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
if not isinstance(x2, Tensor):
return ScalarMultiplyOperation(x1, x2).outputs[... | [
"def",
"multiply",
"(",
"x1",
",",
"x2",
",",
"output_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"x2",
",",
"Tensor",
")",
":",
"return",
"ScalarMultiplyOperation",
"(",
"x1",
",",
"x2",
")",
".",
"output... | Binary multiplication with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor | [
"Binary",
"multiplication",
"with",
"broadcasting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4014-L4032 |
227,874 | tensorflow/mesh | mesh_tensorflow/ops.py | divide | def divide(x1, x2, output_shape=None, name=None):
"""Binary division with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return ... | python | def divide(x1, x2, output_shape=None, name=None):
"""Binary division with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor
"""
output_shape = convert_to_shape(output_shape)
if not isinstance(x2, Tensor):
return ... | [
"def",
"divide",
"(",
"x1",
",",
"x2",
",",
"output_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"output_shape",
"=",
"convert_to_shape",
"(",
"output_shape",
")",
"if",
"not",
"isinstance",
"(",
"x2",
",",
"Tensor",
")",
":",
"return",
"Sc... | Binary division with broadcasting.
Args:
x1: a Tensor
x2: a Tensor
output_shape: an optional Shape
name: an optional string
Returns:
a Tensor | [
"Binary",
"division",
"with",
"broadcasting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4035-L4051 |
227,875 | tensorflow/mesh | mesh_tensorflow/ops.py | one_hot | def one_hot(indices, output_dim, on_value=1.0,
off_value=0.0, dtype=tf.float32, name=None):
"""One hot operation.
TODO(noam): Is there a good reason we need a special mtf.Operation here?
We could just use some code like this:
cast(equal(indices, mtf_range(indices.mesh, output_dim, dtype=indices.dty... | python | def one_hot(indices, output_dim, on_value=1.0,
off_value=0.0, dtype=tf.float32, name=None):
"""One hot operation.
TODO(noam): Is there a good reason we need a special mtf.Operation here?
We could just use some code like this:
cast(equal(indices, mtf_range(indices.mesh, output_dim, dtype=indices.dty... | [
"def",
"one_hot",
"(",
"indices",
",",
"output_dim",
",",
"on_value",
"=",
"1.0",
",",
"off_value",
"=",
"0.0",
",",
"dtype",
"=",
"tf",
".",
"float32",
",",
"name",
"=",
"None",
")",
":",
"return",
"OneHotOperation",
"(",
"indices",
",",
"output_dim",
... | One hot operation.
TODO(noam): Is there a good reason we need a special mtf.Operation here?
We could just use some code like this:
cast(equal(indices, mtf_range(indices.mesh, output_dim, dtype=indices.dtype)),
dtype)
Args:
indices: a Tensor
output_dim: a Dimension
on_value: Value taken when... | [
"One",
"hot",
"operation",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4087-L4107 |
227,876 | tensorflow/mesh | mesh_tensorflow/ops.py | gradients | def gradients(ys, xs, grad_ys=None):
"""Compute gradients in dtf.
Args:
ys: a list of Tensors
xs: a list of Tensors
grad_ys: an optional list of Tensors
Returns:
grad_xs: a list of Tensors
"""
graph = ys[0].graph
if not grad_ys:
grad_ys = [Constant(y.mesh, 1.0, y.shape, y.dtype).output... | python | def gradients(ys, xs, grad_ys=None):
"""Compute gradients in dtf.
Args:
ys: a list of Tensors
xs: a list of Tensors
grad_ys: an optional list of Tensors
Returns:
grad_xs: a list of Tensors
"""
graph = ys[0].graph
if not grad_ys:
grad_ys = [Constant(y.mesh, 1.0, y.shape, y.dtype).output... | [
"def",
"gradients",
"(",
"ys",
",",
"xs",
",",
"grad_ys",
"=",
"None",
")",
":",
"graph",
"=",
"ys",
"[",
"0",
"]",
".",
"graph",
"if",
"not",
"grad_ys",
":",
"grad_ys",
"=",
"[",
"Constant",
"(",
"y",
".",
"mesh",
",",
"1.0",
",",
"y",
".",
... | Compute gradients in dtf.
Args:
ys: a list of Tensors
xs: a list of Tensors
grad_ys: an optional list of Tensors
Returns:
grad_xs: a list of Tensors | [
"Compute",
"gradients",
"in",
"dtf",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4129-L4161 |
227,877 | tensorflow/mesh | mesh_tensorflow/ops.py | _infer_binary_broadcast_shape | def _infer_binary_broadcast_shape(shape1, shape2, given_output_shape=None):
"""Infer shape of the output of a binary op with broadcasting.
If the output shape is not given with given_output_shape, then we check
to see if one of the shapes is a subsequence of the other one, and we
return the one that is the sup... | python | def _infer_binary_broadcast_shape(shape1, shape2, given_output_shape=None):
"""Infer shape of the output of a binary op with broadcasting.
If the output shape is not given with given_output_shape, then we check
to see if one of the shapes is a subsequence of the other one, and we
return the one that is the sup... | [
"def",
"_infer_binary_broadcast_shape",
"(",
"shape1",
",",
"shape2",
",",
"given_output_shape",
"=",
"None",
")",
":",
"shape1",
"=",
"convert_to_shape",
"(",
"shape1",
")",
"shape2",
"=",
"convert_to_shape",
"(",
"shape2",
")",
"given_output_shape",
"=",
"conver... | Infer shape of the output of a binary op with broadcasting.
If the output shape is not given with given_output_shape, then we check
to see if one of the shapes is a subsequence of the other one, and we
return the one that is the supersequence. Otherwise, we list the dimensions
of shape1, followed by all new d... | [
"Infer",
"shape",
"of",
"the",
"output",
"of",
"a",
"binary",
"op",
"with",
"broadcasting",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4164-L4189 |
227,878 | tensorflow/mesh | mesh_tensorflow/ops.py | _expand_dims | def _expand_dims(x, input_shape, output_shape):
"""Expand dimensions and transpose if necessary.
Args:
x: a tf.Tensor
input_shape: a Shape
output_shape: a Shape whose dimensions are a superset of
those in input_shape
Returns:
a tf.Tensor
"""
verify_no_new_dims([output_shape], input_sha... | python | def _expand_dims(x, input_shape, output_shape):
"""Expand dimensions and transpose if necessary.
Args:
x: a tf.Tensor
input_shape: a Shape
output_shape: a Shape whose dimensions are a superset of
those in input_shape
Returns:
a tf.Tensor
"""
verify_no_new_dims([output_shape], input_sha... | [
"def",
"_expand_dims",
"(",
"x",
",",
"input_shape",
",",
"output_shape",
")",
":",
"verify_no_new_dims",
"(",
"[",
"output_shape",
"]",
",",
"input_shape",
")",
"if",
"input_shape",
"==",
"output_shape",
"or",
"input_shape",
".",
"ndims",
"==",
"0",
":",
"r... | Expand dimensions and transpose if necessary.
Args:
x: a tf.Tensor
input_shape: a Shape
output_shape: a Shape whose dimensions are a superset of
those in input_shape
Returns:
a tf.Tensor | [
"Expand",
"dimensions",
"and",
"transpose",
"if",
"necessary",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4192-L4213 |
227,879 | tensorflow/mesh | mesh_tensorflow/ops.py | _einsum_equation | def _einsum_equation(input_shapes, output_shape):
"""Turn shapes into an einsum equation.
e.g. "ij,jk->ik"
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Returns:
a string
"""
ret = []
next_letter = ord("a")
dim_to_letter = {}
for shape_num, shape in enumerate(input_shapes + ... | python | def _einsum_equation(input_shapes, output_shape):
"""Turn shapes into an einsum equation.
e.g. "ij,jk->ik"
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Returns:
a string
"""
ret = []
next_letter = ord("a")
dim_to_letter = {}
for shape_num, shape in enumerate(input_shapes + ... | [
"def",
"_einsum_equation",
"(",
"input_shapes",
",",
"output_shape",
")",
":",
"ret",
"=",
"[",
"]",
"next_letter",
"=",
"ord",
"(",
"\"a\"",
")",
"dim_to_letter",
"=",
"{",
"}",
"for",
"shape_num",
",",
"shape",
"in",
"enumerate",
"(",
"input_shapes",
"+"... | Turn shapes into an einsum equation.
e.g. "ij,jk->ik"
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Returns:
a string | [
"Turn",
"shapes",
"into",
"an",
"einsum",
"equation",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4216-L4241 |
227,880 | tensorflow/mesh | mesh_tensorflow/ops.py | is_subsequence | def is_subsequence(short_seq, long_seq):
"""Is short_seq a subsequence of long_seq."""
if not short_seq:
return True
pos = 0
for x in long_seq:
if pos == len(short_seq):
return True
if short_seq[pos] == x:
pos += 1
if pos == len(short_seq):
return True
return False | python | def is_subsequence(short_seq, long_seq):
"""Is short_seq a subsequence of long_seq."""
if not short_seq:
return True
pos = 0
for x in long_seq:
if pos == len(short_seq):
return True
if short_seq[pos] == x:
pos += 1
if pos == len(short_seq):
return True
return False | [
"def",
"is_subsequence",
"(",
"short_seq",
",",
"long_seq",
")",
":",
"if",
"not",
"short_seq",
":",
"return",
"True",
"pos",
"=",
"0",
"for",
"x",
"in",
"long_seq",
":",
"if",
"pos",
"==",
"len",
"(",
"short_seq",
")",
":",
"return",
"True",
"if",
"... | Is short_seq a subsequence of long_seq. | [
"Is",
"short_seq",
"a",
"subsequence",
"of",
"long_seq",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4244-L4256 |
227,881 | tensorflow/mesh | mesh_tensorflow/ops.py | verify_no_new_dims | def verify_no_new_dims(input_shapes, output_shape):
"""Verifies that all dimensions in the output are in at least one input.
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Raises:
ValueError: if there are new dimensions in the output.
"""
all_input_dims = set(sum([s.dims for s in inpu... | python | def verify_no_new_dims(input_shapes, output_shape):
"""Verifies that all dimensions in the output are in at least one input.
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Raises:
ValueError: if there are new dimensions in the output.
"""
all_input_dims = set(sum([s.dims for s in inpu... | [
"def",
"verify_no_new_dims",
"(",
"input_shapes",
",",
"output_shape",
")",
":",
"all_input_dims",
"=",
"set",
"(",
"sum",
"(",
"[",
"s",
".",
"dims",
"for",
"s",
"in",
"input_shapes",
"]",
",",
"[",
"]",
")",
")",
"all_output_dims",
"=",
"set",
"(",
"... | Verifies that all dimensions in the output are in at least one input.
Args:
input_shapes: a list of Shapes
output_shape: a Shape
Raises:
ValueError: if there are new dimensions in the output. | [
"Verifies",
"that",
"all",
"dimensions",
"in",
"the",
"output",
"are",
"in",
"at",
"least",
"one",
"input",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4259-L4274 |
227,882 | tensorflow/mesh | mesh_tensorflow/ops.py | pnum_to_processor_coordinates | def pnum_to_processor_coordinates(mesh_shape, pnum):
"""Coordinates of a processor in the mesh.
Args:
mesh_shape: a Shape
pnum: an integer less than len(mesh_shape)
Returns:
a list of integers with length len(mesh_shape)
"""
ret = []
for dimsize in mesh_shape.to_integer_list[::-1]:
ret.app... | python | def pnum_to_processor_coordinates(mesh_shape, pnum):
"""Coordinates of a processor in the mesh.
Args:
mesh_shape: a Shape
pnum: an integer less than len(mesh_shape)
Returns:
a list of integers with length len(mesh_shape)
"""
ret = []
for dimsize in mesh_shape.to_integer_list[::-1]:
ret.app... | [
"def",
"pnum_to_processor_coordinates",
"(",
"mesh_shape",
",",
"pnum",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"dimsize",
"in",
"mesh_shape",
".",
"to_integer_list",
"[",
":",
":",
"-",
"1",
"]",
":",
"ret",
".",
"append",
"(",
"pnum",
"%",
"dimsize",
... | Coordinates of a processor in the mesh.
Args:
mesh_shape: a Shape
pnum: an integer less than len(mesh_shape)
Returns:
a list of integers with length len(mesh_shape) | [
"Coordinates",
"of",
"a",
"processor",
"in",
"the",
"mesh",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4277-L4291 |
227,883 | tensorflow/mesh | mesh_tensorflow/ops.py | processor_coordinates_to_pnum | def processor_coordinates_to_pnum(mesh_shape, coord):
"""Inverse of pnum_to_processor_coordinates.
Args:
mesh_shape: a Shape
coord: a list of integers with length len(mesh_shape)
Returns:
an integer less than len(mesh_shape)
"""
ret = 0
multiplier = 1
for c, d in zip(coord[::-1], mesh_shape.... | python | def processor_coordinates_to_pnum(mesh_shape, coord):
"""Inverse of pnum_to_processor_coordinates.
Args:
mesh_shape: a Shape
coord: a list of integers with length len(mesh_shape)
Returns:
an integer less than len(mesh_shape)
"""
ret = 0
multiplier = 1
for c, d in zip(coord[::-1], mesh_shape.... | [
"def",
"processor_coordinates_to_pnum",
"(",
"mesh_shape",
",",
"coord",
")",
":",
"ret",
"=",
"0",
"multiplier",
"=",
"1",
"for",
"c",
",",
"d",
"in",
"zip",
"(",
"coord",
"[",
":",
":",
"-",
"1",
"]",
",",
"mesh_shape",
".",
"to_integer_list",
"[",
... | Inverse of pnum_to_processor_coordinates.
Args:
mesh_shape: a Shape
coord: a list of integers with length len(mesh_shape)
Returns:
an integer less than len(mesh_shape) | [
"Inverse",
"of",
"pnum_to_processor_coordinates",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4294-L4309 |
227,884 | tensorflow/mesh | mesh_tensorflow/ops.py | pnum_to_group | def pnum_to_group(mesh_shape, group_dims, pnum):
"""Group number for grouped allreduce.
Args:
mesh_shape: a Shape
group_dims: a list of integers (the dimensions reduced over)
pnum: an integer
Returns:
an integer
"""
coord = pnum_to_processor_coordinates(mesh_shape, pnum)
remaining_shape = ... | python | def pnum_to_group(mesh_shape, group_dims, pnum):
"""Group number for grouped allreduce.
Args:
mesh_shape: a Shape
group_dims: a list of integers (the dimensions reduced over)
pnum: an integer
Returns:
an integer
"""
coord = pnum_to_processor_coordinates(mesh_shape, pnum)
remaining_shape = ... | [
"def",
"pnum_to_group",
"(",
"mesh_shape",
",",
"group_dims",
",",
"pnum",
")",
":",
"coord",
"=",
"pnum_to_processor_coordinates",
"(",
"mesh_shape",
",",
"pnum",
")",
"remaining_shape",
"=",
"Shape",
"(",
"[",
"d",
"for",
"i",
",",
"d",
"in",
"enumerate",
... | Group number for grouped allreduce.
Args:
mesh_shape: a Shape
group_dims: a list of integers (the dimensions reduced over)
pnum: an integer
Returns:
an integer | [
"Group",
"number",
"for",
"grouped",
"allreduce",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4312-L4327 |
227,885 | tensorflow/mesh | mesh_tensorflow/ops.py | processor_groups | def processor_groups(mesh_shape, group_dims):
"""Groups of processors which differ only in the given dimensions.
Args:
mesh_shape: a Shape
group_dims: a list of integers
Returns:
a list of lists of integers (processor numbers)
"""
group_numbers = [
pnum_to_group(mesh_shape, group_dims, pnu... | python | def processor_groups(mesh_shape, group_dims):
"""Groups of processors which differ only in the given dimensions.
Args:
mesh_shape: a Shape
group_dims: a list of integers
Returns:
a list of lists of integers (processor numbers)
"""
group_numbers = [
pnum_to_group(mesh_shape, group_dims, pnu... | [
"def",
"processor_groups",
"(",
"mesh_shape",
",",
"group_dims",
")",
":",
"group_numbers",
"=",
"[",
"pnum_to_group",
"(",
"mesh_shape",
",",
"group_dims",
",",
"pnum",
")",
"for",
"pnum",
"in",
"xrange",
"(",
"mesh_shape",
".",
"size",
")",
"]",
"ret",
"... | Groups of processors which differ only in the given dimensions.
Args:
mesh_shape: a Shape
group_dims: a list of integers
Returns:
a list of lists of integers (processor numbers) | [
"Groups",
"of",
"processors",
"which",
"differ",
"only",
"in",
"the",
"given",
"dimensions",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4330-L4348 |
227,886 | tensorflow/mesh | mesh_tensorflow/ops.py | mtf_range | def mtf_range(mesh, dim, dtype, name=None):
"""Create a 1d mesh tensor with a range from [0, dim.size).
Call externally as mtf.range()
Args:
mesh: a Mesh
dim: a Dimension
dtype: a tf.DType
name: an optional string
Returns:
a Tensor
"""
dim = convert_to_dimension(dim)
with tf.variabl... | python | def mtf_range(mesh, dim, dtype, name=None):
"""Create a 1d mesh tensor with a range from [0, dim.size).
Call externally as mtf.range()
Args:
mesh: a Mesh
dim: a Dimension
dtype: a tf.DType
name: an optional string
Returns:
a Tensor
"""
dim = convert_to_dimension(dim)
with tf.variabl... | [
"def",
"mtf_range",
"(",
"mesh",
",",
"dim",
",",
"dtype",
",",
"name",
"=",
"None",
")",
":",
"dim",
"=",
"convert_to_dimension",
"(",
"dim",
")",
"with",
"tf",
".",
"variable_scope",
"(",
"name",
",",
"default_name",
"=",
"\"range\"",
")",
":",
"if",... | Create a 1d mesh tensor with a range from [0, dim.size).
Call externally as mtf.range()
Args:
mesh: a Mesh
dim: a Dimension
dtype: a tf.DType
name: an optional string
Returns:
a Tensor | [
"Create",
"a",
"1d",
"mesh",
"tensor",
"with",
"a",
"range",
"from",
"[",
"0",
"dim",
".",
"size",
")",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4406-L4428 |
227,887 | tensorflow/mesh | mesh_tensorflow/ops.py | pretty_print_counters | def pretty_print_counters(counters):
"""print counters hierarchically.
Each counter is a pair of a string and a number.
The string can have slashes, meaning that the number also counts towards
each prefix. e.g. "parameters/trainable" counts towards both "parameters"
and "parameters/trainable".
Args:
... | python | def pretty_print_counters(counters):
"""print counters hierarchically.
Each counter is a pair of a string and a number.
The string can have slashes, meaning that the number also counts towards
each prefix. e.g. "parameters/trainable" counts towards both "parameters"
and "parameters/trainable".
Args:
... | [
"def",
"pretty_print_counters",
"(",
"counters",
")",
":",
"totals",
"=",
"collections",
".",
"defaultdict",
"(",
"int",
")",
"for",
"(",
"name",
",",
"val",
")",
"in",
"counters",
":",
"prefixes",
"=",
"[",
"name",
"[",
":",
"i",
"]",
"for",
"i",
"i... | print counters hierarchically.
Each counter is a pair of a string and a number.
The string can have slashes, meaning that the number also counts towards
each prefix. e.g. "parameters/trainable" counts towards both "parameters"
and "parameters/trainable".
Args:
counters: a list of (string, number) pair... | [
"print",
"counters",
"hierarchically",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4431-L4453 |
227,888 | tensorflow/mesh | mesh_tensorflow/ops.py | _parse_string_to_list_of_pairs | def _parse_string_to_list_of_pairs(s, seconds_to_int=False):
r"""Parses a string into a list of pairs.
In the input string, each pair is separated by a colon, and the delimiters
between pairs are any of " ,.;".
e.g. "rows:32,cols:32"
Args:
s: str to parse.
seconds_to_int: Boolean. If True, then the... | python | def _parse_string_to_list_of_pairs(s, seconds_to_int=False):
r"""Parses a string into a list of pairs.
In the input string, each pair is separated by a colon, and the delimiters
between pairs are any of " ,.;".
e.g. "rows:32,cols:32"
Args:
s: str to parse.
seconds_to_int: Boolean. If True, then the... | [
"def",
"_parse_string_to_list_of_pairs",
"(",
"s",
",",
"seconds_to_int",
"=",
"False",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"p",
"in",
"[",
"s",
".",
"split",
"(",
"\":\"",
")",
"for",
"s",
"in",
"re",
".",
"sub",
"(",
"\"[,.;]\"",
",",
"\" \"",
... | r"""Parses a string into a list of pairs.
In the input string, each pair is separated by a colon, and the delimiters
between pairs are any of " ,.;".
e.g. "rows:32,cols:32"
Args:
s: str to parse.
seconds_to_int: Boolean. If True, then the second elements are returned
as integers; otherwise the... | [
"r",
"Parses",
"a",
"string",
"into",
"a",
"list",
"of",
"pairs",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4456-L4483 |
227,889 | tensorflow/mesh | mesh_tensorflow/ops.py | parallel | def parallel(devices, fn, *args, **kwargs):
"""Call a function once on each device.
Args:
devices: a list of n devices
fn: a function
*args: arguments, each of which is a list of length n
**kwargs: keyword-args, each of which is a list of length n
Returns:
a list of length n
Raises:
Val... | python | def parallel(devices, fn, *args, **kwargs):
"""Call a function once on each device.
Args:
devices: a list of n devices
fn: a function
*args: arguments, each of which is a list of length n
**kwargs: keyword-args, each of which is a list of length n
Returns:
a list of length n
Raises:
Val... | [
"def",
"parallel",
"(",
"devices",
",",
"fn",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"isinstance",
"(",
"devices",
",",
"list",
")",
":",
"raise",
"ValueError",
"(",
"\"devices must be a list\"",
")",
"for",
"x",
"in",
"list"... | Call a function once on each device.
Args:
devices: a list of n devices
fn: a function
*args: arguments, each of which is a list of length n
**kwargs: keyword-args, each of which is a list of length n
Returns:
a list of length n
Raises:
ValueError: if the arguments are not all lists of le... | [
"Call",
"a",
"function",
"once",
"on",
"each",
"device",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4486-L4513 |
227,890 | tensorflow/mesh | mesh_tensorflow/ops.py | random_uniform | def random_uniform(mesh, shape, **kwargs):
"""Random uniform.
Args:
mesh: a Mesh
shape: a Shape
**kwargs: keyword args for tf.random.uniform, except seed
Returns:
a Tensor
"""
shape = convert_to_shape(shape)
return RandomOperation(mesh, shape, tf.random.uniform, **kwargs).outputs[0] | python | def random_uniform(mesh, shape, **kwargs):
"""Random uniform.
Args:
mesh: a Mesh
shape: a Shape
**kwargs: keyword args for tf.random.uniform, except seed
Returns:
a Tensor
"""
shape = convert_to_shape(shape)
return RandomOperation(mesh, shape, tf.random.uniform, **kwargs).outputs[0] | [
"def",
"random_uniform",
"(",
"mesh",
",",
"shape",
",",
"*",
"*",
"kwargs",
")",
":",
"shape",
"=",
"convert_to_shape",
"(",
"shape",
")",
"return",
"RandomOperation",
"(",
"mesh",
",",
"shape",
",",
"tf",
".",
"random",
".",
"uniform",
",",
"*",
"*",... | Random uniform.
Args:
mesh: a Mesh
shape: a Shape
**kwargs: keyword args for tf.random.uniform, except seed
Returns:
a Tensor | [
"Random",
"uniform",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4611-L4623 |
227,891 | tensorflow/mesh | mesh_tensorflow/ops.py | dropout | def dropout(x, keep_prob, noise_shape=None, name=None):
"""Dropout layer.
Args:
x: a Tensor
keep_prob: a float between 0.0 and 1.0
noise_shape: an optional Shape (a subset of x.shape)
name: an optional string
Returns:
a Tensor
"""
noise_shape = convert_to_shape(noise_shape)
if noise_sh... | python | def dropout(x, keep_prob, noise_shape=None, name=None):
"""Dropout layer.
Args:
x: a Tensor
keep_prob: a float between 0.0 and 1.0
noise_shape: an optional Shape (a subset of x.shape)
name: an optional string
Returns:
a Tensor
"""
noise_shape = convert_to_shape(noise_shape)
if noise_sh... | [
"def",
"dropout",
"(",
"x",
",",
"keep_prob",
",",
"noise_shape",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"noise_shape",
"=",
"convert_to_shape",
"(",
"noise_shape",
")",
"if",
"noise_shape",
"is",
"None",
":",
"noise_shape",
"=",
"x",
".",
"sha... | Dropout layer.
Args:
x: a Tensor
keep_prob: a float between 0.0 and 1.0
noise_shape: an optional Shape (a subset of x.shape)
name: an optional string
Returns:
a Tensor | [
"Dropout",
"layer",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4626-L4647 |
227,892 | tensorflow/mesh | mesh_tensorflow/ops.py | _cumprod | def _cumprod(l):
"""Cumulative product of a list.
Args:
l: a list of integers
Returns:
a list with one more element (starting with 1)
"""
ret = [1]
for item in l:
ret.append(ret[-1] * item)
return ret | python | def _cumprod(l):
"""Cumulative product of a list.
Args:
l: a list of integers
Returns:
a list with one more element (starting with 1)
"""
ret = [1]
for item in l:
ret.append(ret[-1] * item)
return ret | [
"def",
"_cumprod",
"(",
"l",
")",
":",
"ret",
"=",
"[",
"1",
"]",
"for",
"item",
"in",
"l",
":",
"ret",
".",
"append",
"(",
"ret",
"[",
"-",
"1",
"]",
"*",
"item",
")",
"return",
"ret"
] | Cumulative product of a list.
Args:
l: a list of integers
Returns:
a list with one more element (starting with 1) | [
"Cumulative",
"product",
"of",
"a",
"list",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4650-L4661 |
227,893 | tensorflow/mesh | mesh_tensorflow/ops.py | while_loop | def while_loop(cond_fn, body_fn, inputs, num_loop_vars=None,
has_accumulators=False, **kwargs):
"""While Loop.
See comments above for WhileLoopOperation
num_loop_vars is a hack for the multi-gpu setup. In this case, loops
are generally slow, as all loop variables are placed on device. By sett... | python | def while_loop(cond_fn, body_fn, inputs, num_loop_vars=None,
has_accumulators=False, **kwargs):
"""While Loop.
See comments above for WhileLoopOperation
num_loop_vars is a hack for the multi-gpu setup. In this case, loops
are generally slow, as all loop variables are placed on device. By sett... | [
"def",
"while_loop",
"(",
"cond_fn",
",",
"body_fn",
",",
"inputs",
",",
"num_loop_vars",
"=",
"None",
",",
"has_accumulators",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"num_loop_vars",
"is",
"None",
":",
"return",
"WhileLoopOperation",
"(",
... | While Loop.
See comments above for WhileLoopOperation
num_loop_vars is a hack for the multi-gpu setup. In this case, loops
are generally slow, as all loop variables are placed on device. By setting
num_loop_vars=k, then all of the loop variables except for the first k
are handled as mtf Variables instead ... | [
"While",
"Loop",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4855-L4910 |
227,894 | tensorflow/mesh | mesh_tensorflow/ops.py | _shape_union | def _shape_union(shapes):
"""A shape containing the union of all dimensions in the input shapes.
Args:
shapes: a list of Shapes
Returns:
a Shape
"""
return Shape(sorted(list(set(sum([s.dims for s in shapes], []))))) | python | def _shape_union(shapes):
"""A shape containing the union of all dimensions in the input shapes.
Args:
shapes: a list of Shapes
Returns:
a Shape
"""
return Shape(sorted(list(set(sum([s.dims for s in shapes], []))))) | [
"def",
"_shape_union",
"(",
"shapes",
")",
":",
"return",
"Shape",
"(",
"sorted",
"(",
"list",
"(",
"set",
"(",
"sum",
"(",
"[",
"s",
".",
"dims",
"for",
"s",
"in",
"shapes",
"]",
",",
"[",
"]",
")",
")",
")",
")",
")"
] | A shape containing the union of all dimensions in the input shapes.
Args:
shapes: a list of Shapes
Returns:
a Shape | [
"A",
"shape",
"containing",
"the",
"union",
"of",
"all",
"dimensions",
"in",
"the",
"input",
"shapes",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4921-L4930 |
227,895 | tensorflow/mesh | mesh_tensorflow/ops.py | _tf_flatten_batch_dims | def _tf_flatten_batch_dims(x, num_nonbatch_dims):
"""Flatten all but last num_nonbatch_dims into one dimension.
Args:
x: a tf.Tensor:
num_nonbatch_dims: an integer
Returns:
a tf.Tensor with 1 + num_nonbatch_dims dimensions.
"""
shape = x.shape.as_list()
assert None not in shape
new_shape = (... | python | def _tf_flatten_batch_dims(x, num_nonbatch_dims):
"""Flatten all but last num_nonbatch_dims into one dimension.
Args:
x: a tf.Tensor:
num_nonbatch_dims: an integer
Returns:
a tf.Tensor with 1 + num_nonbatch_dims dimensions.
"""
shape = x.shape.as_list()
assert None not in shape
new_shape = (... | [
"def",
"_tf_flatten_batch_dims",
"(",
"x",
",",
"num_nonbatch_dims",
")",
":",
"shape",
"=",
"x",
".",
"shape",
".",
"as_list",
"(",
")",
"assert",
"None",
"not",
"in",
"shape",
"new_shape",
"=",
"(",
"[",
"list_product",
"(",
"shape",
"[",
":",
"-",
"... | Flatten all but last num_nonbatch_dims into one dimension.
Args:
x: a tf.Tensor:
num_nonbatch_dims: an integer
Returns:
a tf.Tensor with 1 + num_nonbatch_dims dimensions. | [
"Flatten",
"all",
"but",
"last",
"num_nonbatch_dims",
"into",
"one",
"dimension",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4933-L4949 |
227,896 | tensorflow/mesh | mesh_tensorflow/ops.py | _tf_restore_batch_dims | def _tf_restore_batch_dims(x, num_nonbatch_dims, prototype):
"""Reverse op of _tf_flatten_batch_dims.
Un-flatten the first dimension of x to match all but the last
num_nonbatch_dims dimensions of prototype.
Args:
x: a tf.Tensor with 1 + num_nonbatch_dims dimensions
num_nonbatch_dims: an integer
pr... | python | def _tf_restore_batch_dims(x, num_nonbatch_dims, prototype):
"""Reverse op of _tf_flatten_batch_dims.
Un-flatten the first dimension of x to match all but the last
num_nonbatch_dims dimensions of prototype.
Args:
x: a tf.Tensor with 1 + num_nonbatch_dims dimensions
num_nonbatch_dims: an integer
pr... | [
"def",
"_tf_restore_batch_dims",
"(",
"x",
",",
"num_nonbatch_dims",
",",
"prototype",
")",
":",
"assert",
"x",
".",
"shape",
".",
"ndims",
"==",
"1",
"+",
"num_nonbatch_dims",
"new_shape",
"=",
"(",
"prototype",
".",
"shape",
".",
"as_list",
"(",
")",
"["... | Reverse op of _tf_flatten_batch_dims.
Un-flatten the first dimension of x to match all but the last
num_nonbatch_dims dimensions of prototype.
Args:
x: a tf.Tensor with 1 + num_nonbatch_dims dimensions
num_nonbatch_dims: an integer
prototype: a tf.Tensor
Returns:
a tf.Tensor | [
"Reverse",
"op",
"of",
"_tf_flatten_batch_dims",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4952-L4972 |
227,897 | tensorflow/mesh | mesh_tensorflow/ops.py | halo_exchange | def halo_exchange(x, blocks_dim, block_size_dim, halo_size, wrap=False):
"""Concat each block with the margins of adjacent blocks.
Get left and right blocks_dim and concatenate along block_size_dim.
Args:
x: a Tensor.
blocks_dim: a Dimension in x.shape
block_size_dim: a Dimension in x.shape
halo... | python | def halo_exchange(x, blocks_dim, block_size_dim, halo_size, wrap=False):
"""Concat each block with the margins of adjacent blocks.
Get left and right blocks_dim and concatenate along block_size_dim.
Args:
x: a Tensor.
blocks_dim: a Dimension in x.shape
block_size_dim: a Dimension in x.shape
halo... | [
"def",
"halo_exchange",
"(",
"x",
",",
"blocks_dim",
",",
"block_size_dim",
",",
"halo_size",
",",
"wrap",
"=",
"False",
")",
":",
"if",
"halo_size",
"==",
"0",
":",
"return",
"x",
"block_size",
"=",
"block_size_dim",
".",
"size",
"partial_size",
"=",
"hal... | Concat each block with the margins of adjacent blocks.
Get left and right blocks_dim and concatenate along block_size_dim.
Args:
x: a Tensor.
blocks_dim: a Dimension in x.shape
block_size_dim: a Dimension in x.shape
halo_size: an integer
wrap: a boolean
Returns:
a Tensor with the same s... | [
"Concat",
"each",
"block",
"with",
"the",
"margins",
"of",
"adjacent",
"blocks",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L4975-L5011 |
227,898 | tensorflow/mesh | mesh_tensorflow/ops.py | conv2d_with_blocks | def conv2d_with_blocks(
conv_input,
conv_filter,
strides,
padding,
h_blocks_dim=None,
w_blocks_dim=None,
name=None):
"""conv2d operation with spatial partitioning.
Spatial partitioning is implemented by decomposing the image into blocks.
Block dimensions represented as h_blocks_dim an... | python | def conv2d_with_blocks(
conv_input,
conv_filter,
strides,
padding,
h_blocks_dim=None,
w_blocks_dim=None,
name=None):
"""conv2d operation with spatial partitioning.
Spatial partitioning is implemented by decomposing the image into blocks.
Block dimensions represented as h_blocks_dim an... | [
"def",
"conv2d_with_blocks",
"(",
"conv_input",
",",
"conv_filter",
",",
"strides",
",",
"padding",
",",
"h_blocks_dim",
"=",
"None",
",",
"w_blocks_dim",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"filter_h_dim",
",",
"filter_w_dim",
"=",
"conv_filter",... | conv2d operation with spatial partitioning.
Spatial partitioning is implemented by decomposing the image into blocks.
Block dimensions represented as h_blocks_dim and w_blocks_dim can be split
along the mesh axis. If split, then we do a halo exchange where each block
receives the part of the image from its lef... | [
"conv2d",
"operation",
"with",
"spatial",
"partitioning",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L5049-L5108 |
227,899 | tensorflow/mesh | mesh_tensorflow/ops.py | tensor_dim_to_mesh_dim_size | def tensor_dim_to_mesh_dim_size(layout, mesh_shape, tensor_dim):
"""How many ways does a tensor dimension get split.
This is used to "cheat" when building the mtf graph and peek at how a
tensor dimension will be split. Returns 1 if the tensor dimension is not
split.
Args:
layout: an input to convert_to... | python | def tensor_dim_to_mesh_dim_size(layout, mesh_shape, tensor_dim):
"""How many ways does a tensor dimension get split.
This is used to "cheat" when building the mtf graph and peek at how a
tensor dimension will be split. Returns 1 if the tensor dimension is not
split.
Args:
layout: an input to convert_to... | [
"def",
"tensor_dim_to_mesh_dim_size",
"(",
"layout",
",",
"mesh_shape",
",",
"tensor_dim",
")",
":",
"layout_rules",
"=",
"convert_to_layout_rules",
"(",
"layout",
")",
"mesh_shape",
"=",
"convert_to_shape",
"(",
"mesh_shape",
")",
"mesh_axis",
"=",
"layout_rules",
... | How many ways does a tensor dimension get split.
This is used to "cheat" when building the mtf graph and peek at how a
tensor dimension will be split. Returns 1 if the tensor dimension is not
split.
Args:
layout: an input to convert_to_layout_rules
mesh_shape: an input to convert_to_shape
tensor_... | [
"How",
"many",
"ways",
"does",
"a",
"tensor",
"dimension",
"get",
"split",
"."
] | 3921196e5e43302e820da0a87329f25d7e2a3016 | https://github.com/tensorflow/mesh/blob/3921196e5e43302e820da0a87329f25d7e2a3016/mesh_tensorflow/ops.py#L5111-L5132 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.