Skip to content

Commit

Permalink
chore: refactor _local_predict for better performances (#171)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Andreux <[email protected]>
  • Loading branch information
mandreux-owkin authored Sep 21, 2023
1 parent 5ee6f3a commit 16d6c85
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions substrafl/algorithms/pytorch/torch_base_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ def _local_predict(self, predict_dataset: torch.utils.data.Dataset, predictions_

self._model.eval()

predictions = torch.Tensor([]).to(self._device)
with torch.inference_mode():
for x in predict_loader:
x = x.to(self._device)
predictions = torch.cat((predictions, self._model(x)), 0)
predictions = [self._model(x.to(self._device)) for x in predict_loader]
predictions = torch.cat(predictions, dim=0)

predictions = predictions.cpu().detach()
self._save_predictions(predictions, predictions_path)
Expand Down

0 comments on commit 16d6c85

Please sign in to comment.