fix: guard optional validation fields in CSAI forward during inference#838
Open
shaun0927 wants to merge 1 commit into
Open
fix: guard optional validation fields in CSAI forward during inference#838shaun0927 wants to merge 1 commit into
shaun0927 wants to merge 1 commit into
Conversation
The post-eval block unconditionally reads inputs["X_ori"] and inputs["indicating_mask"] whenever self.training is False. These keys are only populated in validation batches, so predict() paths where the user's Dataset omits ground-truth fields crash with KeyError. Gating the accesses keeps validation behavior unchanged and restores plain inference on minimal input dicts.
|
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
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.



Description
In
pypots/imputation/csai/core.py,_BCSAI.forwardends with:The first block correctly gates
X_ori/indicating_maskbehindcalc_criterion(those keys only exist in validation batches). The secondblock runs whenever
self.trainingis False — including plainpredict()calls where the user's
Datasethas no ground-truth fields — and raisesKeyError: 'X_ori'there.The unconditional accesses were introduced when CSAI was re-landed in PR
#788 and never made it through a predict-only test. This PR restores the
invariant by guarding the accesses so they only fire when the keys actually
exist in the input dict.
Changes
pypots/imputation/csai/core.py: wrap theresults["x_ori"]andresults["indicating_mask"]assignments inif "X_ori" in inputs:/if "indicating_mask" in inputs:checks. Semantically identical for anycaller that already provides those keys (validation); now safe for pure
inference.
Testing
keys present, both entries are added to
resultsjust as before.X,missing_mask, thedeltas_*/
last_obs_*pair) now returns the regular result dict without raisingKeyError.No changes to model weights, training loss, or validation metric; the fix
is limited to two safe attribute lookups.