Skip to content

TST Fix some tests with global_random_seed in test_logistic.py - #33021

Merged
ogrisel merged 2 commits into
scikit-learn:mainfrom
OmarManzoor:fix-lr-tests
Jan 7, 2026
Merged

ogrisel merged 2 commits into
scikit-learn:mainfrom
OmarManzoor:fix-lr-tests

Conversation

@OmarManzoor

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Follow up on #32759 (comment)

What does this implement/fix? Explain your changes.

  • Fix tests test_logistic_cv_sparse and test_logreg_l1 so that they pass with all global random seeds.

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Any other comments?

@OmarManzoor OmarManzoor changed the title Fix some tests with global_random_seed in test_logistic.py TST Fix some tests with global_random_seed in test_logistic.py Jan 7, 2026
@OmarManzoor OmarManzoor changed the title TST Fix some tests with global_random_seed in test_logistic.py TST Fix some tests with global_random_seed in test_logistic.py Jan 7, 2026
test_logreg_l1
test_logistic_cv_sparse
@OmarManzoor

Copy link
Copy Markdown
Contributor Author

@lesteve I am not sure how to figure out the test_logreg_l1 error. The other one seems to be fixed

@OmarManzoor

Copy link
Copy Markdown
Contributor Author

@lorentzenchr Can you please have a look?

@ogrisel

ogrisel commented Jan 7, 2026

Copy link
Copy Markdown
Member

I am not sure how to figure out the test_logreg_l1 error.

I checked the Azure test report for the above run and test_logreg_l1 passed for all random seeds as expected from the commit message.

@ogrisel

ogrisel commented Jan 7, 2026

Copy link
Copy Markdown
Member

Let's merge this quickly to get the test_logistic_cv_sparse fix in main so that it stops disrupting other PRs.

We can open a follow-up PR for test_logreg_l1 if someone actually manages to reproduce the problem.

@lorentzenchr

Copy link
Copy Markdown
Member

@OmarManzoor Thanks for the fix.

General comment: As a developer, I find our test setup too complicated. Even when running tests with all rng seeds locally, one still needs a commit to trigger the CD pipeline with all seeds.
I would prefer to not need to think about test random seeds at all.

@lesteve

lesteve commented Jan 8, 2026 •

Copy link
Copy Markdown
Member

@lesteve I am not sure how to figure out the test_logreg_l1 error. The other one seems to be fixed

@OmarManzoor I guess you can still check in a PR that the free-threaded build pass with a commit message like this

[free-threaded] [all random seeds]
test_logreg_l1

@lesteve

lesteve commented Jan 8, 2026 •

Copy link
Copy Markdown
Member

General comment: As a developer, I find our test setup too complicated. Even when running tests with all rng seeds locally, one still needs a commit to trigger the CD pipeline with all seeds. I would prefer to not need to think about test random seeds at all.

Personally I am less and less convinced that our global_random_seed setup is worth its maintenance cost. I do understand why it exists, i.e. catch numerical instability or avoid that a test pass only because we chose a lucky random seed. At the same time this setup has a maintenance cost and I am not sure we have actually seen any of the benefit. Maybe I don't remember the few cases where it allowed us to notice a numerical instability or maybe it's the kind of "silent" usefulness that makes you write a more robust test in the first place and/or catch numerical instability bugs when you write the test.

To be explicit about the maintenance costs:

  • intermittent CI error tracking. I am probably the main person that seems to care about sporadic automatically opened issues. This does take a bit of time (like a few hours a week maybe) and adds some noise in the CI. I would say global_random_seed are the main source of intermittent errors even if there are others, like conda-forge download error, or intermittent segmentation fault on free-threaded.
  • ad-hoc PR raising atol and/or rtol where nobody really has a super clear idea whether this is OK or not to raise it or it would need a deeper look and generally we merge anyway.
  • new global_random_seed issues keep appearing, the PR CI only checks a single random seed, and it's only afterwards that you notice issues in automatically opened issues where the global random seed is random on each daily schedule run.

@lorentzenchr to answer your point I don't know how to make our test setup simpler with our current set of constraints so I am proposing to remove one constraint (without too much hope to be honest).

In an ideal infinite-resources world (which we don't live in, remember 😉), I think we should have some kind of fuzzing-like tests that lives outside the main CI workflow, tweaks the random seeds, and reports the most problematic tests (maybe they fail for a high number of seeds, maybe the difference is big for values not near 0, or some better criterion). Just to be explicit, this ideal scenario is super unlikely to happen.

@ogrisel

ogrisel commented Jan 13, 2026

Copy link
Copy Markdown
Member

+1 to remove the random selection of the seed in nightly builds while keeping the rest of the fixture as is (and in particular the fact that different CI builds use distinct but fixed seeds).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants