sam icon indicating copy to clipboard operation
sam copied to clipboard

RuntimeError: stack expects a non-empty TensorList

Open hphyhl opened this issue 3 years ago • 0 comments

def _grad_norm(self):
    shared_device = self.param_groups[0]["params"][0].device  # put everything on the same device, in case of model parallelism
    norm = torch.norm(
                torch.stack([
                    ((torch.abs(p) if group["adaptive"] else 1.0) * p.grad).norm(p=2).to(shared_device)
                    for group in self.param_groups for p in group["params"]
                    if p.grad is not None
                ]),
                p=2
           )
    return norm

hphyhl avatar Jul 22 '22 07:07 hphyhl