Skip to content

[release/6.0] Preserve LightGBM validation groups after dataset loading - #7782

Merged
matouskozak merged 1 commit into
release/6.0from
backport/pr-7761-to-release/6.0
Oct 13, 2026
Merged

matouskozak merged 1 commit into
release/6.0from
backport/pr-7761-to-release/6.0

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #7761 to release/6.0

/cc @matouskozak @syhstanley

Customer Impact

Customer reported LightGBM bug #7759

Testing

Risk

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

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.26%. Comparing base (79bf1f8) to head (5ab48a1).

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     
Flag Coverage Δ
Debug 70.26% <100.00%> (+<0.01%) ⬆️
production 64.52% <100.00%> (+<0.01%) ⬆️
test 89.79% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Microsoft.ML.LightGbm/LightGbmTrainerBase.cs 80.58% <100.00%> (+0.02%) ⬆️
...osoft.ML.Tests/TrainerEstimators/TreeEstimators.cs 97.94% <100.00%> (+0.09%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matouskozak
matouskozak requested review from rosebyte, svick and vejbomar and a balanced review from Copilot October 13, 2026 07:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants