Graph Item¶
GraphItem and its supporting functionality.
-
cached_property
(fn, *args, **kwargs)[source]¶ Decorator to make a function a “cached property”.
This means that it is a property whose return value is cached after the first time it is called.
- Parameters
fn – The function to be made a cached property
*args – Any args for the function
**kwargs – Any kwargs for the function
- Returns
function
-
get_default_graph_item
()[source]¶ Get the current default graph_item under the graph_item scope.
- Returns
GraphItem
-
wrap_optimizer_init
(fn: Callable)[source]¶ Wraps the __init__ function of OptimizerV2 objects and stores the info in the default GraphItem.
-
wrap_optimizer_apply_gradient
(fn: Callable)[source]¶ Wraps the apply_gradients function of OptimizerV2 objects and stores the info in the default GraphItem.
-
class
Info
[source]¶ Bases:
object
Stores useful variable tracking information.
In essence, replaces collections, and this way we don’t have to deal with MetaGraphs.
-
update_variables
(variables, replace=True)[source]¶ Update variables in GraphItem Info.
- Parameters
variables (Iterable[VariableType]) – Iterable of variables to insert.
replace (bool) – Whether or not to overwrite existing contents.
-
update_table_initializers
(table_initializers, replace=True)[source]¶ Update table initializers in GraphItem Info.
-
-
class
GraphItem
(graph: Optional[tensorflow.python.framework.ops.Graph] = None, graph_def: Optional[tensorflow.core.framework.graph_pb2.GraphDef] = None)[source]¶ Bases:
object
GraphItem is a TensorFlow Graph wrapper.
It represents the states in-between consecutive AutoDist.kernel graph transformations. tf.Graph is the primary property of GraphItem, whereas MetaGraph is exported/generated on demand.
A GraphItem can be constructed with either a tf.Graph or a GraphDef.
-
get_trainable_variables
()[source]¶ Get variables that need to be synchronized if doing data parallelism.
-
extend_optimizer_info
(optimizer, *args, **kwargs)[source]¶ Add the detected optimizer to the object.
-
extend_gradient_info_by_names
(grads, targets)[source]¶ Add the detected grad-target pairs to the object by names.
-
property
all_update_ops
[source]¶ Get all ops in the graph that perform stateful operations.
- Returns
List
-
property
var_op_name_to_grad_info
[source]¶ 0”) to its (grad, var, update_op) tuple.
- Type
A mapping from VarHandleOp name (e.g. “W” not “W
-
property
var_op_name_to_grad_info_v2
[source]¶ An optimized version that is aware of this method is iteratively used. It optimize based on.
Give an updated option, if the graph has not been updated before this query, then it will not calculate again. A new method considering this v2 method needs to manipulate updated outside.
Give an var_queried option, which will record which variable has been doen synchronized. If all the variable associated with an update op has been synchronized, this method will not consier the update op next time (it will reconsider if the current loop has done processed, so the set/reset optimize method is necessary to set the boolean flags). This optimization is inspired by that the for loop in this method is executed for every update_op, which is typically a lot, and causes the slowness. This option is safe in that if the var_queried is not set outside, it will not trigger the remove op.
-
property
grad_target_name_pairs
[source]¶ List of names of grad and target variable pairs.
- Returns
List
-
property
trainable_var_op_to_var
[source]¶ Mapping from trainable variable ops (e.g. VarHandleOps) to the Variables.
- Returns
Dict
-
get_colocation_op
(colocation_group)[source]¶ Get the binding op for a given colocation group.
- Parameters
colocation_group (bytes) – The colocation group
- Returns
Op
-