Return a slot named `name` created for `var` by the Optimizer. Some `Optimizer` subclasses use additional variables. For example `Momentum` and `Adagrad` use variables to accumulate updates. This method gives access to these `Variable` objects if for some reason you need them. Us
(self, var, name)
| 855 | return apply_fn() |
| 856 | |
| 857 | def get_slot(self, var, name): |
| 858 | """Return a slot named `name` created for `var` by the Optimizer. |
| 859 | |
| 860 | Some `Optimizer` subclasses use additional variables. For example |
| 861 | `Momentum` and `Adagrad` use variables to accumulate updates. This method |
| 862 | gives access to these `Variable` objects if for some reason you need them. |
| 863 | |
| 864 | Use `get_slot_names()` to get the list of slot names created by the |
| 865 | `Optimizer`. |
| 866 | |
| 867 | Args: |
| 868 | var: A variable passed to `minimize()` or `apply_gradients()`. |
| 869 | name: A string. |
| 870 | |
| 871 | Returns: |
| 872 | The `Variable` for the slot if it was created, `None` otherwise. |
| 873 | """ |
| 874 | # pylint: disable=protected-access |
| 875 | named_slots = self._slots.get(name, None) |
| 876 | if not named_slots: |
| 877 | return None |
| 878 | |
| 879 | if hasattr(var, "_distributed_container"): |
| 880 | # NOTE: If this isn't patched, then there is no `handle` in |
| 881 | # `_resource_apply_dense`. |
| 882 | distributed_container = var._distributed_container() |
| 883 | assert distributed_container is not None |
| 884 | if ops.executing_eagerly_outside_functions(): |
| 885 | key = distributed_container._unique_id |
| 886 | else: |
| 887 | key = (distributed_container.graph, distributed_container._shared_name) |
| 888 | # pylint: enable=protected-access |
| 889 | mirrored_slot = named_slots.get(key, None) |
| 890 | if mirrored_slot is None: return None |
| 891 | return mirrored_slot.get(device=var.device) |
| 892 | |
| 893 | return named_slots.get(_var_key(var), None) |
| 894 | |
| 895 | def get_slot_names(self): |
| 896 | """Return a list of the names of slots created by the `Optimizer`. |