Class BasicGradientsAccumulator
- java.lang.Object
-
- org.deeplearning4j.optimize.solvers.accumulation.BasicGradientsAccumulator
-
- All Implemented Interfaces:
Serializable,GradientsAccumulator
public class BasicGradientsAccumulator extends Object implements GradientsAccumulator
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected CyclicBarrierbarrierprotected List<INDArray>candidatesprotected AtomicLongextCounterprotected AtomicLongfirstOneprotected IndexedTailgradientsprotected MessageHandlerhandlerprotected AtomicBooleanhasSomethingprotected charorderingprotected AtomicLongownCounterprotected intpartiesprotected long[]shapeprotected INDArraystorageprotected INDArrayupdatesprotected ReentrantReadWriteLockupdatesLock
-
Constructor Summary
Constructors Constructor Description BasicGradientsAccumulator(int parties)Creates new GradientsAccumulator with starting threshold of 1e-3BasicGradientsAccumulator(int parties, @NonNull MessageHandler handler)Creates new GradientsAccumulator with custom starting threshold
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyUpdate(StepFunction function, INDArray params, INDArray grad, boolean isFinalStep)This method applies accumulated updates via given StepFunctionvoidapplyUpdate(StepFunction function, INDArray params, INDArray grad, double alpha)This method applies accumulated updates via given StepFunctionIndexedTailgetExternalSource()booleanhasAnything()This method checks if there are any (probably external) updates availablevoidmarkExternalUpdates(boolean updatesAvailable)This method allows to highlight early availability of updatesvoidreceiveUpdate(INDArray array)This method accepts updates suitable for StepFunction and puts them to the queue, which is used in backpropagation loop PLEASE NOTE: array is expected to be ready for use and match params dimensionalityvoidreset()This method resets all accumulated updates (if any)voidsetExternalSource(IndexedTail source)This method allows to pass external updates to accumulator, they will be populated across all workers using this GradientsAccumulator instancevoidstoreUpdate(INDArray array, int iterationNumber, int epochNumber)This method accepts updates suitable for StepFunction, and accumulates/propagates it across all workersvoidtouch()This method does initialization of given worker wrt Thread-Device Affinity
-
-
-
Field Detail
-
handler
protected MessageHandler handler
-
gradients
protected transient IndexedTail gradients
-
storage
protected transient INDArray storage
-
updates
protected transient INDArray updates
-
ownCounter
protected transient AtomicLong ownCounter
-
extCounter
protected transient AtomicLong extCounter
-
shape
protected long[] shape
-
ordering
protected char ordering
-
parties
protected int parties
-
barrier
protected CyclicBarrier barrier
-
firstOne
protected AtomicLong firstOne
-
updatesLock
protected ReentrantReadWriteLock updatesLock
-
hasSomething
protected AtomicBoolean hasSomething
-
-
Constructor Detail
-
BasicGradientsAccumulator
public BasicGradientsAccumulator(int parties)
Creates new GradientsAccumulator with starting threshold of 1e-3
-
BasicGradientsAccumulator
public BasicGradientsAccumulator(int parties, @NonNull @NonNull MessageHandler handler)Creates new GradientsAccumulator with custom starting threshold- Parameters:
handler- MessageHandler instance that'll be used for communication purposes
-
-
Method Detail
-
getExternalSource
public IndexedTail getExternalSource()
- Specified by:
getExternalSourcein interfaceGradientsAccumulator
-
applyUpdate
public void applyUpdate(StepFunction function, INDArray params, INDArray grad, boolean isFinalStep)
This method applies accumulated updates via given StepFunction- Specified by:
applyUpdatein interfaceGradientsAccumulator- Parameters:
function-params-
-
markExternalUpdates
public void markExternalUpdates(boolean updatesAvailable)
Description copied from interface:GradientsAccumulatorThis method allows to highlight early availability of updates- Specified by:
markExternalUpdatesin interfaceGradientsAccumulator
-
applyUpdate
public void applyUpdate(StepFunction function, INDArray params, INDArray grad, double alpha)
This method applies accumulated updates via given StepFunction- Specified by:
applyUpdatein interfaceGradientsAccumulator- Parameters:
function-params-
-
storeUpdate
public void storeUpdate(INDArray array, int iterationNumber, int epochNumber)
This method accepts updates suitable for StepFunction, and accumulates/propagates it across all workers- Specified by:
storeUpdatein interfaceGradientsAccumulator- Parameters:
array-
-
receiveUpdate
public void receiveUpdate(INDArray array)
This method accepts updates suitable for StepFunction and puts them to the queue, which is used in backpropagation loop PLEASE NOTE: array is expected to be ready for use and match params dimensionality- Specified by:
receiveUpdatein interfaceGradientsAccumulator- Parameters:
array-
-
reset
public void reset()
This method resets all accumulated updates (if any)- Specified by:
resetin interfaceGradientsAccumulator
-
touch
public void touch()
This method does initialization of given worker wrt Thread-Device Affinity- Specified by:
touchin interfaceGradientsAccumulator
-
setExternalSource
public void setExternalSource(IndexedTail source)
Description copied from interface:GradientsAccumulatorThis method allows to pass external updates to accumulator, they will be populated across all workers using this GradientsAccumulator instance- Specified by:
setExternalSourcein interfaceGradientsAccumulator
-
hasAnything
public boolean hasAnything()
Description copied from interface:GradientsAccumulatorThis method checks if there are any (probably external) updates available- Specified by:
hasAnythingin interfaceGradientsAccumulator- Returns:
-
-