fix: return predictions on multiple predict calls#2129
Open
pankajbaid567 wants to merge 3 commits intosktime:mainfrom
Open
fix: return predictions on multiple predict calls#2129pankajbaid567 wants to merge 3 commits intosktime:mainfrom
pankajbaid567 wants to merge 3 commits intosktime:mainfrom
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2129 +/- ##
=======================================
Coverage ? 86.63%
=======================================
Files ? 165
Lines ? 9733
Branches ? 0
=======================================
Hits ? 8432
Misses ? 1301
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reference Issues/PRs
Fixes #2108.
What does this implement/fix? Explain your changes.
When calling
.predict()twice on aTemporalFusionTransformermodel, the second call returns an empty prediction. This happens because PyTorch Lightning clones or duplicates callbacks internally within theTrainerinstantiated in the.predict()method if a trainer is already present or attached. Consequently, the localpredict_callbackinstance's.resultis never populated, while the actual duplicated callback instance processes and holds the results inTrainer.This PR fixes the bug by retrieving the active
PredictCallbackdirectly fromtrainer.callbacksdynamically (scanning in reverse to get the latest updated instance contextually injected) and falling back to the localpredict_callbackobject if not found. This ensures the output is populated correctly on repeated.predict()calls.What should a reviewer concentrate their feedback on?
PredictCallbackinside_base_model.predict, iterating backward overtrainer.callbacks.test_prediction_with_dataloader_twiceto ensure it functionally validates against this behaviour.Did you add any tests for the change?
Yes, added a regression test:
test_prediction_with_dataloader_twicewithintests/test_models/test_temporal_fusion_transformer.py. It explicitly calls.predict()twice and ensures the prediction index length is non-empty (> 0) on both runs.Any other comments?
N/A
PR checklist
pre-commit install.To run hooks independent of commit, execute
pre-commit run --all-files