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

Function _wrap_label

tensorflow/tools/compatibility/tf_upgrade_v2.py:1821–1842  ·  view source on GitHub ↗

Wrap labels with tf.stop_gradient.

(parent, old_value)

Source from the content-addressed store, hash-verified

1819 parent, node, full_name, name, logs):
1820 """Wrap labels argument with stop_gradients."""
1821 def _wrap_label(parent, old_value):
1822 """Wrap labels with tf.stop_gradient."""
1823 already_stop_grad = (isinstance(old_value, ast.Call) and
1824 isinstance(old_value.func, ast.Attribute) and
1825 old_value.func.attr == "stop_gradient" and
1826 isinstance(old_value.func.value, ast.Name) and
1827 old_value.func.value.id == "tf")
1828 if already_stop_grad:
1829 return False
1830 try:
1831 new_value = ast.Call(
1832 ast.Name(id="tf.stop_gradient", ctx=ast.Load()),
1833 [old_value], [])
1834 except TypeError:
1835 new_value = ast.Call(
1836 ast.Name(id="tf.stop_gradient", ctx=ast.Load()),
1837 [old_value], [], None, None)
1838
1839 # This copies the prefix and suffix on old_value to new_value.
1840 pasta.ast_utils.replace_child(parent, old_value, new_value)
1841 ast.copy_location(new_value, old_value)
1842 return True
1843
1844 # Check if we have a labels keyword arg
1845 for karg in node.keywords:

Calls 3

CallMethod · 0.45
NameMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected