Fix AttributeError in eval_collector for non-tensor metric values#2209
Open
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
Open
Fix AttributeError in eval_collector for non-tensor metric values#2209he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
Conversation
The `get_data_struct` method called `.cpu()` on every value in `_data_dict`, but non-accuracy metrics (AveragePopularity, GiniIndex, ShannonEntropy) store plain integers and Counter objects instead of tensors. This adds a type check so `.cpu()` is only called on torch.Tensor objects. Fixes RUCAIBox#2194 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
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.
Summary
get_data_struct()inCollectorcalls.cpu()on every value in_data_dict, but non-accuracy metrics (AveragePopularity,GiniIndex,ShannonEntropy) store plain integers andCounterobjectsisinstance(value, torch.Tensor)check before calling.cpu()Root Cause
The
data_collectmethod registers non-tensor values likedata.num_items(int),data.count_items(Counter), etc. Whenget_data_struct()iterates over all values and calls.cpu(), these non-tensor types raiseAttributeError: 'int' object has no attribute 'cpu'.Test plan
🤖 Generated with Claude Code