Repository navigation
[release/6.0] Preserve LightGBM validation groups after dataset loading - #7782
Merged
Merged
Conversation
Fixes #7759 ## Summary Preserve validation query boundaries when training a LightGBM ranker through ML.NET's `Fit(trainData, validationData)`. ## Root cause LightGBM's `LGBM_DatasetCreateByReference` initializes the validation dataset's `query_` vector with zeros because the training dataset contains query information. ML.NET supplies group sizes through LightGBM's `LGBM_DatasetSetField("group")`, but does not populate LightGBM's per-row `query_` vector. When ML.NET pushes the last validation rows through LightGBM's `LGBM_DatasetPushRows`, LightGBM's `FinishLoad()` rebuilds the query boundaries from the zero-filled `query_` vector and merges all validation rows into one query. The training dataset does not have this issue because ML.NET creates it through LightGBM's `LGBM_DatasetCreateFromSampledColumn`, which leaves `query_` empty. LightGBM's `FinishLoad()` therefore does not rebuild its query boundaries. ## Fix Apply the validation groups after ML.NET's `LoadDataset` completes. LightGBM's `LGBM_DatasetSetField("group")` then updates the query count, query boundaries, query weights, and CUDA metadata before the validation dataset is added to the booster. ## Tests Added a regression test that verifies a ranking model can be trained with many validation groups. ## Additional information LightGBM supports ranking metadata in two forms: - Group sizes through `LGBM_DatasetSetField("group")`. - Per-row query IDs through the streaming `LGBM_DatasetPushRowsWithMetadata` API. ML.NET currently uses LightGBM's non-streaming `LGBM_DatasetPushRows` path, where query IDs cannot be supplied with each row. Switching to per-row query IDs would require moving ML.NET's dataset loader to the streaming API and extending its native wrappers and batch metadata handling. LightGBM ranking only requires query boundaries, not the original query ID values, so group sizes remain a valid representation. Applying them after loading is therefore the smallest targeted fix. --------- Co-authored-by: Yu-Hong Shen <stanley.shen2003@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/6.0 #7782 +/- ##
============================================
Coverage 70.26% 70.26%
============================================
Files 1419 1419
Lines 272569 272603 +34
Branches 27938 27940 +2
============================================
+ Hits 191519 191553 +34
- Misses 73637 73638 +1
+ Partials 7413 7412 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
matouskozak
approved these changes
Oct 13, 2026
matouskozak
requested review from
rosebyte,
svick and
vejbomar
and
a balanced review from Copilot
October 13, 2026 07:54
rosebyte
approved these changes
Oct 13, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The targeted backport matches the merged upstream fix and includes regression coverage for the reported failure.
0 open findings
What changed in this PR
Backports #7761 to preserve LightGBM validation query boundaries during ranking training.
Changes:
- Applies validation groups after dataset loading.
- Adds regression coverage using 5,000 validation groups.
| File | Description |
|---|---|
src/Microsoft.ML.LightGbm/LightGbmTrainerBase.cs |
Restores validation groups after rows are loaded. |
test/Microsoft.ML.Tests/TrainerEstimators/TreeEstimators.cs |
Tests ranking with many validation groups. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Nov 11, 2026
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #7761 to release/6.0
/cc @matouskozak @syhstanley
Customer Impact
Customer reported LightGBM bug #7759
Testing
Risk