public class EncodedGradientsAccumulator extends Object implements GradientsAccumulator, Registerable
| Modifier and Type | Class and Description |
|---|---|
static class |
EncodedGradientsAccumulator.Builder |
| Constructor and Description |
|---|
EncodedGradientsAccumulator(int parties,
double threshold) |
EncodedGradientsAccumulator(int parties,
@NonNull MessageHandler handler,
long initialMemory,
int queueSize,
Integer boundary,
boolean encodingDebugMode) |
EncodedGradientsAccumulator(int parties,
ThresholdAlgorithm thresholdAlgorithm,
ResidualPostProcessor residualPostProcessor,
boolean encodingDebugMode) |
| Modifier and Type | Method and Description |
|---|---|
void |
applyUpdate(StepFunction function,
INDArray params,
INDArray updates,
boolean isFinalStep)
This method applies accumulated updates via given StepFunction
|
void |
applyUpdate(StepFunction function,
INDArray params,
INDArray updates,
double alpha)
This method applies accumulated updates via given StepFunction
|
void |
fallbackToSingleConsumerMode(boolean reallyFallback)
This method enables/disables bypass mode
|
IndexedTail |
getExternalSource() |
static long |
getOptimalBufferSize(long paramsLength,
int numWorkers,
int queueSize)
This method returns optimal bufferSize for a given model
We know, that updates are guaranteed to have MAX size of params / 16.
|
static long |
getOptimalBufferSize(Model model,
int numWorkers,
int queueSize) |
boolean |
hasAnything()
This method checks if there are any (probably external) updates available
|
void |
markExternalUpdates(boolean updatesAvailable)
This method allows to highlight early availability of updates
|
void |
receiveUpdate(INDArray array)
This method accepts updates suitable for StepFunction and puts them to the queue, which is used in backpropagation loop
|
void |
registerConsumers(int numConsumers)
This method notifies producer about number of consumers for the current consumption cycle
|
void |
reset()
This method resets all accumulated updates (if any)
|
void |
setExternalSource(IndexedTail source)
This method allows to pass external updates to accumulator, they will be populated across all workers using this GradientsAccumulator instance
|
void |
storeUpdate(INDArray array,
int iterationNumber,
int epochNumber)
This method accepts updates suitable for StepFunction, and accumulates/propagates it across all workers
|
protected void |
synchronize(int consumers) |
protected void |
synchronize(int consumers,
boolean finalLock) |
void |
touch()
This method does initialization of given worker wrt Thread-Device Affinity
|
public static final long DEFAULT_INITIAL_MEMORY
protected ThreadLocal<INDArray> accumulator
protected int parties
protected MessageHandler handler
protected List<BlockingQueue<INDArray>> messages
protected List<MemoryWorkspace> workspaces
protected List<ReentrantLock> locks
protected AtomicInteger workersCounter
protected ThreadLocal<Integer> index
protected long initialMemory
protected int queueSize
protected Integer boundary
protected boolean encodingDebugMode
protected IndexedTail externalSource
protected AtomicBoolean isFirst
protected AtomicBoolean isDone
protected AtomicInteger barrier
protected AtomicInteger secondary
protected AtomicBoolean registered
protected AtomicBoolean bypassMode
protected final AtomicInteger currentConsumers
protected final AtomicThrowable throwable
protected boolean isDebug
protected final boolean relocatable
protected ThreadLocal<AtomicLong> updatesApplied
protected AtomicBoolean externalUpdatesAvailable
protected WorkspaceConfiguration appliedConfiguration
public EncodedGradientsAccumulator(int parties,
double threshold)
public EncodedGradientsAccumulator(int parties,
ThresholdAlgorithm thresholdAlgorithm,
ResidualPostProcessor residualPostProcessor,
boolean encodingDebugMode)
public EncodedGradientsAccumulator(int parties,
@NonNull
@NonNull MessageHandler handler,
long initialMemory,
int queueSize,
Integer boundary,
boolean encodingDebugMode)
public static long getOptimalBufferSize(long paramsLength,
int numWorkers,
int queueSize)
paramsLength - numWorkers - queueSize - public static long getOptimalBufferSize(Model model, int numWorkers, int queueSize)
public void fallbackToSingleConsumerMode(boolean reallyFallback)
RegisterablefallbackToSingleConsumerMode in interface Registerablepublic void registerConsumers(int numConsumers)
RegisterableregisterConsumers in interface Registerablepublic IndexedTail getExternalSource()
getExternalSource in interface GradientsAccumulatorpublic void markExternalUpdates(boolean updatesAvailable)
GradientsAccumulatormarkExternalUpdates in interface GradientsAccumulatorprotected void synchronize(int consumers)
protected void synchronize(int consumers,
boolean finalLock)
public void applyUpdate(StepFunction function, INDArray params, INDArray updates, boolean isFinalStep)
applyUpdate in interface GradientsAccumulatorfunction - params - public void applyUpdate(StepFunction function, INDArray params, INDArray updates, double alpha)
applyUpdate in interface GradientsAccumulatorfunction - params - alpha - public void setExternalSource(IndexedTail source)
setExternalSource in interface GradientsAccumulatorsource - public void touch()
touch in interface GradientsAccumulatorpublic void storeUpdate(INDArray array, int iterationNumber, int epochNumber)
storeUpdate in interface GradientsAccumulatorarray - public void receiveUpdate(INDArray array)
PLEASE NOTE: array is expected to be ready for use and match params dimensionality
receiveUpdate in interface GradientsAccumulatorarray - public void reset()
reset in interface GradientsAccumulatorpublic boolean hasAnything()
GradientsAccumulatorhasAnything in interface GradientsAccumulatorCopyright © 2020. All rights reserved.