zalandoresearch / pytorch-ts

PyTorch based Probabilistic Time Series forecasting framework based on GluonTS backend
MIT License
1.21k stars 191 forks source link

nan values for the flow module, how to avoid, or mask out properly? #89

Open vamp-ire-tap opened 2 years ago

vamp-ire-tap commented 2 years ago

Hello,

thank you for making the code available, i have a problem with the following lines of code (https://github.com/zalandoresearch/pytorch-ts/blob/master/pts/modules/flows.py#L339):

    def log_prob(self, x, cond):
        u, sum_log_abs_det_jacobians = self.forward(x, cond)
        return torch.sum(self.base_dist.log_prob(u) + sum_log_abs_det_jacobians, dim=-1)

basically, the tensor u contains on very odd occasions: nan values, for which the base_dist.log_prob call fails. how can i resolve this issue according to best practices?

thank you

kashif commented 2 years ago

right so since the network itself in the coupling layers are simple linear layers, I suspect you get nans when there are nans in your input data... the x or potentially the cond... can you check if that is not the case?

vamp-ire-tap commented 2 years ago

thanks a lot for the swift response, the x and cond variables do not seem to have nans:

(Pdb) !np.argwhere(np.isnan(x.cpu().detach().numpy()))
array([], shape=(0, 3), dtype=int64)
(Pdb) !np.argwhere(np.isnan(cond.cpu().detach().numpy()))
array([], shape=(0, 3), dtype=int64)
(Pdb) 

however, the u tensor has several:

(Pdb) !np.argwhere(np.isnan(u.cpu().detach().numpy())).shape
(3700, 3)
pdenailly commented 1 year ago

Hello,

Having the same type of problem (nans for u) I was wondering if you had found a solution.

thank you !