Hi,
I ran both your code samples with both python 2.7.13 and 3.6.5 with pytorch compiled from master. So this possibly has already been fixed in master.
I guess a temporary fix would be to use an if statement to check if "weights" is in the keys of batch, or make your dataloader always fill this field, even if it’s a a tensor full of 1s.