This is likely because vs is constant:
a = torch.zeros(10, requires_grad=True)                                                                                                                                                                    
a.std().backward()                                                                                                                                                                                         
a.grad                                                                                                                                                                                                     

gives
tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])
What you could do is add a gradient hook and modify the gradient to replace the nan with 0 (using torch.where).
Best regards
Thomas