Browse Source

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

GitOrigin-RevId: 01ad51a222
release-1.2
Megvii Engine Team 4 years ago
parent
commit
b5ec83c53f
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      imperative/python/test/unit/autodiff/test_grad_manger.py

+ 18
- 0
imperative/python/test/unit/autodiff/test_grad_manger.py View File

@@ -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"
)


Loading…
Cancel
Save