Skip to content

Commit

Permalink
Update XGBoost-Ray by removing deprecated calls for Ray 2.0 (#227)
Browse files Browse the repository at this point in the history
Following ray-project/ray#26907, we can now avoid a deprecation message when using XGBRay with 2.0.

Signed-off-by: Richard Liaw <[email protected]>
  • Loading branch information
richardliaw authored Jul 25, 2022
1 parent a84a446 commit 08f3bc1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions xgboost_ray/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ def __exit__(self, *args):

def _ray_get_actor_cpus():
# Get through resource IDs
resource_ids = ray.worker.get_resource_ids()
if "CPU" in resource_ids:
return sum(cpu[1] for cpu in resource_ids["CPU"])
return None
if LooseVersion(ray.__version__) < LooseVersion("2.0.0"):
# Remove after 2.2?
resource_ids = ray.worker.get_resource_ids()
if "CPU" in resource_ids:
return sum(cpu[1] for cpu in resource_ids["CPU"])
else:
resource_ids = ray.get_runtime_context().get_assigned_resources()
return resource_ids.get("CPU")


def _ray_get_cluster_cpus():
Expand Down Expand Up @@ -569,9 +573,7 @@ def train(self, rabit_args: List[str], return_bst: bool,
local_params["nthread"] = num_threads
local_params["n_jobs"] = num_threads
else:
local_params["nthread"] = sum(
num
for _, num in ray.worker.get_resource_ids().get("CPU", []))
local_params["nthread"] = _ray_get_actor_cpus()
local_params["n_jobs"] = local_params["nthread"]

if dtrain not in self._data:
Expand Down

0 comments on commit 08f3bc1

Please sign in to comment.