(data_shape, dtype, axes)
| 1105 | ], |
| 1106 | ) |
| 1107 | def 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 | |
| 1144 | def test_attention_rewrite_fp16(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…