MCPcopy Index your code
hub / github.com/apache/tvm / test_layer_norm

Function test_layer_norm

tests/python/relax/test_codegen_cutlass.py:1107–1141  ·  view source on GitHub ↗
(data_shape, dtype, axes)

Source from the content-addressed store, hash-verified

1105 ],
1106)
1107def test_layer_norm(data_shape, dtype, axes):
1108 def get_mod(data_shape, dtype, axes):
1109 reduced_shape = [data_shape[axis] for axis in axes]
1110 with IRBuilder() as builder:
1111 with relax_builder.function():
1112 R.func_name("main")
1113 inp = R.arg("input", R.Tensor(data_shape, dtype))
1114 gamma = R.arg("gamma", R.Tensor(reduced_shape, dtype))
1115 beta = R.arg("beta", R.Tensor(reduced_shape, dtype))
1116
1117 with R.dataflow() as frame:
1118 output = R.emit(R.nn.layer_norm(inp, gamma, beta, axes))
1119 R.output(output)
1120
1121 R.func_ret_value(frame.output_vars[0])
1122
1123 func = builder.get()
1124 return tvm.IRModule({"main": func})
1125
1126 Module = get_mod(data_shape, dtype, axes)
1127 mod = partition_for_cutlass(Module)
1128
1129 if len(axes) != 1 or (axes[0] != -1 and axes[0] != len(data_shape) - 1):
1130 tvm.ir.assert_structural_equal(mod, Module)
1131 return
1132
1133 mod = relax.transform.RunCodegen()(mod)
1134
1135 inp = np.random.randn(*data_shape).astype(dtype)
1136 gamma = np.random.randn(data_shape[-1]).astype(dtype)
1137 beta = np.random.randn(data_shape[-1]).astype(dtype)
1138 out = build_and_run(mod, [inp, gamma, beta], "cuda")
1139 ref = build_and_run(Module, [inp, gamma, beta], "llvm")
1140
1141 tvm.testing.assert_allclose(out, ref, rtol=1e-2, atol=1e-2)
1142
1143
1144def test_attention_rewrite_fp16():

Callers

nothing calls this directly

Calls 4

partition_for_cutlassFunction · 0.90
get_modFunction · 0.70
build_and_runFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…