@propertydefpropagator(self):returnself._propagator@propertydeftrace_graph(self):"""Aggregate the graphs of all the parameters."""returnsum_feedback(self.parameters)
[docs]defpropose(self,*args,**kwargs):"""Propose the new data of the parameters based on the feedback."""returnself._step(*args,**kwargs)
[docs]defupdate(self,update_dict:Dict[ParameterNode,Any]):"""Update the trainable parameters given a dictionary of new data."""forp,dinupdate_dict.items():ifp.trainable:p._data=d
# Subclass should implement the methods below.def_step(self,*args,**kwargs)->Dict[ParameterNode,Any]:"""Return the new data of parameter nodes based on the feedback."""raiseNotImplementedError
[docs]defdefault_propagator(self):"""Return the default Propagator object of the optimizer."""returnGraphPropagator()
[docs]defbackward(self,node:Node,*args,**kwargs):"""Propagate the feedback backward."""returnnode.backward(*args,propagator=self.propagator,**kwargs)