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

FIX: optimize the update_attentive_A function in KGAT #597

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion recbole/model/knowledge_aware_recommender/kgat.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def update_attentive_A(self):
# Current PyTorch version does not support softmax on SparseCUDA, temporarily move to CPU to calculate softmax
A_in = torch.sparse.FloatTensor(indices, kg_score, self.matrix_size).cpu()
A_in = torch.sparse.softmax(A_in, dim=1).to(self.device)
self.A_in = copy.copy(A_in)
self.A_in = A_in

def predict(self, interaction):
user = interaction[self.USER_ID]
Expand Down
4 changes: 3 additions & 1 deletion recbole/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ def _train_epoch(self, train_data, epoch_idx, loss_func=None):
kg_total_loss = super()._train_epoch(train_data, epoch_idx, self.model.calculate_kg_loss)

# update A
self.model.update_attentive_A()
self.model.eval()
with torch.no_grad():
self.model.update_attentive_A()

return rs_total_loss, kg_total_loss

Expand Down