RecBole icon indicating copy to clipboard operation
RecBole copied to clipboard

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

Open xxx08796 opened this issue 1 year ago • 1 comments

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 avatar Jan 08 '25 15:01 xxx08796

@xxx08796 Thank you for your attention! This fix is correct, we will fix it in our following updates.

Fotiligner avatar Feb 17 '25 13:02 Fotiligner