def test_dependencies(self) -> None: t1 = Tensor(1, requires_grad=True) with t1.no_grad(): t2 = t1 + 1 assert not t2.requires_grad assert t1 not in [dependency.tensor for dependency in t2.depends_on]
def test_requires_grad_resets_after_exception(self) -> None: tensor = Tensor(1, requires_grad=True) try: with tensor.no_grad(): raise Exception() except Exception: pass assert tensor.requires_grad
def test_requires_grad_resets(self) -> None: tensor = Tensor(1, requires_grad=True) with tensor.no_grad(): pass assert tensor.requires_grad
def test_requires_grad_false_in_context_manager(self) -> None: tensor = Tensor(1, requires_grad=True) with tensor.no_grad(): assert not tensor.requires_grad