提交 b5ec83c5 编写于 作者: M Megvii Engine Team

test(mge/autodiff): validate grad is set to None when no dependency

GitOrigin-RevId: 01ad51a2227999f932e803a755a81de62360f0a7
上级 577366a2
......@@ -92,6 +92,24 @@ def test_attach_temporary():
# gm.backward(y)
def test_no_dependency():
x = mge.tensor(3)
w = mge.Parameter(1.0)
w_no_dep = mge.Parameter(1.0)
gm = GradManager()
gm.attach(w)
gm.attach(w_no_dep)
with gm:
out1 = x * w
out2 = w_no_dep * out1
gm.backward(out1.sum())
assert w.grad is not None
assert w_no_dep.grad is None
@pytest.mark.skipif(
platform.system() == "Darwin", reason="do not imp GPU mode at macos now"
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册