Search in sources :

Example 6 with AngelException

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

the class Sampler method inference.

public void inference(PartitionKey pkey, PartCSRResult csr) {
    int ws = pkey.getStartRow();
    int we = pkey.getEndRow();
    Random rand = new Random(System.currentTimeMillis());
    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();
        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));
                throw new AngelException("some error happens");
            }
            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);
            }
            data.topics[wi] = tt;
        }
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) Random(java.util.Random)

Example 7 with AngelException

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

the class ModelMergeAndConverterTask method run.

@Override
public void run(TaskContext taskContext) throws AngelException {
    try {
        // Get input path, output path
        String modelLoadDir = conf.get(AngelConf.ANGEL_LOAD_MODEL_PATH);
        if (modelLoadDir == null) {
            throw new InvalidParameterException("convert source path " + AngelConf.ANGEL_LOAD_MODEL_PATH + " must be set");
        }
        String convertedModelSaveDir = conf.get(AngelConf.ANGEL_SAVE_MODEL_PATH);
        if (convertedModelSaveDir == null) {
            throw new InvalidParameterException("converted model save path " + AngelConf.ANGEL_LOAD_MODEL_PATH + " must be set");
        }
        // Init serde
        String modelSerdeClass = conf.get("angel.modelconverts.serde.class", TextModelLineConvert.class.getName());
        Class<? extends ModelLineConvert> funcClass = (Class<? extends ModelLineConvert>) Class.forName(modelSerdeClass);
        Constructor<? extends ModelLineConvert> constructor = funcClass.getConstructor();
        constructor.setAccessible(true);
        ModelLineConvert serde = constructor.newInstance();
        // Parse need convert model names, if not set, we will convert all models in input directory
        String needConvertModelNames = conf.get("angel.modelconverts.model.names");
        String[] modelNames = null;
        if (needConvertModelNames == null) {
            LOG.info("we will convert all models save in " + modelLoadDir);
            Path modelLoadPath = new Path(modelLoadDir);
            FileSystem fs = modelLoadPath.getFileSystem(conf);
            FileStatus[] fileStatus = fs.listStatus(modelLoadPath);
            if (fileStatus == null || fileStatus.length == 0) {
                throw new IOException("can not find any models in " + modelLoadDir);
            }
            List<String> modelNameList = new ArrayList<>();
            for (int i = 0; i < fileStatus.length; i++) {
                if (fileStatus[i].isDirectory()) {
                    modelNameList.add(fileStatus[i].getPath().getName());
                }
            }
            if (modelNameList.isEmpty()) {
                throw new IOException("can not find any models in " + modelLoadDir);
            }
            modelNames = modelNameList.toArray(new String[0]);
        } else {
            modelNames = needConvertModelNames.split(",");
            if (modelNames.length == 0) {
                throw new IOException("can not find any models in " + modelLoadDir);
            }
        }
        for (int i = 0; i < modelNames.length; i++) {
            LOG.info("===================start to convert model " + modelNames[i]);
            ModelMergeAndConvert.convert(conf, modelLoadDir + Path.SEPARATOR + modelNames[i], convertedModelSaveDir + Path.SEPARATOR + modelNames[i], serde);
            LOG.info("===================end to convert model " + modelNames[i]);
        }
    } catch (Throwable x) {
        LOG.fatal("convert model falied, ", x);
        throw new AngelException(x);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AngelException(com.tencent.angel.exception.AngelException) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) TextModelLineConvert(com.tencent.angel.tools.TextModelLineConvert) TextModelLineConvert(com.tencent.angel.tools.TextModelLineConvert) ModelLineConvert(com.tencent.angel.tools.ModelLineConvert) IOException(java.io.IOException) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 8 with AngelException

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

the class DataBlock method loopingRead.

/**
 * Read LabeledData from DataBlock Looping. If it reach the end, start from the beginning again.
 *
 * @return
 */
public VALUE loopingRead() throws IOException {
    VALUE data = this.read();
    if (data == null) {
        resetReadIndex();
        data = read();
    }
    if (data != null)
        return data;
    else
        throw new AngelException("Train data storage is empty or corrupted.");
}
Also used : AngelException(com.tencent.angel.exception.AngelException)

Example 9 with AngelException

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

the class LabeledUpdateIndexBaseTask method preProcess.

@Override
public void preProcess(TaskContext taskContext) {
    try {
        Reader<KEYIN, VALUEIN> reader = taskContext.getReader();
        while (reader.nextKeyValue()) {
            LabeledData out = parse(reader.getCurrentKey(), reader.getCurrentValue());
            if (out != null) {
                taskDataBlock.put(out);
                if (updateIndexEnable) {
                    TAbstractVector vector = out.getX();
                    if (vector instanceof SparseDummyVector) {
                        int[] indexes = ((SparseDummyVector) vector).getIndices();
                        for (int i = 0; i < indexes.length; i++) {
                            indexSet.add(indexes[i]);
                        }
                    }
                }
            }
        }
        taskDataBlock.flush();
    } catch (Exception e) {
        throw new AngelException("Pre-Process Error.", e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) LabeledData(com.tencent.angel.ml.feature.LabeledData) TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) SparseDummyVector(com.tencent.angel.ml.math.vector.SparseDummyVector) AngelException(com.tencent.angel.exception.AngelException) IOException(java.io.IOException)

Example 10 with AngelException

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

the class AngelClient method run.

@Override
public void run() throws AngelException {
    if (master == null) {
        throw new AngelException("parameter servers are not started, you must execute startPSServer first!!");
    }
    try {
        createMatrices();
        master.start(null, StartRequest.newBuilder().build());
    } catch (ServiceException | InvalidParameterException e) {
        LOG.error("start application failed.", e);
        throw new AngelException(e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) ServiceException(com.google.protobuf.ServiceException)

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