docs/design/psf_update_en.md
PS Client divides the requests to generate a request list, where each request in the list corresponds to a model parameter partition.
PS Client sends every request in the list to the PS instance that has the corresponding partition. The PS instance gets and updates the parameters in units of model parameter partitions, and returns the result.
UpdateFunc waits for all requests to finish and return.
Interface
Future<VoidResult> update(UpdaterFunc update) throws AngelException;
Parameters
The parameter type is an UpdaterFunc object, which encapsulates the parameters and process of the update psf method:
public abstract class UpdaterFunc {
private final UpdaterParam param;
public UpdaterFunc(UpdaterParam param) {
this.param = param;
}
public UpdaterParam getParam() {return param;}
public abstract void partitionUpdate(PartitionUpdaterParam partParam);
}
The parameter type of an UpdateFunc object is UpdateParam
split method, which divides the overall update parameters to a list of update parameters for their corresponding model partitions (list of PartitionUpdateParam objects).Different from get psf, update psf's process consists of only one step:
update in units of model partitions (partitionUpdate)update psf has no specific return value, but returns Future to the application; the application then decides whether to wait for the operations to complete.
The execution process of update type psFunc requires the PS Client and PS to work together:
The specific process is shown below, with the chart on the left showing the process on the worker, and the chart on the right showing the process on the PS server:
com.tencent.angel.ml.matrix.psf.update.RandomUniform: an example that assigns a specified range of random numbers to a row:
public class RandomUniform extends MMUpdateFunc {
...
@Override
protected void doUpdate(ServerDenseDoubleRow[] rows, double[] scalars) {
Random rand = new Random(System.currentTimeMillis());
try {
rows[0].getLock().writeLock().lock();
double min = scalars[0];
double max = scalars[1];
double factor = max - min;
DoubleBuffer data = rows[0].getData();
int size = rows[0].size();
for (int i = 0; i < size; i++) {
data.put(i, factor * rand.nextDouble() + min);
}
} finally {
rows[0].getLock().writeLock().unlock();
}
}
}
Compile the code and create the jar to be uploaded through angel.lib.jars when submitting the application; the new UpdateFunc can then be called, for instance:
Random randomFunc = new RandomUniform(new RandomParam(matrixId, rowIndex, 0.0, 1.0));
psModel.update(randomFunc).get();
Abs
from row id, to row idAdd
from row id, second from row id, to row idAddS
from row id, to row id, scalar valueAxpy
Ceil
from row id, to row idCopy
from row id, to row idDiv
from row id, second from row id, to row idDivS
from row id, to row id, scalarExp
from row id, to row idExpm1
from row id, to row idFill
Floor
from row id, to row idIncrement
from row id, array (must have same size as the row)Log
from row id, to row idLog10
from row id, to row idLog1p
from row id, to row idMap
from row id, to row id, function f(x)MapWithIndex
from row id, to row id, function f(i,x)
MaxA
MaxV
from row id, second from row id, to row idMinA
MinV
from row id, second from row id, to row idMul
from row id, second from row id, to row idMulS
from row id, to row id, scalarPow
from row id, to row id, scalarPut
RandomNormal
RandomUniform
Round
from row id, to row idScale
Signum
from row id, to row idSqrt
from row id, to row idSub
from row id, second from row id, to row idZip2Map
from row id, second from row id, to row id, function f(x,y) where x and y are the corresponding pair of elements from the two rowsZip2MapWithIndex
from row id, second from row id, to row id, function(i,x,y) where i is the index of x and yZip3Map
from row id, second from row id, third from row id, to row id, function f(x,y,z)Zip3MapWithIndex
from row id, second from row id, third from row id, to row id, function f(i,x,y,z) where i is the index of x, y and z