MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / subscribe

Function subscribe

tensorflow/python/framework/subscribe.py:312–354  ·  view source on GitHub ↗

Subscribe to a tensor. This method will attach side effect graphs to a given set of tensors. Set of tensors follows from session.run and supports single `Tensor`, `list`, nested `list`, `tuple`, `namedtuple`, or `dict`. It returns the tensors in the same passed in structure, but as clones w

(tensors, side_effects)

Source from the content-addressed store, hash-verified

310
311
312def subscribe(tensors, side_effects):
313 """Subscribe to a tensor.
314
315 This method will attach side effect graphs to a given set
316 of tensors. Set of tensors follows from session.run and supports
317 single `Tensor`, `list`, nested `list`, `tuple`, `namedtuple`, or `dict`. It
318 returns the tensors in the same passed in structure, but as clones with
319 side effects applied. The supplied side effect graphs are specified
320 as a constructor function which takes the target tensor and
321 constructs a side effect graph and returns a list of ops that should
322 be control dependencies on fetching the tensor. It will append
323 'subscription' to the name scope of the tensor for every node in
324 the side effect graph. These control dependencies are what trigger
325 the side effects. Subscribe will construct the additions to your
326 graph and return the created identity tensor downstream of the control
327 dependencies. Use these tensors as you would normally in the rest of
328 your tensorflow code. If a given tensor has already been subscribed or a
329 tensor returned by a call to subscribe is passed, the previously created
330 identity tensor will be reused and the side effect graphs will be added to
331 the existing ones.
332
333 Args:
334 tensors: `Tensor` or set of tensors to subscribe to. Set of tensors format
335 follows from `Session.run` and supports single `Tensor`, `list`, nested
336 `list`, `tuple`, `namedtuple`, or `dict`.
337 side_effects: Function(s) that takes a `Tensor`, construct a subgraph, and
338 return a nonempty list of control dependencies. This can be a single
339 function or list of functions.
340
341 Returns:
342 Subscribed tensors, which are identity copies of the passed in tensors
343 in the same passed in structure, but the graph has been modified
344 such that these are downstream of the control dependencies for
345 the side effect graphs. Use these functionally equivalent tensors
346 instead of the passed in tensors for further construction or running.
347 """
348 if not hasattr(side_effects, '__iter__'):
349 side_effects = [side_effects]
350
351 control_outputs = _ControlOutputCache()
352 result = _recursive_apply(
353 tensors, lambda t: _scoped_subscribe(t, side_effects, control_outputs))
354 return result

Callers

nothing calls this directly

Calls 3

_ControlOutputCacheClass · 0.85
_recursive_applyFunction · 0.85
_scoped_subscribeFunction · 0.85

Tested by

no test coverage detected