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