MCPcopy Create free account
hub / github.com/apache/tvm / _test_optimizer

Function _test_optimizer

tests/python/relax/test_training_optimizer_numeric.py:68–79  ·  view source on GitHub ↗
(target, dev, np_func, opt_type, *args, **kwargs)

Source from the content-addressed store, hash-verified

66
67@tvm.testing.parametrize_targets("llvm")
68def _test_optimizer(target, dev, np_func, opt_type, *args, **kwargs):
69 x = relax.Var("x", R.Tensor((3, 3), "float32"))
70 y = relax.Var("y", R.Tensor((3,), "float32"))
71 opt = opt_type(*args, **kwargs).init([x, y])
72 mod = IRModule.from_expr(opt.get_function().with_attr("global_symbol", "main"))
73 tvm_func = _legalize_and_build(mod, target, dev)["main"]
74
75 param_arr = [np.random.rand(3, 3).astype(np.float32), np.random.rand(3).astype(np.float32)]
76 grad_arr = [np.random.rand(3, 3).astype(np.float32), np.random.rand(3).astype(np.float32)]
77 state_arr = _tvm_to_numpy(opt.state)
78
79 _assert_run_result_same(tvm_func, np_func, [param_arr, grad_arr, state_arr])
80
81
82lr, weight_decay = tvm.testing.parameters(

Callers 3

test_sgdFunction · 0.85
test_momentum_sgdFunction · 0.85
test_adamFunction · 0.85

Calls 9

_assert_run_result_sameFunction · 0.85
TensorMethod · 0.80
from_exprMethod · 0.80
_legalize_and_buildFunction · 0.70
_tvm_to_numpyFunction · 0.70
initMethod · 0.45
with_attrMethod · 0.45
get_functionMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…