Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove param 'evals_result' 'early_stopping_rounds' in lightgbm version > 3.3.1 #5206

Merged
merged 5 commits into from Dec 31, 2021

Conversation

liangz1
Copy link
Collaborator

@liangz1 liangz1 commented Dec 28, 2021

Signed-off-by: Liang Zhang liang.zhang@databricks.com

What changes are proposed in this pull request?

The parameter evals_result is removed in the master of lightgbm: microsoft/LightGBM#4882.
The parameter early_stopping_rounds is removed in the master of lightgbm: microsoft/LightGBM#4908.

We should also remove this param in our test.

This PR also fixed the sagemaker test failure.

How is this patch tested?

Existing tests.

Does this PR change the documentation?

  • No. You can skip the rest of this section.
  • Yes. Make sure the changed pages / sections render correctly by following the steps below.
  1. Check the status of the ci/circleci: build_doc check. If it's successful, proceed to the
    next step, otherwise fix it.
  2. Click Details on the right to open the job page of CircleCI.
  3. Click the Artifacts tab.
  4. Click docs/build/html/index.html.
  5. Find the changed pages / sections and make sure they render correctly.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

(Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Signed-off-by: Liang Zhang <liang.zhang@databricks.com>
@github-actions github-actions bot added area/tracking Tracking service, tracking client APIs, autologging rn/none List under Small Changes in Changelogs. labels Dec 28, 2021
@liangz1 liangz1 added the enable-dev-tests Enables cross-version tests for dev versions label Dec 28, 2021
Signed-off-by: Liang Zhang <liang.zhang@databricks.com>
@liangz1 liangz1 changed the title Remove param 'evals_result' in lightgbm version > 3.3.1 Remove param 'evals_result' 'early_stopping_rounds' in lightgbm version > 3.3.1 Dec 29, 2021
Signed-off-by: Liang Zhang <liang.zhang@databricks.com>
for cb in kwargs["callbacks"]:
if (
hasattr(cb, "__qualname__")
and cb.__qualname__ == "early_stopping.<locals>._callback"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checking is a little tricky , is there better way ? I think you want to check whether the callback is lgb.early_stopping(5) , can we directly compare the function object with it ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly comparing function object seems not working:

lightgbm.early_stopping(stopping_rounds=1) is lightgbm.early_stopping(stopping_rounds=1) # False
lightgbm.early_stopping(stopping_rounds=1) == lightgbm.early_stopping(stopping_rounds=1) # False

Copy link
Collaborator

@WeichenXu123 WeichenXu123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except one comment

Signed-off-by: Liang Zhang <liang.zhang@databricks.com>
early_stopping = (
num_pos_args >= early_stopping_index + 1 or "early_stopping_rounds" in kwargs
)
early_stopping = model.best_iteration > 0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.best_iteration > 0 can be used to determine whether early stopping is activated.

model.best_iteration is initiated as 0 and is assigned with a positive int when EarlyStoppingException is raised (this means early stopping is activated, including using the early_stopping_rounds param, lightgbm.early_stopping callback function, or even a user-defined early_stopping callback that raises EarlyStoppingException).
model.best_iteration is returned as 0 when early stopping is not activated.

Reference: https://github.com/microsoft/LightGBM/blob/ce486e5b45a6f5e67743e14765ed139ff8d532e5/python-package/lightgbm/engine.py#L226-L263

Signed-off-by: Liang Zhang <liang.zhang@databricks.com>
new_backend = SageMakerBackend()
sagemaker_backends[region] = new_backend
# Create a SageMaker backend for EC2 region: "us-west-2"
sagemaker_backends = {"us-west-2": SageMakerBackend()}
Copy link
Collaborator Author

@liangz1 liangz1 Dec 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the description in getmoto/moto#4699:

all backends are now generated on-request, rather then on start-up.

So we need to create a SageMaker backend for "us-west-2", which is used in our test. Since "us-west-2" is hardcoded in our tests as the default AWS region, I also hardcoded it here.

With moto==2.3.0, the old implementation only returns one region "us-east-1", which is the default region used by moto.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably update the small-requirements.txt now to instead of excluding version 2.0.7, just force use of >=2.3.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is also compatible with moto<2.3.0, so we don't have to change it now.

@liangz1 liangz1 merged commit c0e0571 into mlflow:master Dec 31, 2021
@liangz1 liangz1 deleted the remove-evals-result branch December 31, 2021 07:06
ankit-db pushed a commit that referenced this pull request Jan 4, 2022
* Add method to load model input example

Signed-off-by: Matthieu Maitre <mmaitre@microsoft.com>

* Try fixing doc and lint failures

Signed-off-by: Matthieu Maitre <mmaitre@microsoft.com>

* Remove param 'evals_result' 'early_stopping_rounds' in lightgbm version > 3.3.1 (#5206)

The parameter evals_result is removed in the master of lightgbm: microsoft/LightGBM#4882.
The parameter early_stopping_rounds is removed in the master of lightgbm: microsoft/LightGBM#4908.

We should also remove this param in our test.

This PR also fixed the sagemaker test failure.

Signed-off-by: Liang Zhang <liang.zhang@databricks.com>

* Address PR feedback

Signed-off-by: Matthieu Maitre <mmaitre@microsoft.com>

Co-authored-by: Liang Zhang <liang.zhang@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tracking Tracking service, tracking client APIs, autologging enable-dev-tests Enables cross-version tests for dev versions rn/none List under Small Changes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants