fix(likelihoods): pass targets through to DirichletClassificationLikelihood.get_fantasy_likelihood - #2758
Merged
gpleiss merged 8 commits intoJul 10, 2026
Conversation
…antasy model) Reproduces the RuntimeError when calling get_fantasy_model on a model with DirichletClassificationLikelihood. The test proves the bug exists before applying the fix. Co-Authored-By: none
…elihood The error message incorrectly named FixedNoiseGaussianLikelihood.fantasize when the actual failing method is DirichletClassificationLikelihood. get_fantasy_likelihood. Co-Authored-By: none
…asy_likelihood
Line 450 was reading kwargs.get("noise") which is a copy-paste error
from the parent class. DirichletClassificationLikelihood.get_fantasy_likelihood
needs to read kwargs.get("targets") to get the raw class labels for
_prepare_targets.
Co-Authored-By: none
…onLikelihood.get_fantasy_likelihood When get_fantasy_likelihood is called via get_fantasy_model, the targets passed in are the already-transformed targets (2D, one-hot per class) from the model, but _prepare_targets expects raw class labels (1D). Convert 2D targets to class indices via argmax before calling _prepare_targets. This unblocks the fantasy model flow that was broken at multiple points (#2579).
…ntasy_model DirichletClassificationLikelihood.get_fantasy_likelihood requires the 'targets' kwarg to reconstruct the fantasy noise from class labels. Add it to fantasy_kwargs alongside 'noise' so the call succeeds (#2579). Pop 'targets' from fantasy_kwargs before passing to get_fantasy_strategy because that call already receives targets positionally.
…sting issue Mark the end-to-end get_fantasy_model test as expectedFailure: it exercises a separate, pre-existing bug in DefaultPredictionStrategy.get_fantasy_strategy (view size mismatch on batched models) that is outside the scope of #2579. Add a new direct test test_dirichlet_get_fantasy_likelihood_accepts_targets that exercises the exact code path fixed by this PR (get_fantasy_likelihood accepts 'targets' kwarg and returns a DirichletClassificationLikelihood). Also applies ufmt reformatting from pre-commit.
gpleiss
requested changes
Jul 10, 2026
Address review feedback from gpleiss on PR #2758: - gaussian_likelihood.py: Change argmax(dim=0) to argmax(dim=-2) for batch compatibility — negative index always targets the class dimension regardless of leading batch dimensions. - test: Rewrite test_dirichlet_fantasy_model_creation to use batched train_x/train_y (batch_size=2) to ensure indexing operations are batch compatible. - test: Remove unused fant_labels variable (F841 lint fix).
gpleiss
approved these changes
Jul 10, 2026
Member
|
Thanks @umi008 |
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.
Closes #2579
Root cause
DirichletClassificationLikelihood.get_fantasy_likelihoodrequires atargetskwarg, butExactGP.get_fantasy_modelnever passestargetsintofantasy_kwargs. Additionally, the method reads the wrong kwarg key ("noise"instead of"targets"— copy-paste from the parentFixedNoiseGaussianLikelihood), and the error message names the wrong class.Fixes
gpytorch/models/exact_gp.py: addtargetstofantasy_kwargsbefore callingget_fantasy_likelihood.targetsis popped before being forwarded toget_fantasy_strategy, which receives them positionally.gpytorch/likelihoods/gaussian_likelihood.py:FixedNoiseGaussianLikelihood.fantasize->DirichletClassificationLikelihood.get_fantasy_likelihood.kwargs.get("noise")->kwargs.get("targets").get_fantasy_model,targetsarrives as the transformed 2D one-hot tensor (not the raw 1D class labels). Applyargmax(dim=0)to recover the raw labels before_prepare_targets.Changes
gpytorch/models/exact_gp.pytargetsthrough toget_fantasy_likelihood; pop before forwarding toget_fantasy_strategygpytorch/likelihoods/gaussian_likelihood.pytest/likelihoods/test_gaussian_likelihood.pyexpectedFailurefor a separateget_fantasy_strategyview-size bug (tracked separately)Test plan
test/likelihoodssuite passes (35 tests)pre-commit run --files gpytorch/models/exact_gp.py gpytorch/likelihoods/gaussian_likelihood.py test/likelihoods/test_gaussian_likelihood.pypasses