Skip to content

Fix AttributeError in eval_collector for non-tensor metric values#2209

Open
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
he-yufeng:fix/eval-collector-cpu-error
Open

Fix AttributeError in eval_collector for non-tensor metric values#2209
he-yufeng wants to merge 1 commit intoRUCAIBox:masterfrom
he-yufeng:fix/eval-collector-cpu-error

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

Root Cause

The data_collect method registers non-tensor values like data.num_items (int), data.count_items (Counter), etc. When get_data_struct() iterates over all values and calls .cpu(), these non-tensor types raise AttributeError: 'int' object has no attribute 'cpu'.

Test plan

  • Verify existing tests pass
  • Test with metrics that collect non-tensor values (AveragePopularity, GiniIndex, ShannonEntropy)

🤖 Generated with Claude Code

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>
@he-yufeng
Copy link
Copy Markdown
Author

Bump — both #2209 and #2210 have been sitting for 3 weeks. Let me know if there's anything to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛BUG] AttributeError in eval_collector when using non-accuracy metrics like AveragePopularity

1 participant