Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛BUG] Error using metric GiniIndex: AttributeError: 'int' object has no attribute 'cpu' #2131

Open
xxx08796 opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@xxx08796
Copy link

xxx08796 commented Jan 8, 2025

I was using the metrics below
metrics: ["Recall", "Hit", 'ShannonEntropy', 'GiniIndex']
topk: [20, 50, 100]

But got this error in collector.py:

line 227, in get_data_struct
self.data_struct._data_dict[key] = self.data_struct._data_dict[key].cpu()
AttributeError: 'int' object has no attribute 'cpu'

I found that it was caused when key=data.num_items, yielding that an int cannot be executed by .cpu()
so I changed the following codes:

def get_data_struct(self):
"""Get all the evaluation resource that been collected.
And reset some of outdated resource.
"""
for key in self.data_struct._data_dict:
self.data_struct._data_dict[key] = self.data_struct._data_dict[key].cpu()
returned_struct = copy.deepcopy(self.data_struct)
for key in ["rec.topk", "rec.meanrank", "rec.score", "rec.items", "data.label"]:
if key in self.data_struct:
del self.data_struct[key]
return returned_struct

into:

def get_data_struct(self):
"""Get all the evaluation resource that been collected.
And reset some of outdated resource.
"""
for key in self.data_struct._data_dict:
try:
self.data_struct._data_dict[key] = self.data_struct._data_dict[key].cpu()
except AttributeError:
pass
returned_struct = copy.deepcopy(self.data_struct)
for key in ["rec.topk", "rec.meanrank", "rec.score", "rec.items", "data.label"]:
if key in self.data_struct:
del self.data_struct[key]
return returned_struct

Is this a correct fix? Thankyou for the attention!

@xxx08796 xxx08796 added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant