Search in sources :

Example 1 with AMMatrixMetaManager

use of com.tencent.angel.master.matrixmeta.AMMatrixMetaManager in project angel by Tencent.

the class MasterService method releaseMatrices.

/**
 * Release matrices
 * @param controller
 * @param request
 * @return
 * @throws ServiceException
 */
@Override
public ReleaseMatricesResponse releaseMatrices(RpcController controller, ReleaseMatricesRequest request) throws ServiceException {
    AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager();
    List<String> matrixNames = request.getMatrixNamesList();
    int size = matrixNames.size();
    for (int i = 0; i < size; i++) {
        matrixMetaManager.releaseMatrix(matrixNames.get(i));
    }
    return ReleaseMatricesResponse.newBuilder().build();
}
Also used : AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)

Example 2 with AMMatrixMetaManager

use of com.tencent.angel.master.matrixmeta.AMMatrixMetaManager in project angel by Tencent.

the class AppStateStorage method loadMatrixMeta.

/**
 * load matrix meta from file
 * @return MatrixMetaManager matrix meta storage
 * @throws IOException, ClassNotFoundException, InvalidParameterException
 */
public AMMatrixMetaManager loadMatrixMeta() throws IOException, ClassNotFoundException, InvalidParameterException {
    try {
        matrixMetaLock.lock();
        Path matrixFilePath = null;
        try {
            matrixFilePath = findFilePathUsePrefix(matrixMetaFileNamePrefix);
        } catch (Exception x) {
            LOG.error("find matrix meta file failed.", x);
            return null;
        }
        if (matrixFilePath == null) {
            return null;
        }
        FSDataInputStream inputStream = fs.open(new Path(writeDir, matrixFilePath));
        AMMatrixMetaManager matrixMetaManager = new AMMatrixMetaManager(context);
        matrixMetaManager.deserialize(inputStream);
        return matrixMetaManager;
    } finally {
        matrixMetaLock.unlock();
    }
}
Also used : AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException)

Example 3 with AMMatrixMetaManager

use of com.tencent.angel.master.matrixmeta.AMMatrixMetaManager in project angel by Tencent.

the class MatrixMetaManagerTest method testCreateMatrix.

@Test
public void testCreateMatrix() throws Exception {
    try {
        LOG.info("===========================testCreateMatrix===============================");
        Worker worker = LocalClusterContext.get().getWorker(worker0Attempt0Id).getWorker();
        MasterClient masterClient = worker.getPSAgent().getMasterClient();
        int w3Id = -1;
        int w4Id = -1;
        // add matrix
        MatrixContext mMatrix = new MatrixContext();
        mMatrix.setName("w3");
        mMatrix.setRowNum(1);
        mMatrix.setColNum(100000);
        mMatrix.setMaxRowNumInBlock(1);
        mMatrix.setMaxColNumInBlock(50000);
        mMatrix.setRowType(RowType.T_DOUBLE_DENSE);
        mMatrix.set(MatrixConf.MATRIX_OPLOG_ENABLEFILTER, "false");
        mMatrix.set(MatrixConf.MATRIX_HOGWILD, "true");
        mMatrix.set(MatrixConf.MATRIX_AVERAGE, "false");
        mMatrix.set(MatrixConf.MATRIX_OPLOG_TYPE, "DENSE_DOUBLE");
        masterClient.createMatrix(mMatrix, 10000);
        mMatrix.setName("w4");
        mMatrix.setRowNum(1);
        mMatrix.setColNum(100000);
        mMatrix.setMaxRowNumInBlock(1);
        mMatrix.setMaxColNumInBlock(50000);
        mMatrix.setRowType(RowType.T_DOUBLE_DENSE);
        mMatrix.set(MatrixConf.MATRIX_OPLOG_ENABLEFILTER, "false");
        mMatrix.set(MatrixConf.MATRIX_HOGWILD, "true");
        mMatrix.set(MatrixConf.MATRIX_AVERAGE, "false");
        mMatrix.set(MatrixConf.MATRIX_OPLOG_TYPE, "DENSE_DOUBLE");
        masterClient.createMatrix(mMatrix, 10000);
        MatrixMeta w3Meta = worker.getPSAgent().getMatrixMetaManager().getMatrixMeta("w3");
        MatrixMeta w4Meta = worker.getPSAgent().getMatrixMetaManager().getMatrixMeta("w4");
        assertEquals(w3Meta.getRowNum(), 1);
        assertEquals(w3Meta.getColNum(), 100000);
        assertEquals(w3Meta.getRowType(), RowType.T_DOUBLE_DENSE);
        assertEquals(w4Meta.getRowNum(), 1);
        assertEquals(w4Meta.getColNum(), 100000);
        assertEquals(w4Meta.getRowType(), RowType.T_DOUBLE_DENSE);
        w3Id = w3Meta.getId();
        w4Id = w4Meta.getId();
        AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
        assertTrue(angelAppMaster != null);
        AMMatrixMetaManager matrixMetaManager = angelAppMaster.getAppContext().getMatrixMetaManager();
        MatrixMeta matrixw3Proto = matrixMetaManager.getMatrix("w3");
        MatrixMeta matrixw4Proto = matrixMetaManager.getMatrix("w4");
        assertNotNull(matrixw3Proto);
        assertNotNull(matrixw4Proto);
        assertEquals(matrixw3Proto.getRowNum(), 1);
        assertEquals(matrixw3Proto.getColNum(), 100000);
        assertEquals(matrixw3Proto.getPartitionMetas().size(), 2);
        Map<Integer, PartitionMeta> w3Parts = matrixw3Proto.getPartitionMetas();
        assertEquals(w3Parts.get(0).getPss().get(0), psId);
        assertEquals(w3Parts.get(0).getPartId(), 0);
        assertEquals(w3Parts.get(0).getStartRow(), 0);
        assertEquals(w3Parts.get(0).getEndRow(), 1);
        assertEquals(w3Parts.get(0).getStartCol(), 0);
        assertEquals(w3Parts.get(0).getEndCol(), 50000);
        assertEquals(w3Parts.get(1).getPartId(), 1);
        assertEquals(w3Parts.get(1).getStartRow(), 0);
        assertEquals(w3Parts.get(1).getEndRow(), 1);
        assertEquals(w3Parts.get(1).getStartCol(), 50000);
        assertEquals(w3Parts.get(1).getEndCol(), 100000);
        Map<Integer, PartitionMeta> w4Parts = matrixw4Proto.getPartitionMetas();
        assertEquals(w4Parts.get(0).getPss().get(0), psId);
        assertEquals(w4Parts.get(0).getPartId(), 0);
        assertEquals(w4Parts.get(0).getStartRow(), 0);
        assertEquals(w4Parts.get(0).getEndRow(), 1);
        assertEquals(w4Parts.get(0).getStartCol(), 0);
        assertEquals(w4Parts.get(0).getEndCol(), 50000);
        assertEquals(w4Parts.get(1).getPartId(), 1);
        assertEquals(w4Parts.get(1).getStartRow(), 0);
        assertEquals(w4Parts.get(1).getEndRow(), 1);
        assertEquals(w4Parts.get(1).getStartCol(), 50000);
        assertEquals(w4Parts.get(1).getEndCol(), 100000);
        ParameterServer ps = LocalClusterContext.get().getPS(psAttempt0Id).getPS();
        PSMatrixMetaManager matrixPartManager = ps.getMatrixMetaManager();
        PartitionMeta w3Part0 = matrixPartManager.getPartMeta(w3Id, 0);
        PartitionMeta w3Part1 = matrixPartManager.getPartMeta(w3Id, 1);
        assertTrue(w3Part0 != null);
        assertTrue(w3Part1 != null);
        assertEquals(w3Part0.getPartitionKey().getStartRow(), 0);
        assertEquals(w3Part0.getPartitionKey().getEndRow(), 1);
        assertEquals(w3Part0.getPartitionKey().getStartCol(), 0);
        assertEquals(w3Part0.getPartitionKey().getEndCol(), 50000);
        assertEquals(w3Part1.getPartitionKey().getStartRow(), 0);
        assertEquals(w3Part1.getPartitionKey().getEndRow(), 1);
        assertEquals(w3Part1.getPartitionKey().getStartCol(), 50000);
        assertEquals(w3Part1.getPartitionKey().getEndCol(), 100000);
        PartitionMeta w4Part0 = matrixPartManager.getPartMeta(w4Id, 0);
        PartitionMeta w4Part1 = matrixPartManager.getPartMeta(w4Id, 1);
        assertTrue(w4Part0 != null);
        assertTrue(w4Part1 != null);
        assertEquals(w4Part0.getPartitionKey().getStartRow(), 0);
        assertEquals(w4Part0.getPartitionKey().getEndRow(), 1);
        assertEquals(w4Part0.getPartitionKey().getStartCol(), 0);
        assertEquals(w4Part0.getPartitionKey().getEndCol(), 50000);
        assertEquals(w4Part1.getPartitionKey().getStartRow(), 0);
        assertEquals(w4Part1.getPartitionKey().getEndRow(), 1);
        assertEquals(w4Part1.getPartitionKey().getStartCol(), 50000);
        assertEquals(w4Part1.getPartitionKey().getEndCol(), 100000);
        MatrixClient w4ClientForTask0 = worker.getPSAgent().getMatrixClient("w4", 0);
        MatrixClient w4ClientForTask1 = worker.getPSAgent().getMatrixClient("w4", 1);
        TaskContext task0Context = w4ClientForTask0.getTaskContext();
        TaskContext task1Context = w4ClientForTask1.getTaskContext();
        double[] delta = new double[100000];
        for (int i = 0; i < delta.length; i++) {
            delta[i] = 1.0;
        }
        int iterIndex = 0;
        while (iterIndex < 5) {
            DenseDoubleVector row1 = (DenseDoubleVector) w4ClientForTask0.getRow(0);
            double sum1 = sum(row1.getValues());
            LOG.info("taskid=" + task0Context.getIndex() + ", matrixId=" + w4ClientForTask0.getMatrixId() + ", rowIndex=0, local row sum=" + sum1);
            DenseDoubleVector deltaRow1 = new DenseDoubleVector(delta.length, delta);
            deltaRow1.setMatrixId(w4ClientForTask0.getMatrixId());
            deltaRow1.setRowId(0);
            w4ClientForTask0.increment(deltaRow1);
            w4ClientForTask0.clock().get();
            task0Context.increaseEpoch();
            DenseDoubleVector row2 = (DenseDoubleVector) w4ClientForTask1.getRow(0);
            double sum2 = sum(row2.getValues());
            LOG.info("taskid=" + task1Context.getIndex() + ", matrixId=" + w4ClientForTask1.getMatrixId() + ", rowIndex=1, local row sum=" + sum2);
            DenseDoubleVector deltaRow2 = new DenseDoubleVector(delta.length, delta);
            deltaRow2.setMatrixId(w4ClientForTask1.getMatrixId());
            deltaRow2.setRowId(0);
            w4ClientForTask1.increment(deltaRow2);
            w4ClientForTask1.clock().get();
            task1Context.increaseEpoch();
            iterIndex++;
        }
        AMTaskManager amTaskManager = angelAppMaster.getAppContext().getTaskManager();
        AMTask amTask0 = amTaskManager.getTask(task0Id);
        AMTask amTask1 = amTaskManager.getTask(task1Id);
        assertEquals(amTask0.getIteration(), 5);
        assertEquals(amTask1.getIteration(), 5);
        Int2IntOpenHashMap task0MatrixClocks = amTask0.getMatrixClocks();
        assertEquals(task0MatrixClocks.size(), 1);
        assertEquals(task0MatrixClocks.get(w4Id), 5);
        Int2IntOpenHashMap task1MatrixClocks = amTask1.getMatrixClocks();
        assertEquals(task1MatrixClocks.size(), 1);
        assertEquals(task1MatrixClocks.get(w4Id), 5);
        DenseDoubleVector row1 = (DenseDoubleVector) w4ClientForTask0.getRow(0);
        double sum1 = sum(row1.getValues());
        assertEquals(sum1, 1000000.0, 0.000001);
        DenseDoubleVector row2 = (DenseDoubleVector) w4ClientForTask1.getRow(0);
        double sum2 = sum(row2.getValues());
        assertEquals(sum2, 1000000.0, 0.000001);
        masterClient.releaseMatrix(w3Meta.getName());
        Thread.sleep(10000);
        matrixw3Proto = matrixMetaManager.getMatrix("w3");
        assertTrue(matrixw3Proto == null);
        MatrixStorageManager matrixStorageManager = LocalClusterContext.get().getPS(psAttempt0Id).getPS().getMatrixStorageManager();
        ServerMatrix sw3 = matrixStorageManager.getMatrix(w3Id);
        assertTrue(sw3 == null);
        w4ClientForTask0.clock().get();
        w4ClientForTask1.clock().get();
        row1 = (DenseDoubleVector) w4ClientForTask0.getRow(0);
        sum1 = sum(row1.getValues());
        assertEquals(sum1, 1000000.0, 0.000001);
        row2 = (DenseDoubleVector) w4ClientForTask1.getRow(0);
        sum2 = sum(row2.getValues());
        assertEquals(sum2, 1000000.0, 0.000001);
    } catch (Exception x) {
        LOG.error("run testCreateMatrix failed ", x);
        throw x;
    }
}
Also used : TaskContext(com.tencent.angel.psagent.task.TaskContext) DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) MasterClient(com.tencent.angel.psagent.client.MasterClient) ServerMatrix(com.tencent.angel.ps.impl.matrix.ServerMatrix) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) AngelException(com.tencent.angel.exception.AngelException) ParameterServer(com.tencent.angel.ps.impl.ParameterServer) PSMatrixMetaManager(com.tencent.angel.ps.impl.PSMatrixMetaManager) AMTaskManager(com.tencent.angel.master.task.AMTaskManager) AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager) MatrixStorageManager(com.tencent.angel.ps.impl.MatrixStorageManager) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) AMTask(com.tencent.angel.master.task.AMTask) Test(org.junit.Test)

Example 4 with AMMatrixMetaManager

use of com.tencent.angel.master.matrixmeta.AMMatrixMetaManager in project angel by Tencent.

the class MatrixMetaManagerTest method testMatrixMetaManager.

@Test
public void testMatrixMetaManager() throws Exception {
    try {
        LOG.info("===========================testMatrixMetaManager===============================");
        AngelApplicationMaster angelAppMaster = LocalClusterContext.get().getMaster().getAppMaster();
        assertTrue(angelAppMaster != null);
        AMMatrixMetaManager matrixMetaManager = angelAppMaster.getAppContext().getMatrixMetaManager();
        MatrixMeta matrixw1Proto = matrixMetaManager.getMatrix("w1");
        MatrixMeta matrixw2Proto = matrixMetaManager.getMatrix("w2");
        assertTrue(matrixw1Proto != null);
        assertTrue(matrixw2Proto != null);
        assertEquals(matrixw1Proto.getRowNum(), 1);
        assertEquals(matrixw1Proto.getColNum(), 100000);
        assertEquals(matrixw1Proto.getPartitionMetas().size(), 2);
        Map<Integer, PartitionMeta> w1Parts = matrixw1Proto.getPartitionMetas();
        assertEquals(w1Parts.get(0).getPss().get(0), psId);
        assertEquals(w1Parts.get(0).getPartId(), 0);
        assertEquals(w1Parts.get(0).getStartRow(), 0);
        assertEquals(w1Parts.get(0).getEndRow(), 1);
        assertEquals(w1Parts.get(0).getStartCol(), 0);
        assertEquals(w1Parts.get(0).getEndCol(), 50000);
        assertEquals(w1Parts.get(1).getPartId(), 1);
        assertEquals(w1Parts.get(1).getStartRow(), 0);
        assertEquals(w1Parts.get(1).getEndRow(), 1);
        assertEquals(w1Parts.get(1).getStartCol(), 50000);
        assertEquals(w1Parts.get(1).getEndCol(), 100000);
        Map<Integer, PartitionMeta> w2Parts = matrixw2Proto.getPartitionMetas();
        assertEquals(w2Parts.get(0).getPss().get(0), psId);
        assertEquals(w2Parts.get(0).getPartId(), 0);
        assertEquals(w2Parts.get(0).getStartRow(), 0);
        assertEquals(w2Parts.get(0).getEndRow(), 1);
        assertEquals(w2Parts.get(0).getStartCol(), 0);
        assertEquals(w2Parts.get(0).getEndCol(), 50000);
        assertEquals(w2Parts.get(1).getPartId(), 1);
        assertEquals(w2Parts.get(1).getStartRow(), 0);
        assertEquals(w2Parts.get(1).getEndRow(), 1);
        assertEquals(w2Parts.get(1).getStartCol(), 50000);
        assertEquals(w2Parts.get(1).getEndCol(), 100000);
    } catch (Exception x) {
        LOG.error("run testMatrixMetaManager failed ", x);
        throw x;
    }
}
Also used : AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager) AngelException(com.tencent.angel.exception.AngelException) Test(org.junit.Test)

Example 5 with AMMatrixMetaManager

use of com.tencent.angel.master.matrixmeta.AMMatrixMetaManager in project angel by Tencent.

the class MasterService method save.

/**
 * Save model to files.
 *
 * @param controller rpc controller of protobuf
 * @param request save request that contains all matrices need save
 * @throws ServiceException some matrices do not exist or save operation is interrupted
 */
@SuppressWarnings("unchecked")
@Override
public SaveResponse save(RpcController controller, SaveRequest request) throws ServiceException {
    List<String> needSaveMatrices = request.getMatrixNamesList();
    List<Integer> matrixIds = new ArrayList<Integer>(needSaveMatrices.size());
    AMMatrixMetaManager matrixMetaManager = context.getMatrixMetaManager();
    int size = needSaveMatrices.size();
    for (int i = 0; i < size; i++) {
        MatrixMeta matrixMeta = matrixMetaManager.getMatrix(needSaveMatrices.get(i));
        if (matrixMeta == null) {
            throw new ServiceException("matrix " + needSaveMatrices.get(i) + " does not exist");
        }
        LOG.info("Need save matrix " + matrixMeta.getName());
        matrixIds.add(matrixMeta.getId());
    }
    context.getEventHandler().handle(new CommitEvent(matrixIds));
    context.getEventHandler().handle(new AppEvent(AppEventType.COMMIT));
    return SaveResponse.newBuilder().build();
}
Also used : AppEvent(com.tencent.angel.master.app.AppEvent) ServiceException(com.google.protobuf.ServiceException) AMMatrixMetaManager(com.tencent.angel.master.matrixmeta.AMMatrixMetaManager) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) CommitEvent(com.tencent.angel.master.ps.CommitEvent)

Aggregations

AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)6 ServiceException (com.google.protobuf.ServiceException)2 AngelException (com.tencent.angel.exception.AngelException)2 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)2 Test (org.junit.Test)2 InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)1 AppEvent (com.tencent.angel.master.app.AppEvent)1 CommitEvent (com.tencent.angel.master.ps.CommitEvent)1 AMTask (com.tencent.angel.master.task.AMTask)1 AMTaskManager (com.tencent.angel.master.task.AMTaskManager)1 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)1 MatrixStorageManager (com.tencent.angel.ps.impl.MatrixStorageManager)1 PSMatrixMetaManager (com.tencent.angel.ps.impl.PSMatrixMetaManager)1 ParameterServer (com.tencent.angel.ps.impl.ParameterServer)1 ServerMatrix (com.tencent.angel.ps.impl.matrix.ServerMatrix)1 MasterClient (com.tencent.angel.psagent.client.MasterClient)1 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)1 TaskContext (com.tencent.angel.psagent.task.TaskContext)1 Worker (com.tencent.angel.worker.Worker)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1