1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-18 01:44:34 +08:00

Add torch.no_grad for evaluation

This commit is contained in:
D-X-Y
2021-03-12 02:46:04 +00:00
parent 67fbdafe76
commit db59713d36
5 changed files with 35 additions and 37 deletions

View File

@@ -195,12 +195,13 @@ class ALSTM(Model):
# feature[torch.isnan(feature)] = 0
label = data[:, -1, -1].to(self.device)
pred = self.ALSTM_model(feature.float())
loss = self.loss_fn(pred, label)
losses.append(loss.item())
with torch.no_grad():
pred = self.ALSTM_model(feature.float())
loss = self.loss_fn(pred, label)
losses.append(loss.item())
score = self.metric_fn(pred, label)
scores.append(score.item())
score = self.metric_fn(pred, label)
scores.append(score.item())
return np.mean(losses), np.mean(scores)