def forward(self,inputs,entryidslist,exitidslist): device = self.lt.weight.device…
- User
def forward(self,inputs,entry_ids_list,exit_ids_list): device = self.lt.weight.device entry_ids_list = torch.tensor(entry_ids_list, dtype=torch.long, device = device) exit_ids_list = torch.tensor(exit_ids_list, dtype=torch.long, device = device) list_entry = self.lt.weight[entry_ids_list] # (city_size, dim) list_exit = self.lt.weight[exit_ids_list] # (city_size, dim) dist_sum = self.distance(list_entry, list_exit) # (city_size, 1)
e = self.lt(inputs) # (batch_size, len([pos_u, pos_v, neg_v]), dim) with torch.no_grad(): e = self.manifold.normalize(e) o = e.narrow(1,1,e.size(1)-1) # (batch_size, len([pos_u, pos_v, neg_v]) - 1, dim) s = e.narrow(1,0,1).expand_as(o) # (batch_size, len([pos_u, pos_v, neg_v]) - 1, dim) ans = self.distance(s,o) # (batch_size, len([pos_u, pos_v, neg_v]) - 1, 1) 我能不能把这里面的self.distance调用两次变为一次(dist_sum = self.distance(list_entry, list_exit) # (city_size, 1);ans = self.distance(s,o) # (batch_size, len([pos_u, pos_v, neg_v]) - 1, 1)),这样会不会加速? - Assistant
To determine if you can replace the two calls to with a single call, we need to understand the context and the operations being performed by these calls.