Run script 1: RuntimeError: found negative index -4745092176981434354 for dim 0
Run script 2: RuntimeError: size is inconsistent with indices: for dim 0, size is 29 but found index 140147970303920
which means n2n_idxes and n2n_vals can contain any value including Infs, NaNs etc.
The error is thus expected, so make sure you are properly initializing the tensors before trying to create the sparse tensor.
I would generally recommend to use the factory method, such as torch.randn, torch.randint etc. instead of the explicit constructors for a dtype.