Skip to content

Fix empty results when calling predict() twice#2123

Open
Koolvansh07 wants to merge 1 commit intosktime:mainfrom
Koolvansh07:fix/predict-callback-result-2108
Open

Fix empty results when calling predict() twice#2123
Koolvansh07 wants to merge 1 commit intosktime:mainfrom
Koolvansh07:fix/predict-callback-result-2108

Conversation

@Koolvansh07
Copy link

Summary

Fixes a bug where a second call to BaseModel.predict() can return an empty result.

The issue happens because predict() returned the local PredictCallback instance, while Lightning may attach/use a callback instance from rainer.callbacks after trainer/model attachment.

This patch returns the active PredictCallback from rainer.callbacks (falling back to the local one).

Tests

  • Added regression test: est_prediction_with_dataloader_twice

Closes #2108

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@6b27898). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2123   +/-   ##
=======================================
  Coverage        ?   86.63%           
=======================================
  Files           ?      165           
  Lines           ?     9733           
  Branches        ?        0           
=======================================
  Hits            ?     8432           
  Misses          ?     1301           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.63% <100.00%> (?)
pytest 86.63% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Calling BaseModel.predict a second time after trainer attaches to the model causes pred returned to be empty

1 participant