Wrap labels with tf.stop_gradient.
(parent, old_value)
| 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: |
no test coverage detected