def test_vif_loss_computes_grad_for_zeros_tensors() -> None: x = torch.zeros(4, 3, 256, 256, requires_grad=True) y = torch.zeros(4, 3, 256, 256) loss_value = VIFLoss()(x, y) loss_value.backward() assert x.grad is not None, NONE_GRAD_ERR_MSG
def test_vif_loss_computes_grad(x, y, device: str) -> None: x.requires_grad_() loss_value = VIFLoss()(x.to(device), y.to(device)) loss_value.backward() assert x.grad is not None, NONE_GRAD_ERR_MSG
def test_vif_loss_computes_grad(prediction: torch.Tensor, target: torch.Tensor, device: str) -> None: prediction.requires_grad_() loss_value = VIFLoss()(prediction.to(device), target.to(device)) loss_value.backward() assert prediction.grad is not None, NONE_GRAD_ERR_MSG
def test_vif_loss_computes_grad_for_zeros_tensors() -> None: prediction = torch.zeros(4, 3, 256, 256, requires_grad=True) target = torch.zeros(4, 3, 256, 256) loss_value = VIFLoss()(prediction, target) loss_value.backward() assert prediction.grad is not None, NONE_GRAD_ERR_MSG
def test_vif_loss_computes_grad_on_gpu(prediction: torch.Tensor, target: torch.Tensor) -> None: prediction.requires_grad_() loss_value = VIFLoss()(prediction.cuda(), target.cuda()) loss_value.backward() assert prediction.grad is not None, NONE_GRAD_ERR_MSG