Search in sources :

Example 11 with AngelException

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

the class AngelClient method saveModel.

@SuppressWarnings("rawtypes")
@Override
public void saveModel(MLModel model) throws AngelException {
    if (master == null) {
        throw new AngelException("parameter servers are not started, you must execute startPSServer first!!");
    }
    SaveRequest.Builder builder = SaveRequest.newBuilder();
    Map<String, PSModel> psModels = model.getPSModels();
    for (Map.Entry<String, PSModel> entry : psModels.entrySet()) {
        MatrixContext context = entry.getValue().getContext();
        String savePath = context.getAttributes().get(MatrixConf.MATRIX_SAVE_PATH);
        if (savePath != null) {
            builder.addMatrixNames(context.getName());
        }
    }
    try {
        master.save(null, builder.build());
    } catch (ServiceException e) {
        LOG.error("save model failed.", e);
        throw new AngelException(e);
    }
    while (!isCompleted()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new AngelException("Interrupted as waiting app complete");
        }
    }
    if (appFailedMessage != null) {
        throw new AngelException("app run failed, " + appFailedMessage);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) MatrixContext(com.tencent.angel.ml.matrix.MatrixContext) PSModel(com.tencent.angel.ml.model.PSModel) ServiceException(com.google.protobuf.ServiceException)

Example 12 with AngelException

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

the class AngelYarnClient method stop.

@Override
public void stop() throws AngelException {
    super.stop();
    if (yarnClient != null) {
        try {
            yarnClient.killApplication(appId);
        } catch (YarnException | IOException e) {
            throw new AngelException(e);
        }
        yarnClient.stop();
    }
    close();
}
Also used : AngelException(com.tencent.angel.exception.AngelException) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 13 with AngelException

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

the class AngelYarnClient method stop.

@Override
public void stop(int stateCode) throws AngelException {
    LOG.info("stop the application");
    super.stop();
    if (master != null) {
        try {
            LOG.info("master is not null, send stop command to Master, stateCode=" + stateCode);
            master.stop(null, ClientMasterServiceProtos.StopRequest.newBuilder().setExitStatus(stateCode).build());
        } catch (ServiceException e) {
            LOG.error("send stop command to Master failed ", e);
            stop();
            throw new AngelException(e);
        }
        close();
    } else {
        LOG.info("master is null, just kill the application");
        stop();
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) ServiceException(com.google.protobuf.ServiceException)

Example 14 with AngelException

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

the class GetValueOfIndexTask method denseDouble.

public void denseDouble(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 dMatClient = tContext.getMatrix(DENSE_DOUBLE_MAT);
        // Set PS Model values
        long startInc = System.currentTimeMillis();
        DenseDoubleVector delt = new DenseDoubleVector(feaNum);
        for (int i = 0; i < feaNum; i++) delt.set(i, (double) i);
        dMatClient.increment(0, delt);
        dMatClient.clock().get();
        long costInc = System.currentTimeMillis() - startInc;
        LOG.info("Increment delt cost " + costInc + " ms.");
        // Wait for all tasks finish this clock
        dMatClient.getTaskContext().globalSync(dMatClient.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) dMatClient.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) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) 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 15 with AngelException

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

the class Sampler method sample.

public Future<VoidResult> sample(PartitionKey pkey, PartCSRResult csr) {
    int ws = pkey.getStartRow();
    int we = pkey.getEndRow();
    Random rand = new Random(System.currentTimeMillis());
    Short2IntOpenHashMap[] updates = new Short2IntOpenHashMap[we - ws];
    for (int w = ws; w < we; w++) {
        if (data.ws[w + 1] - data.ws[w] == 0)
            continue;
        if (!csr.read(wk))
            throw new AngelException("some error happens");
        buildFTree();
        updates[w - ws] = new Short2IntOpenHashMap();
        for (int wi = data.ws[w]; wi < data.ws[w + 1]; wi++) {
            int d = data.docs[wi];
            TraverseHashMap dk = data.dks[d];
            int tt = data.topics[wi];
            if (wk[tt] <= 0) {
                LOG.error(String.format("Error wk[%d] = %d for word %d", tt, wk[tt], w));
                continue;
            }
            wk[tt]--;
            nk[tt]--;
            float value = (wk[tt] + beta) / (nk[tt] + vbeta);
            tree.update(tt, value);
            updates[w - ws].addTo((short) tt, -1);
            synchronized (dk) {
                dk.dec(tt);
                float sum = build(dk);
                float u = rand.nextFloat() * (sum + alpha * tree.first());
                if (u < sum) {
                    u = rand.nextFloat() * sum;
                    int idx = BinarySearch.binarySearch(psum, u, 0, dk.size - 1);
                    tt = tidx[idx];
                } else
                    tt = tree.sample(rand.nextFloat() * tree.first());
                dk.inc(tt);
            }
            wk[tt]++;
            nk[tt]++;
            value = (wk[tt] + beta) / (nk[tt] + vbeta);
            tree.update(tt, value);
            data.topics[wi] = tt;
            updates[w - ws].addTo((short) tt, 1);
        }
    // model.wtMat().increment(w, update);
    }
    CSRPartUpdateParam param = new CSRPartUpdateParam(model.wtMat().getMatrixId(), pkey, updates);
    Future<VoidResult> future = PSAgentContext.get().getMatrixTransportClient().update(new UpdatePartFunc(null), param);
    return future;
}
Also used : AngelException(com.tencent.angel.exception.AngelException) UpdatePartFunc(com.tencent.angel.ml.lda.psf.UpdatePartFunc) CSRPartUpdateParam(com.tencent.angel.ml.lda.psf.CSRPartUpdateParam) Random(java.util.Random) VoidResult(com.tencent.angel.ml.matrix.psf.update.enhance.VoidResult) Short2IntOpenHashMap(it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap)

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