Search in sources :

Example 6 with MatrixFilesMeta

use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.

the class ModelLoader method loadToDoubleArrays.

/**
 * Load dense double model to a 2-dimension double array
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static double[][] loadToDoubleArrays(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_DENSE && rowType != RowType.T_DOUBLE_DENSE_COMPONENT) {
        throw new IOException("model row type is not dense double, you should check it");
    }
    // Load model
    DenseDoubleModel model = new DenseDoubleModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 7 with MatrixFilesMeta

use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.

the class ModelLoader method loadToDoubleMaps.

/**
 * Load dense double model to int->double maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Int2DoubleOpenHashMap[] loadToDoubleMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_SPARSE && rowType != RowType.T_DOUBLE_SPARSE_COMPONENT) {
        throw new IOException("model row type is not sparse double, you should check it");
    }
    // Load model
    SparseDoubleModel model = new SparseDoubleModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 8 with MatrixFilesMeta

use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.

the class ModelLoader method loadToIntArrays.

/**
 * Load dense float model to a 2-dimension int array
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static int[][] loadToIntArrays(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_INT_DENSE && rowType != RowType.T_INT_DENSE_COMPONENT) {
        throw new IOException("model row type is not dense int, you should check it");
    }
    // Load model
    DenseIntModel model = new DenseIntModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 9 with MatrixFilesMeta

use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.

the class ModelLoader method getMeta.

/**
 * Get model meta
 *
 * @param modelDir model save directory path
 * @return model meta
 */
public static MatrixFilesMeta getMeta(String modelDir, Configuration conf) throws IOException {
    Path modelPath = new Path(modelDir);
    Path meteFilePath = new Path(modelPath, ModelFilesConstent.modelMetaFileName);
    MatrixFilesMeta meta = new MatrixFilesMeta();
    FileSystem fs = meteFilePath.getFileSystem(conf);
    if (!fs.exists(meteFilePath)) {
        throw new IOException("matrix meta file does not exist ");
    }
    FSDataInputStream input = fs.open(meteFilePath);
    meta.read(input);
    input.close();
    return meta;
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Example 10 with MatrixFilesMeta

use of com.tencent.angel.model.output.format.MatrixFilesMeta in project angel by Tencent.

the class ModelLoader method loadToDoubleLongKeyMaps.

/**
 * Load dense double model to long->double maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Long2DoubleOpenHashMap[] loadToDoubleLongKeyMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_SPARSE_LONGKEY && rowType != RowType.T_DOUBLE_SPARSE_LONGKEY_COMPONENT) {
        throw new IOException("model row type is not sparse long double, you should check it");
    }
    // Load model
    SparseDoubleLongKeyModel model = new SparseDoubleLongKeyModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Aggregations

MatrixFilesMeta (com.tencent.angel.model.output.format.MatrixFilesMeta)16 IOException (java.io.IOException)13 RowType (com.tencent.angel.ml.matrix.RowType)7 Path (org.apache.hadoop.fs.Path)5 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)2 ParameterServerId (com.tencent.angel.ps.ParameterServerId)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)1 PartitionMeta (com.tencent.angel.ml.matrix.PartitionMeta)1 MatrixPartitionMeta (com.tencent.angel.model.output.format.MatrixPartitionMeta)1 PSMatrixFilesMeta (com.tencent.angel.model.output.format.PSMatrixFilesMeta)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1