Fix dimension mismatch and add auto-loss support to TRAK#246
Open
traderbxy wants to merge 2 commits intoTRAIS-Lab:mainfrom
Open
Fix dimension mismatch and add auto-loss support to TRAK#246traderbxy wants to merge 2 commits intoTRAIS-Lab:mainfrom
traderbxy wants to merge 2 commits intoTRAIS-Lab:mainfrom
Conversation
jiaqima
reviewed
Feb 12, 2026
| model(**inputs) | ||
| else: | ||
| inputs = sample_inputs[0].to(device) | ||
| inputs = sample_inputs.to(device) |
Contributor
There was a problem hiding this comment.
Could you add a unit test related to this bug fix so that we could make sure future changes won't introduce such bugs again?
Contributor
There was a problem hiding this comment.
In addition, I would recommend separating this bug fix from the other change to maintain a clean change log.
| import torch | ||
| from torch.func import vmap | ||
| from tqdm import tqdm | ||
| import torch.nn.functional as F |
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
Summary
This PR fixes a dimension mismatch issue and enhances the TRAK method's usability by adding automatic loss/probability function support for common task types.
Changes
Fix dimension conflict in sample_inputs
dattri/dattri/algorithm/block_projected_if/core/compressor.pysample_inputs[0]had a dimension mismatch with model expectations, causing runtime errors.sample_inputsand model input requirements.Enhanced TRAK method with automatic function support
TRAKAttributorandAttributionTasktask_typeparameter supporting'image_classification'and'text_classification'valuestask_typeis specified, users no longer need to manually designloss_funcandcorrect_probability_functask_typeis not specifiedBenefits