public class EncodedGradientsAccumulator extends Object implements GradientsAccumulator, Registerable
Modifier and Type | Class and Description |
---|---|
static class |
EncodedGradientsAccumulator.Builder |
Modifier | Constructor and Description |
---|---|
|
EncodedGradientsAccumulator(int parties,
double threshold) |
protected |
EncodedGradientsAccumulator(int parties,
MessageHandler handler,
long initialMemory,
int queueSize,
Double 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<org.nd4j.linalg.api.memory.MemoryWorkspace> workspaces
protected List<ReentrantLock> locks
protected AtomicInteger workersCounter
protected ThreadLocal<Integer> index
protected long initialMemory
protected int queueSize
protected Double 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 org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration appliedConfiguration
public EncodedGradientsAccumulator(int parties, double threshold)
public EncodedGradientsAccumulator(int parties, ThresholdAlgorithm thresholdAlgorithm, ResidualPostProcessor residualPostProcessor, boolean encodingDebugMode)
protected EncodedGradientsAccumulator(int parties, @NonNull MessageHandler handler, long initialMemory, int queueSize, Double 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)
Registerable
fallbackToSingleConsumerMode
in interface Registerable
public void registerConsumers(int numConsumers)
Registerable
registerConsumers
in interface Registerable
public IndexedTail getExternalSource()
getExternalSource
in interface GradientsAccumulator
public void markExternalUpdates(boolean updatesAvailable)
GradientsAccumulator
markExternalUpdates
in interface GradientsAccumulator
protected 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 GradientsAccumulator
function
- params
- public void applyUpdate(StepFunction function, INDArray params, INDArray updates, double alpha)
applyUpdate
in interface GradientsAccumulator
function
- params
- alpha
- public void setExternalSource(IndexedTail source)
setExternalSource
in interface GradientsAccumulator
source
- public void touch()
touch
in interface GradientsAccumulator
public void storeUpdate(INDArray array, int iterationNumber, int epochNumber)
storeUpdate
in interface GradientsAccumulator
array
- public void receiveUpdate(INDArray array)
PLEASE NOTE: array is expected to be ready for use and match params dimensionality
receiveUpdate
in interface GradientsAccumulator
array
- public void reset()
reset
in interface GradientsAccumulator
public boolean hasAnything()
GradientsAccumulator
hasAnything
in interface GradientsAccumulator
Copyright © 2019. All rights reserved.