use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.
the class UpdatePSFTest method testDenseFloatUDF.
public void testDenseFloatUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_FLOAT_MAT, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) {
deltaVec.set(i, i);
}
deltaVec.setRowId(0);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
IntFloatVector row = (IntFloatVector) client1.getRow(0);
for (int id : index) {
Assert.assertTrue(row.get(id) == deltaVec.get(id));
}
Assert.assertTrue(feaNum == row.size());
}
use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.
the class UpdatePSFTest method testDenseDoubleUDF.
public void testDenseDoubleUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_DOUBLE_MAT, 0);
int matrixW1Id = client1.getMatrixId();
int[] index = genIndexs(feaNum, nnz);
IntDoubleVector deltaVec = new IntDoubleVector(feaNum, new IntDoubleDenseVectorStorage(feaNum));
for (int i = 0; i < feaNum; i++) {
deltaVec.set(i, i);
}
deltaVec.setRowId(0);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
IntDoubleVector row = (IntDoubleVector) client1.getRow(0);
for (int id : index) {
Assert.assertEquals(row.get(id), deltaVec.get(id), 0);
}
Assert.assertEquals(feaNum, row.size());
}
use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.
the class PytorchPSFTask method run.
@Override
public void run(TaskContext taskContext) throws AngelException {
int feaNum = taskContext.getConf().getInt("col", 100000000);
int batchNNZ = taskContext.getConf().getInt("batch.nnz", 10000);
int updateTime = 0;
long startTs = System.currentTimeMillis();
try {
while (true) {
int[] indices = genIndexs(feaNum, batchNNZ);
IntFloatVector deltaVec = VFactory.sparseFloatVector(feaNum, batchNNZ);
for (int i = 0; i < indices.length; i++) {
deltaVec.set(indices[i], 1);
}
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
MatrixClient client = taskContext.getMatrix("psf_test");
client.asyncUpdate(new IncrementRows(new IncrementRowsParam(client.getMatrixId(), updates))).get();
updateTime++;
if (updateTime % 100 == 0) {
LOG.info("update num = " + updateTime + ", avg update time=" + (System.currentTimeMillis() - startTs) / updateTime);
}
}
} catch (Throwable ie) {
}
}
use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.
the class UpdatePSFTest method testSparseLongLongKeyUDF.
public void testSparseLongLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_LONG_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongLongVector deltaVec = new LongLongVector(feaNum, new LongLongSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < nnz; i++) {
deltaVec.set(index[i], index[i]);
}
deltaVec.setRowId(0);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
LongLongVector row = (LongLongVector) client1.getRow(0);
for (long id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
Assert.assertEquals(row.get(id), deltaVec.get(id));
}
// Assert.assertTrue(index.length == row.size());
}
use of com.tencent.angel.ml.matrix.psf.update.update.IncrementRows in project angel by Tencent.
the class UpdatePSFTest method testSparseDoubleLongKeyUDF.
public void testSparseDoubleLongKeyUDF() throws Exception {
Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_DOUBLE_LONG_MAT, 0);
int matrixW1Id = client1.getMatrixId();
long[] index = genLongIndexs(feaNum, nnz);
LongDoubleVector deltaVec = new LongDoubleVector(feaNum, new LongDoubleSparseVectorStorage(feaNum, nnz));
for (int i = 0; i < feaNum; i++) {
deltaVec.set(i, i);
}
deltaVec.setRowId(0);
Vector[] updates = new Vector[1];
updates[0] = deltaVec;
client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
// client1.clock().get();
LongDoubleVector row = (LongDoubleVector) client1.getRow(0);
for (long id : index) {
// System.out.println("id=" + id + ", value=" + row.get(id));
Assert.assertTrue(row.get(id) == deltaVec.get(id));
}
// Assert.assertTrue(index.length == row.size());
}
Aggregations