def test_backward_without_grad_zero_tensor(self) -> None: tensor = Tensor(1, requires_grad=True) tensor.backward() assert tensor.grad.tolist() == 1
def test_backward_without_grad(self) -> None: tensor = Tensor([1], requires_grad=True) with pytest.raises(RuntimeError): tensor.backward()