Skip to content

Commit

Permalink
Fix verbose param being removed for fit in LightGBM master (#21)
Browse files Browse the repository at this point in the history
* Fix verbose being removed for `fit` in lgbm master

* Fix
  • Loading branch information
Yard1 authored Dec 1, 2021
1 parent e3a2005 commit e4c1ff6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lightgbm_ray/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Callable)
from copy import deepcopy
from dataclasses import dataclass
from distutils.version import LooseVersion

import time
import logging
Expand All @@ -41,6 +42,7 @@
import numpy as np
import pandas as pd

import lightgbm
from lightgbm import LGBMModel, LGBMRanker, Booster
from lightgbm.basic import _choose_param_value, _ConfigAliases, LightGBMError
from lightgbm.callback import CallbackEnv
Expand Down Expand Up @@ -68,6 +70,7 @@
logger.setLevel(logging.DEBUG)

ELASTIC_RESTART_DISABLED = True
LIGHTGBM_VERSION = LooseVersion(lightgbm.__version__)


class StopException(Exception):
Expand Down Expand Up @@ -369,6 +372,15 @@ def train(self, return_bst: bool, params: Dict[str, Any],
callback.is_rank_0 = return_bst
kwargs["callbacks"] = callbacks

if LIGHTGBM_VERSION < LooseVersion("3.3.0"):
# In lightgbm<3.3.0, verbosity doesn't always work as a parameter
# but passing it as kwarg to fit does
local_params = _choose_param_value(
main_param_name="verbosity",
params=local_params,
default_value=1)
kwargs["verbose"] = local_params.pop("verbosity")

result_dict = {}
error_dict = {}

Expand Down Expand Up @@ -1070,8 +1082,10 @@ def _wrapped(*args, **kwargs):
warnings.warn(f"Parameter {param_alias} will be ignored.")
params.pop(param_alias)

if not ("verbose" in kwargs and verbose_eval is True):
kwargs["verbose"] = verbose_eval
if not verbose_eval and not any(
verbose_alias in params
for verbose_alias in _ConfigAliases.get("verbosity")):
params["verbose"] = -1

if gpus_per_actor > 0 and params["device_type"] == "cpu":
warnings.warn(
Expand Down

0 comments on commit e4c1ff6

Please sign in to comment.