Search in sources :

Example 1 with AngelException

use of com.tencent.angel.exception.AngelException in project angel by Tencent.

the class PSAgent method releaseMatrix.

/**
 * Release a matrix
 *
 * @param matrixName matrix name
 * @throws AngelException exception come from master
 */
public void releaseMatrix(String matrixName) throws AngelException {
    try {
        removeLocalMatrix(matrixName);
        masterClient.releaseMatrix(matrixName);
    } catch (Throwable x) {
        throw new AngelException(x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException)

Example 2 with AngelException

use of com.tencent.angel.exception.AngelException in project angel by Tencent.

the class GetValueOfIndexTask method sparseDouble.

public void sparseDouble(TaskContext tContext) {
    long startGen = System.currentTimeMillis();
    int[] index = genIndexs(feaNum, nnz);
    long cost = System.currentTimeMillis() - startGen;
    LOG.info("Gen index cost: " + cost + " ms.");
    try {
        MatrixClient sMatClient = tContext.getMatrix(SPARSE_DOUBLE_MAT);
        // Set PS Model values
        long startInc = System.currentTimeMillis();
        SparseDoubleVector delt = new SparseDoubleVector(feaNum);
        for (int i = 0; i < feaNum; i++) delt.set(i, (double) i);
        sMatClient.increment(0, delt);
        sMatClient.clock().get();
        long costInc = System.currentTimeMillis() - startInc;
        LOG.info("Increment delt cost " + costInc + " ms.");
        // Wait for all tasks finish this clock
        sMatClient.getTaskContext().globalSync(sMatClient.getMatrixId());
        // Get values of index array
        long startGet = System.currentTimeMillis();
        IndexGetFunc func = new IndexGetFunc(new IndexGetParam(tContext.getMatrix(DENSE_DOUBLE_MAT).getMatrixId(), 0, index));
        SparseDoubleVector row = (SparseDoubleVector) ((GetRowResult) sMatClient.get(func)).getRow();
        long costGet = System.currentTimeMillis() - startGet;
        LOG.info("Get row of indexs cost " + costGet + " ms.");
    } catch (Throwable e) {
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IndexGetFunc(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc) IndexGetParam(com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector)

Example 3 with AngelException

use of com.tencent.angel.exception.AngelException in project angel by Tencent.

the class LongKeyTestTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("longkey_test");
        while (taskContext.getEpoch() < 100) {
            long startTs = System.currentTimeMillis();
            TVector row = client.getRow(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum=" + ((CompSparseLongKeyDoubleVector) row).sum());
            startTs = System.currentTimeMillis();
            CompSparseLongKeyDoubleVector deltaV = new CompSparseLongKeyDoubleVector(client.getMatrixId(), 0, 2100000000, 110000000);
            SparseLongKeyDoubleVector deltaV1 = new SparseLongKeyDoubleVector(2100000000, 150000000);
            DenseDoubleVector deltaV2 = new DenseDoubleVector(110000000);
            for (int i = 0; i < 2100000000; i += 20) {
                deltaV.set(i, 1.0);
                deltaV1.set(i, 1.0);
            }
            for (int i = 0; i < 110000000; i++) {
                deltaV2.set(i, 1.0);
            }
            startTs = System.currentTimeMillis();
            int tryNum = 100;
            while (tryNum-- > 0) {
                deltaV.timesBy(2.0);
            }
            LOG.info("combine times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV1.timesBy(2.0);
            }
            LOG.info("single times use time " + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            tryNum = 100;
            while (tryNum-- > 0) {
                deltaV2.timesBy(2.0);
            }
            LOG.info("dense times use time " + (System.currentTimeMillis() - startTs));
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " train use time=" + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            client.increment(deltaV);
            client.clock().get();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " flush use time=" + (System.currentTimeMillis() - startTs));
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) CompSparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.CompSparseLongKeyDoubleVector) SparseLongKeyDoubleVector(com.tencent.angel.ml.math.vector.SparseLongKeyDoubleVector)

Example 4 with AngelException

use of com.tencent.angel.exception.AngelException in project angel by Tencent.

the class PSFTestTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("psf_test");
        Pull func = new Pull(client.getMatrixId(), 0);
        Pull func1 = new Pull(client.getMatrixId(), 1);
        while (taskContext.getEpoch() < 100) {
            taskContext.globalSync(client.getMatrixId());
            long startTs = System.currentTimeMillis();
            TVector row = ((GetRowResult) client.get(func)).getRow();
            TVector row1 = ((GetRowResult) client.get(func1)).getRow();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum of row 0=" + sum((DenseDoubleVector) row) + " sum of row 1=" + sum((DenseDoubleVector) row1));
            double[] delta = new double[10000000];
            for (int i = 0; i < 10000000; i++) {
                delta[i] = 1.0;
            }
            DenseDoubleVector deltaV = new DenseDoubleVector(10000000, delta);
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            double[] delta1 = new double[10000000];
            for (int i = 0; i < 10000000; i++) {
                delta1[i] = 2.0;
            }
            DenseDoubleVector deltaV1 = new DenseDoubleVector(10000000, delta1);
            deltaV1.setMatrixId(client.getMatrixId());
            deltaV1.setRowId(1);
            client.increment(deltaV);
            client.increment(deltaV1);
            client.clock().get();
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) Pull(com.tencent.angel.ml.matrix.psf.aggr.Pull) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) GetRowResult(com.tencent.angel.ml.matrix.psf.get.single.GetRowResult)

Example 5 with AngelException

use of com.tencent.angel.exception.AngelException in project angel by Tencent.

the class SparseDoubleTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        MatrixClient client = taskContext.getMatrix("sparse_double_test");
        while (taskContext.getEpoch() < 100) {
            long startTs = System.currentTimeMillis();
            TVector row = client.getRow(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " pull use time=" + (System.currentTimeMillis() - startTs) + ", sum=" + sum((SparseDoubleVector) row));
            startTs = System.currentTimeMillis();
            SparseDoubleVector deltaV = new SparseDoubleVector(2100000000, 150000000);
            for (int i = 0; i < 2100000000; i += 20) {
                deltaV.set(i, 1.0);
            }
            deltaV.setMatrixId(client.getMatrixId());
            deltaV.setRowId(0);
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " train use time=" + (System.currentTimeMillis() - startTs));
            startTs = System.currentTimeMillis();
            client.increment(deltaV);
            client.clock().get();
            LOG.info("Task " + taskContext.getTaskId() + " in iteration " + taskContext.getEpoch() + " flush use time=" + (System.currentTimeMillis() - startTs));
            taskContext.incEpoch();
        }
    } catch (Throwable x) {
        throw new AngelException("run task failed ", x);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) TVector(com.tencent.angel.ml.math.TVector) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector)

Aggregations

AngelException (com.tencent.angel.exception.AngelException)27 ServiceException (com.google.protobuf.ServiceException)8 IOException (java.io.IOException)6 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)5 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)3 TVector (com.tencent.angel.ml.math.TVector)3 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)3 SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)3 ArrayList (java.util.ArrayList)3 MatrixContext (com.tencent.angel.ml.matrix.MatrixContext)2 IndexGetFunc (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetFunc)2 IndexGetParam (com.tencent.angel.ml.matrix.psf.get.enhance.indexed.IndexGetParam)2 ModelLineConvert (com.tencent.angel.tools.ModelLineConvert)2 TextModelLineConvert (com.tencent.angel.tools.TextModelLineConvert)2 Random (java.util.Random)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Output (com.esotericsoftware.kryo.io.Output)1