From b3ed81877af09a19ff134795b452fcd57cba4d8c Mon Sep 17 00:00:00 2001 From: Bobby Wang Date: Tue, 23 Jul 2024 13:57:10 +0800 Subject: [PATCH] [jvm-packages] Cleanup xgboost4j (#10627) --- .../java/ml/dmlc/xgboost4j/java/RabitTracker.java | 2 +- .../main/scala/ml/dmlc/xgboost4j/scala/Booster.scala | 12 +++++++----- .../xgboost4j/scala/ExternalCheckpointManager.scala | 5 +++-- .../main/scala/ml/dmlc/xgboost4j/scala/XGBoost.scala | 4 +++- .../scala/ml/dmlc/xgboost4j/scala/DMatrixSuite.scala | 1 + .../dmlc/xgboost4j/scala/ScalaBoosterImplSuite.scala | 7 ++----- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/RabitTracker.java b/jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/RabitTracker.java index 48b163a77..3fe787be2 100644 --- a/jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/RabitTracker.java +++ b/jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/RabitTracker.java @@ -89,7 +89,7 @@ public class RabitTracker implements ITracker { this.trackerDaemon = new Thread(() -> { try { waitFor(0); - } catch (XGBoostError ex) { + } catch (Exception ex) { logger.error(ex); return; // exit the thread } diff --git a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/Booster.scala b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/Booster.scala index 57c3b9a5d..c7f3cac5c 100644 --- a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/Booster.scala +++ b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/Booster.scala @@ -1,5 +1,5 @@ /* - Copyright (c) 2014-2022 by Contributors + Copyright (c) 2014-2024 by Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,13 +16,15 @@ package ml.dmlc.xgboost4j.scala -import com.esotericsoftware.kryo.io.{Output, Input} -import com.esotericsoftware.kryo.{Kryo, KryoSerializable} -import ml.dmlc.xgboost4j.java.{Booster => JBooster} -import ml.dmlc.xgboost4j.java.XGBoostError import scala.collection.JavaConverters._ import scala.collection.mutable +import com.esotericsoftware.kryo.{Kryo, KryoSerializable} +import com.esotericsoftware.kryo.io.{Input, Output} + +import ml.dmlc.xgboost4j.java.{Booster => JBooster} +import ml.dmlc.xgboost4j.java.XGBoostError + /** * Booster for xgboost, this is a model API that support interactive build of a XGBoost Model * diff --git a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/ExternalCheckpointManager.scala b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/ExternalCheckpointManager.scala index 240c23871..87b9807d0 100644 --- a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/ExternalCheckpointManager.scala +++ b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/ExternalCheckpointManager.scala @@ -1,5 +1,5 @@ /* - Copyright (c) 2014 by Contributors + Copyright (c) 2024 by Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,9 +16,10 @@ package ml.dmlc.xgboost4j.scala -import ml.dmlc.xgboost4j.java.{ExternalCheckpointManager => JavaECM} import org.apache.hadoop.fs.FileSystem +import ml.dmlc.xgboost4j.java.{ExternalCheckpointManager => JavaECM} + class ExternalCheckpointManager(checkpointPath: String, fs: FileSystem) extends JavaECM(checkpointPath, fs) { diff --git a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/XGBoost.scala b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/XGBoost.scala index 561b97ff3..80e1fce14 100644 --- a/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/XGBoost.scala +++ b/jvm-packages/xgboost4j/src/main/scala/ml/dmlc/xgboost4j/scala/XGBoost.scala @@ -17,12 +17,14 @@ package ml.dmlc.xgboost4j.scala import java.io.InputStream -import ml.dmlc.xgboost4j.java.{XGBoostError, XGBoost => JXGBoost} import scala.jdk.CollectionConverters._ + import org.apache.hadoop.conf.Configuration import org.apache.hadoop.fs.Path +import ml.dmlc.xgboost4j.java.{XGBoost => JXGBoost, XGBoostError} + /** * XGBoost Scala Training function. */ diff --git a/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/DMatrixSuite.scala b/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/DMatrixSuite.scala index 53325effa..d81bfde46 100644 --- a/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/DMatrixSuite.scala +++ b/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/DMatrixSuite.scala @@ -21,6 +21,7 @@ import java.util.Arrays import scala.util.Random import org.scalatest.funsuite.AnyFunSuite + import ml.dmlc.xgboost4j.java.{DMatrix => JDMatrix} class DMatrixSuite extends AnyFunSuite { diff --git a/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/ScalaBoosterImplSuite.scala b/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/ScalaBoosterImplSuite.scala index 2eda1fa2d..3cb77f938 100644 --- a/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/ScalaBoosterImplSuite.scala +++ b/jvm-packages/xgboost4j/src/test/scala/ml/dmlc/xgboost4j/scala/ScalaBoosterImplSuite.scala @@ -1,5 +1,5 @@ /* - Copyright (c) 2014-2022 by Contributors + Copyright (c) 2014-2024 by Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package ml.dmlc.xgboost4j.scala -import java.io.{FileOutputStream, FileInputStream, File} +import java.io.{File, FileInputStream, FileOutputStream} import junit.framework.TestCase import org.apache.commons.logging.LogFactory @@ -169,7 +169,6 @@ class ScalaBoosterImplSuite extends AnyFunSuite { test("test with quantile histo lossguide with max bin") { val trainMat = new DMatrix("../../demo/data/agaricus.txt.train?format=libsvm") - val testMat = new DMatrix("../../demo/data/agaricus.txt.test?format=libsvm") val paramMap = List("max_depth" -> "3", "silent" -> "0", "objective" -> "binary:logistic", "tree_method" -> "hist", "grow_policy" -> "lossguide", "max_leaves" -> "8", "max_bin" -> "16", @@ -180,7 +179,6 @@ class ScalaBoosterImplSuite extends AnyFunSuite { test("test with quantile histo depthwidth with max depth") { val trainMat = new DMatrix("../../demo/data/agaricus.txt.train?format=libsvm") - val testMat = new DMatrix("../../demo/data/agaricus.txt.test?format=libsvm") val paramMap = List("max_depth" -> "0", "silent" -> "0", "objective" -> "binary:logistic", "tree_method" -> "hist", "grow_policy" -> "depthwise", "max_leaves" -> "8", "max_depth" -> "2", @@ -191,7 +189,6 @@ class ScalaBoosterImplSuite extends AnyFunSuite { test("test with quantile histo depthwidth with max depth and max bin") { val trainMat = new DMatrix("../../demo/data/agaricus.txt.train?format=libsvm") - val testMat = new DMatrix("../../demo/data/agaricus.txt.test?format=libsvm") val paramMap = List("max_depth" -> "0", "silent" -> "0", "objective" -> "binary:logistic", "tree_method" -> "hist", "grow_policy" -> "depthwise", "max_depth" -> "2", "max_bin" -> "2",