Fork自 MegEngine 天元 / MegEngine
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
import numpy as np import megengine as mge from megengine import autodiff as ad def test_attach_in_with_block(): a = mge.Parameter([1.0]) g = ad.GradManager() with g: b = a * 3 g.attach(b) c = b + 1 g.backward(c) assert int(b.grad.numpy()) == 1