[jvm-packages] Linux上使用 Booster.preprict () 的无限制本地内存增长( 2.1.4 – 3. 4. 0)
import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.util.HashMap; import java.util.Map; import ml.dmlc.xgboost4j.java.Booster; import ml.dmlc.xgboost4j.java.DMatrix; import ml.dmlc.xgboost4j.java.XGBoost; /** * Minimal reproducer for a native memory leak in xgboost4j on linux/x86_64: * RSS grows linearly (~0.5-0.9 KB per cycle) as long as the JVM keeps doing * "new DMatrix -> Booster.predict -> DMatrix.dispose" cycles, and never plateaus. * Construct+dispose without predict is flat; a single reused DMatrix is flat. */ public class LeakRepro { public static void main(String[] args) throws Exception { final int rows = 1440, cols = 14; float[] data = new float[rows * cols]; float[] labels = new float[rows]; java.util.Random rnd = new java.util.Random(42); for (int i = 0; i < data.length; i++) data[i] = rnd.nextFloat() * 100f; for (int i = 0; i < rows; i++) labels[i] = rnd.nextFloat() * 100f; // Train a small booster (quantile objective, as used by our production models). Map<String, Object> params = new HashMap(); params.put("objective", "reg:quantileerror"); params.put("quantile_alpha", 0.5); params.put("max_depth", 4); params.put("nthread", 2); DMatrix train = new DMatrix(data, rows, cols); train.setLabel(labels); Booster booster = XGBoost.train(train, params, 20, new HashMap<String, DMatrix>(), null, null); train.dispose(); // Warm up: native lib load, JIT, OpenMP thread pool. for (int i = 0; i < 1000; i++) { DMatrix dm = new DMatrix(data, rows, cols); booster.predict(dm, false,
内容来源: dmlc/xgboost