This repository was archived by the owner on Nov 17, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -773,3 +773,40 @@ def grad_req(self, req):
773773 warnings .warn ('Constant parameter "{}" does not support '
774774 'grad_req other than "null", and new value "{}" '
775775 'is ignored.' .format (self .name , req ))
776+
777+ class Intermediate :
778+ """A Container holding marked intermediate variables of Blocks.
779+
780+ Parameters
781+ ----------
782+ name : str.
783+ Name of this parameter. It be used to retrieve the marked variables.
784+ grad_req : {'write', 'add', 'null'}, default 'write'
785+ Specifies how to update gradient to grad arrays.
786+
787+ - ``'write'`` means everytime gradient is written to grad :py:class:`NDArray`.
788+ - ``'add'`` means everytime gradient is added to the grad :py:class:`NDArray`. You need
789+ to manually call ``zero_grad()`` to clear the gradient buffer before each
790+ iteration when using this option.
791+ - 'null' means gradient is not requested for this parameter. gradient arrays
792+ will not be allocated.
793+ """
794+ def __init__ (self , name , data = None , grad_req = 'write' ):
795+ self ._name = name
796+ self ._data = data
797+ self ._grad_req = grad_req
798+
799+ def __repr__ (self ):
800+ s = 'Intermediate name={name}'
801+ return s .format (name = self ._name )
802+
803+ def data (self ):
804+ return self ._data
805+
806+ @property
807+ def name (self ):
808+ return self ._name
809+
810+ @property
811+ def grad_req (self ):
812+ return self ._grad_req
You can’t perform that action at this time.
0 commit comments