From dfd2af6014970aba1f840d6fe3af0d796d596cb6 Mon Sep 17 00:00:00 2001 From: Jan-Matthis Date: Fri, 7 Aug 2020 17:30:21 +0200 Subject: [PATCH] Detach weights for SIR immediately to save memory --- sbi/inference/posteriors/base_posterior.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sbi/inference/posteriors/base_posterior.py b/sbi/inference/posteriors/base_posterior.py index d9d4d9c68..4bd5857df 100644 --- a/sbi/inference/posteriors/base_posterior.py +++ b/sbi/inference/posteriors/base_posterior.py @@ -326,11 +326,11 @@ def _sample_posterior_mcmc( ) log_weights = torch.cat( [ - potential_function(init_param_candidates[i, :]) + potential_function(init_param_candidates[i, :]).detach() for i in range(init_strategy_num_candidates) ] ) - probs = np.exp(log_weights.view(-1).detach().numpy().astype(np.float64)) + probs = np.exp(log_weights.view(-1).numpy().astype(np.float64)) probs[np.isnan(probs)] = 0.0 probs[np.isinf(probs)] = 0.0 probs /= probs.sum()