Search in sources :

Example 1 with ModelSaveContextProto

use of com.tencent.angel.protobuf.generated.ClientMasterServiceProtos.ModelSaveContextProto 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 {
    ModelSaveContextProto saveContextProto = request.getSaveContext();
    ModelSaveContext saveContext = ProtobufUtil.convert(saveContextProto);
    List<MatrixSaveContext> needSaveMatrices = saveContext.getMatricesContext();
    int size = needSaveMatrices.size();
    for (int i = 0; i < size; i++) {
        if (!context.getMatrixMetaManager().exist(needSaveMatrices.get(i).getMatrixName())) {
            throw new ServiceException("matrix " + needSaveMatrices.get(i).getMatrixName() + " does not exist");
        }
    }
    int requestId;
    try {
        requestId = context.getModelSaver().save(saveContext);
    } catch (Throwable x) {
        throw new ServiceException(x);
    }
    return SaveResponse.newBuilder().setRequestId(requestId).build();
}
Also used : ServiceException(com.google.protobuf.ServiceException) ModelSaveContextProto(com.tencent.angel.protobuf.generated.ClientMasterServiceProtos.ModelSaveContextProto) MatrixSaveContext(com.tencent.angel.model.MatrixSaveContext) ModelSaveContext(com.tencent.angel.model.ModelSaveContext)

Aggregations

ServiceException (com.google.protobuf.ServiceException)1 MatrixSaveContext (com.tencent.angel.model.MatrixSaveContext)1 ModelSaveContext (com.tencent.angel.model.ModelSaveContext)1 ModelSaveContextProto (com.tencent.angel.protobuf.generated.ClientMasterServiceProtos.ModelSaveContextProto)1