Search in sources :

Example 1 with MatrixLoadContext

use of com.tencent.angel.model.MatrixLoadContext in project angel by Tencent.

the class MasterService method load.

/**
 * Load model from file
 */
@Override
public LoadResponse load(RpcController controller, LoadRequest request) throws ServiceException {
    if (context.getModelLoader().isLoading()) {
        throw new ServiceException("Model is loading now, please wait");
    }
    ModelLoadContextProto loadContextProto = request.getLoadContext();
    ModelLoadContext loadContext = ProtobufUtil.convert(loadContextProto);
    List<MatrixLoadContext> needLoadMatrices = loadContext.getMatricesContext();
    int size = needLoadMatrices.size();
    for (int i = 0; i < size; i++) {
        if (!context.getMatrixMetaManager().exist(needLoadMatrices.get(i).getMatrixName())) {
            throw new ServiceException("matrix " + needLoadMatrices.get(i).getMatrixName() + " does not exist");
        }
    }
    int requestId;
    try {
        requestId = context.getModelLoader().load(loadContext);
    } catch (Throwable x) {
        throw new ServiceException(x);
    }
    return LoadResponse.newBuilder().setRequestId(requestId).build();
}
Also used : ServiceException(com.google.protobuf.ServiceException) MatrixLoadContext(com.tencent.angel.model.MatrixLoadContext) ModelLoadContext(com.tencent.angel.model.ModelLoadContext) ModelLoadContextProto(com.tencent.angel.protobuf.generated.ClientMasterServiceProtos.ModelLoadContextProto)

Example 2 with MatrixLoadContext

use of com.tencent.angel.model.MatrixLoadContext in project angel by Tencent.

the class AngelClient method load.

public void load(Set<String> matrixNames) {
    // Check need load matrices
    String loadPath = conf.get(AngelConf.ANGEL_LOAD_MODEL_PATH);
    if (loadPath != null && !loadPath.isEmpty()) {
        ModelLoadContext loadContext = new ModelLoadContext(loadPath);
        int needLoadMatrixCount = 0;
        for (String name : matrixNames) {
            MatrixContext matrix = nameToMatrixMap.get(name);
            if (matrix.getAttributes().get(MatrixConf.MATRIX_LOAD_PATH) != null) {
                loadContext.addMatrix(new MatrixLoadContext(name));
                needLoadMatrixCount++;
            }
        }
        if (needLoadMatrixCount > 0) {
            load(loadContext);
        }
    }
}
Also used : MatrixContext(com.tencent.angel.ml.matrix.MatrixContext) MatrixLoadContext(com.tencent.angel.model.MatrixLoadContext) ModelLoadContext(com.tencent.angel.model.ModelLoadContext)

Aggregations

MatrixLoadContext (com.tencent.angel.model.MatrixLoadContext)2 ModelLoadContext (com.tencent.angel.model.ModelLoadContext)2 ServiceException (com.google.protobuf.ServiceException)1 MatrixContext (com.tencent.angel.ml.matrix.MatrixContext)1 ModelLoadContextProto (com.tencent.angel.protobuf.generated.ClientMasterServiceProtos.ModelLoadContextProto)1