Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 2b392d4

Browse files
authored
Compatibility for xgboost 0.90 (#90)
1 parent 09d732f commit 2b392d4

File tree

13 files changed

+517
-27
lines changed

13 files changed

+517
-27
lines changed

.github/workflows/test.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,39 @@ jobs:
189189
bash ./run_ci_tests.sh
190190
- name: Run examples
191191
run: |
192-
bash ./run_ci_examples.sh
192+
bash ./run_ci_examples.sh
193+
194+
test_linux_xgboost_legacy:
195+
# Tests on XGBoost 0.90 and latest Ray release
196+
runs-on: ubuntu-latest
197+
timeout-minutes: 14
198+
strategy:
199+
matrix:
200+
python-version: [3.6.9]
201+
steps:
202+
- uses: actions/checkout@v2
203+
- name: Set up Python ${{ matrix.python-version }}
204+
uses: actions/setup-python@v2
205+
with:
206+
python-version: ${{ matrix.python-version }}
207+
- name: Install dependencies
208+
run: |
209+
python -m pip install --upgrade pip
210+
python -m pip install codecov
211+
python -m pip install -U ray
212+
if [ -f requirements-test.txt ]; then python -m pip install -r requirements-test.txt; fi
213+
- name: Install package
214+
run: |
215+
python -m pip install -e .
216+
- name: Install legacy XGBoost
217+
run: |
218+
python -m pip install xgboost==0.90
219+
- name: Print environment info
220+
run: |
221+
./xgboost_ray/tests/env_info.sh
222+
- name: Run tests
223+
run: |
224+
bash ./run_ci_tests.sh
225+
- name: Run examples
226+
run: |
227+
bash ./run_ci_examples.sh

examples/simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main(cpus_per_actor, num_actors):
3434
evals=[(test_set, "eval")],
3535
evals_result=evals_result,
3636
ray_params=RayParams(
37-
max_actor_restarts=1,
37+
max_actor_restarts=0,
3838
gpus_per_actor=0,
3939
cpus_per_actor=cpus_per_actor,
4040
num_actors=num_actors),

format.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,22 @@ format_changed() {
104104
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
105105
if which flake8 >/dev/null; then
106106
git diff --name-only --diff-filter=ACRM "$MERGEBASE" -- '*.py' | xargs -P 5 \
107-
flake8 --inline-quotes '"' --no-avoid-escape --ignore=C408,E121,E123,E126,E226,E24,E704,W503,W504,W605
107+
flake8 --inline-quotes '"' --no-avoid-escape --ignore=N,I,C408,E121,E123,E126,E226,E24,E704,W503,W504,W605
108108
fi
109109
fi
110110

111111
if ! git diff --diff-filter=ACRM --quiet --exit-code "$MERGEBASE" -- '*.pyx' '*.pxd' '*.pxi' &>/dev/null; then
112112
if which flake8 >/dev/null; then
113113
git diff --name-only --diff-filter=ACRM "$MERGEBASE" -- '*.pyx' '*.pxd' '*.pxi' | xargs -P 5 \
114-
flake8 --inline-quotes '"' --no-avoid-escape --ignore=C408,E121,E123,E126,E211,E225,E226,E227,E24,E704,E999,W503,W504,W605
114+
flake8 --inline-quotes '"' --no-avoid-escape --ignore=N,I,C408,E121,E123,E126,E211,E225,E226,E227,E24,E704,E999,W503,W504,W605
115115
fi
116116
fi
117117
}
118118

119119
# Format all files, and print the diff to stdout for travis.
120120
format_all() {
121121
yapf --diff "${YAPF_FLAGS[@]}" "${YAPF_EXCLUDES[@]}" xgboost_ray
122-
flake8 --inline-quotes '"' --no-avoid-escape --ignore=C408,E121,E123,E126,E211,E225,E226,E227,E24,E704,E999,W503,W504,W605 xgboost_ray
122+
flake8 --inline-quotes '"' --no-avoid-escape --ignore=N,I,C408,E121,E123,E126,E211,E225,E226,E227,E24,E704,E999,W503,W504,W605 xgboost_ray
123123
}
124124

125125
# This flag formats individual files. --files *must* be the first command line

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"distributed computing framework Ray.",
1111
url="https://github.com/ray-project/xgboost_ray",
1212
install_requires=[
13-
"xgboost>=1.3", "ray", "numpy>=1.16,<1.20", "pandas", "pyarrow"
13+
"xgboost>=0.90", "ray", "numpy>=1.16,<1.20", "pandas", "pyarrow"
1414
])

xgboost_ray/compat/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import xgboost as xgb
2+
3+
try:
4+
from xgboost.callback import TrainingCallback
5+
LEGACY_CALLBACK = False
6+
except ImportError:
7+
8+
class TrainingCallback:
9+
def __init__(self):
10+
if hasattr(self, "before_iteration"):
11+
# XGBoost < 1.0 is looking up __dict__ to see if a
12+
# callback should be called before or after an iteration.
13+
# So here we move this to self._before_iteration and
14+
# overwrite the dict.
15+
self._before_iteration = getattr(self, "before_iteration")
16+
self.__dict__["before_iteration"] = True
17+
18+
def __call__(self, callback_env: xgb.core.CallbackEnv):
19+
if hasattr(self, "_before_iteration"):
20+
self._before_iteration(
21+
model=callback_env.model,
22+
epoch=callback_env.iteration,
23+
evals_log=callback_env.evaluation_result_list)
24+
25+
if hasattr(self, "after_iteration"):
26+
self.after_iteration(
27+
model=callback_env.model,
28+
epoch=callback_env.iteration,
29+
evals_log=callback_env.evaluation_result_list)
30+
31+
def before_training(self, model):
32+
pass
33+
34+
def after_training(self, model):
35+
pass
36+
37+
LEGACY_CALLBACK = True
38+
39+
try:
40+
from xgboost import RabitTracker
41+
except ImportError:
42+
from xgboost_ray.compat.tracker import RabitTracker
43+
44+
__all__ = ["TrainingCallback", "RabitTracker"]

0 commit comments

Comments
 (0)