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;
}
}
}
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);
}
}
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.");
}
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);
}
}
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);
}
}
Aggregations