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

Function _ensure_unique_tensor_objects

tensorflow/python/eager/backprop.py:374–403  ·  view source on GitHub ↗

Make each of the parameter_positions in args a unique ops.Tensor object. Ensure that each parameter is treated independently. For example: def f(x, y): return x * y g = gradients_function(f) one = tf.constant(1.) g(one, one) should return [1., 1.] (even though the two arguments are

(parameter_positions, args)

Source from the content-addressed store, hash-verified

372
373
374def _ensure_unique_tensor_objects(parameter_positions, args):
375 """Make each of the parameter_positions in args a unique ops.Tensor object.
376
377 Ensure that each parameter is treated independently.
378 For example:
379
380 def f(x, y): return x * y
381 g = gradients_function(f)
382 one = tf.constant(1.)
383
384 g(one, one) should return [1., 1.]
385 (even though the two arguments are the same Tensor object).
386
387 Args:
388 parameter_positions: List of indices into args defining the arguments to
389 differentiate against.
390 args: A list of arguments to the function to be differentiated.
391
392 Returns:
393 args, possibly edited in-place.
394 """
395 s = set()
396 for (i, t) in enumerate(args):
397 if i in parameter_positions:
398 tid = ops.tensor_id(t)
399 if tid in s:
400 args[i] = gen_array_ops.identity(args[i])
401 else:
402 s.add(tid)
403 return args
404
405
406def val_and_grad_function(f, params=None):

Callers 1

decoratedFunction · 0.85

Calls 3

tensor_idMethod · 0.45
identityMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected