Getting error when evaluating JODIE model

rhum2: <p>Hello, I am trying to reproduce the code of Kumar’s JODIE model available on the following github <a href="https://github.com/srijankr/jodie" class="inline-onebox" rel="noopener nofollow ugc">GitHub - claws-lab/jodie: A PyTorch implementation of ACM SIGKDD 2019 paper "Predicting Dynamic Embedding Trajectory in Temporal Interaction Networks"</a> with pytorch version 1.7.1. Everything goes fine during training but for model evaluation I get the following error RuntimeError: Function ‘MseLossBackward’ returned nan values in its 0th output. the code used is the following:</p>
<blockquote>
<p>def evaluate(data, embedding_dim, state_change, train_proportion, model, optimizer, user_embeddings_dystat, item_embeddings_dystat, user_embeddings_timeseries, item_embeddings_timeseries):</p>
<p>torch.autograd.set_detect_anomaly(True)<br>
df = data.to_numpy()</p>
<p>[user2id, user_sequence_id, user_timediffs_sequence, user_previous_itemid_sequence,<br>
item2id, item_sequence_id, item_timediffs_sequence,<br>
timestamp_sequence, feature_sequence, y_true] = load_network(df)<br>
num_interactions = len(user_sequence_id)<br>
num_users = len(user2id)<br>
num_items = len(item2id) + 1<br>
num_features = len(feature_sequence[0])<br>
true_labels_ratio = len(y_true) / (1.0 + sum(y_true))<br>
print(“*** Network statistics: \n %d users\n %d items\n %d interactions\n %d %d true labels ***\n\n” % (num_users, num_items, num_interactions, sum(y_true), len(y_true)))</p>
<p>train_end_idx = validation_start_idx = int(num_interactions * train_proportion)<br>
test_start_idx = int(num_interactions * (train_proportion + 0.2))<br>
test_end_idx = int(num_interactions * (train_proportion + 0.4))</p>
<p>timespan = timestamp_sequence[-1] - timestamp_sequence[0]<br>
tbatch_timespan = timespan / 500</p>
<p>model = JODIE(num_features, num_users, num_items, embedding_dim)<br>
weight = torch.Tensor([1, true_labels_ratio])<br>
crossEntropyLoss = nn.CrossEntropyLoss(weight = weight)<br>
MSELoss = nn.MSELoss()</p>
<p>learning_rate = 1e-3<br>
optimizer = optim.Adam(model.parameters(), lr = learning_rate, weight_decay = 1e-5)</p>
<p>set_embeddings_training_end(user_embeddings_dystat, item_embeddings_dystat, user_embeddings_timeseries, item_embeddings_timeseries, user_sequence_id, item_sequence_id, train_end_idx)</p>
<p>item_embeddings = item_embeddings_dystat[:, :embedding_dim]<br>
item_embeddings = item_embeddings.clone()<br>
item_embeddings_static = item_embeddings_dystat[:, embedding_dim:]<br>
item_embeddings_static = item_embeddings_static.clone()</p>
<p>user_embeddings = user_embeddings_dystat[:, :embedding_dim]<br>
user_embeddings = user_embeddings.clone()<br>
user_embeddings_static = user_embeddings_dystat[:, embedding_dim:]<br>
user_embeddings_static = user_embeddings_static.clone()</p>
<p>validation_predicted_y = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
test_predicted_y = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
validation_true_y = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
test_true_y = <span class="chcklst-box fa fa-square-o fa-fw"></span></p>
<p>tbatch_start_time = None<br>
loss = 0</p>
<p>with trange(train_end_idx, test_end_idx) as progress_bar:<br>
for j in progress_bar:<br>
progress_bar.set_description(“%dth interaction for validation and testing” % j)</p>
<pre><code>  	userid = user_sequence_id[j]
  	itemid = item_sequence_id[j]
  	feature = feature_sequence[j]
  	user_timediff = user_timediffs_sequence[j]
  	item_timediff = item_timediffs_sequence[j]
  	timestamp = timestamp_sequence[j]

  	
  	if not tbatch_start_time:

  		tbatch_start_time = timestamp

  	itemid_previous = user_previous_itemid_sequence[j]
  	user_embedding_input = user_embeddings[torch.LongTensor([userid])]
  	user_embedding_static_input = user_embeddings_static[torch.LongTensor([userid])]
  	item_embedding_input = item_embeddings[torch.LongTensor([itemid])]
  	item_embedding_static_input = item_embeddings_static[torch.LongTensor([itemid])]
  	feature_tensor = Variable(torch.Tensor([feature])).unsqueeze(0)
  	user_timediffs_tensor = Variable(torch.Tensor([user_timediff])).unsqueeze(0)
  	item_timediffs_tensor = Variable(torch.Tensor([item_timediff])).unsqueeze(0)
  	item_embedding_previous = item_embeddings[torch.LongTensor([itemid_previous])]

  	user_projected_embedding = model.forward(user_embedding_input, item_embedding_previous, timediffs = user_timediffs_tensor, features = feature_tensor, select = "project")
  	user_item_embedding = torch.cat([user_projected_embedding, item_embedding_previous, item_embeddings_static[torch.LongTensor([itemid_previous])], user_embedding_static_input], dim = 1)

  	predicted_item_embedding = model.predicted_item_embedding(user_item_embedding)

  	loss = loss + MSELoss(predicted_item_embedding, torch.cat([item_embedding_input, item_embedding_static_input], dim = 1).clone())

  	user_embedding_output = model.forward(user_embedding_input, item_embedding_input, timediffs = user_timediffs_tensor, features = feature_tensor.reshape(1,-1), select = "user_update")
  	item_embedding_output = model.forward(user_embedding_input, item_embedding_input, timediffs = item_timediffs_tensor, features = feature_tensor.reshape(1,-1), select = "item_update")

  	item_embeddings[itemid, :] = item_embedding_output.squeeze(0)
  	user_embeddings[userid, :] = user_embedding_output.squeeze(0)
  	user_embeddings_timeseries[j, :] = user_embedding_output.squeeze(0)
  	item_embeddings_timeseries[j, :] = item_embedding_output.squeeze(0)

  	loss = loss + MSELoss(item_embedding_output, item_embedding_input.clone())
  	loss = loss + MSELoss(user_embedding_output, user_embedding_input.clone())


  	if state_change:
  		loss = loss + calculate_state_prediction_loss(model, [j], user_embeddings_timeseries, y_true, crossEntropyLoss)

  	if timestamp - tbatch_start_time &gt; tbatch_timespan:
  		print("ok")
  		tbatch_start_time = timestamp
  		loss.backward()
  		optimizer.step()
  		optimizer.zero_grad()

  		loss = 0
  		item_embeddings.detach_()
  		user_embeddings.detach_()
  		item_embeddings_timeseries.detach_()
  		user_embeddings_timeseries.detach_()

  	prob = model.predict_label(user_embedding_output)

  	if j &lt; test_start_idx:
  		validation_predicted_y.extend(prob.data.cpu().numpy())
  		validation_true_y.extend([y_true[j]])
  	else:
  		test_predicted_y.extend(prob.data.cpu().numpy())
  		test_true_y.extend([y_true[j]])
</code></pre>
<p>validation_predicted_y = np.array(validation_predicted_y)<br>
test_predicted_y = np.array(test_predicted_y)</p>
<p>performance_dict = dict()<br>
auc = roc_auc_score(validation_true_y, validation_predicted_y[:, 1])<br>
performance_dict[“validation”] = [auc]</p>
<p>auc = roc_auc_score(test_true_y, test_predicted_y[:, 1])<br>
performance_dict[“test”] = [auc]</p>
<p>return performance_dict</p>
</blockquote>
<p>Can you help me please</p>