From d0c179e372e9fccb5dfe5612a6d44bf53a3d6a1d Mon Sep 17 00:00:00 2001 From: HertzHan Date: Tue, 2 Apr 2024 12:27:57 +0000 Subject: [PATCH] add softmax and layernorm --- .../perf_monitor/manual_subgraph/__init__.py | 7 +- .../layernorm_fp32_shape_1_13_4096.py | 70 +++++++++++++++++++ ...rm.py => rms_norm_fp32_shape_1_13_4096.py} | 0 .../{rope.py => rope_fp32_shape_1_13_4096.py} | 0 .../softmax_fp32_shape_1_13_4096.py | 67 ++++++++++++++++++ 5 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/layernorm_fp32_shape_1_13_4096.py rename framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/{rms_norm.py => rms_norm_fp32_shape_1_13_4096.py} (100%) rename framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/{rope.py => rope_fp32_shape_1_13_4096.py} (100%) create mode 100644 framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/softmax_fp32_shape_1_13_4096.py diff --git a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/__init__.py b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/__init__.py index 04e6d51796..db8038c4b2 100644 --- a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/__init__.py +++ b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/__init__.py @@ -1,3 +1,6 @@ -import layercase.perf_monitor.manual_subgraph.rms_norm -import layercase.perf_monitor.manual_subgraph.rope +import layercase.perf_monitor.manual_subgraph.rms_norm_fp32_shape_1_13_4096 +import layercase.perf_monitor.manual_subgraph.rope_fp32_shape_1_13_4096 +import layercase.perf_monitor.manual_subgraph.layernorm_fp32_shape_1_13_4096 +import layercase.perf_monitor.manual_subgraph.softmax_fp32_shape_1_13_4096 # import layercase.perf_monitor.manual_subgraph.utils +å \ No newline at end of file diff --git a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/layernorm_fp32_shape_1_13_4096.py b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/layernorm_fp32_shape_1_13_4096.py new file mode 100644 index 0000000000..e83287f4c6 --- /dev/null +++ b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/layernorm_fp32_shape_1_13_4096.py @@ -0,0 +1,70 @@ +# FLAGS_pir_apply_shape_optimization_pass=0 FLAGS_enable_pir_api=1 +# FLAGS_prim_enable_dynamic=true FLAGS_prim_all=true +# FLAGS_cinn_new_group_scheduler=1 FLAGS_group_schedule_tiling_first=1 FLAGS_cinn_bucket_compile=True +# FLAGS_cinn_compile_with_nvrtc=True FLAGS_nvrtc_compile_to_cubin=True +# FLAGS_support_reduce_stride_read=1 + +import unittest +import numpy as np +# import utils + +import paddle + +class LayerCase(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.variance_epsilon = 1e-6 + def forward(self, x, weight, bias): + out = paddle.nn.functional.layer_norm(x, x.shape[-1], weight, bias, self.variance_epsilon) + return out + +def create_paddle_inputs(): + shape = [1, 13, 4096] + x = paddle.uniform(shape, dtype="float32", min=-0.5, max=0.5) + x.stop_gradient = False + weight = paddle.ones(shape=[shape[-1]], dtype="float32") + weight.stop_gradient = False + bias = paddle.ones(shape=[shape[-1]], dtype="float32") + bias.stop_gradient = False + inputs = (x, weight,bias) + return inputs + + +# class PaddleLayernormSubGraph(paddle.nn.Layer): +# def __init__(self): +# super().__init__() +# self.variance_epsilon = 1e-6 +# def forward(self, x, weight, bias): +# out = paddle.nn.functional.layer_norm(x, x.shape[-1], weight, bias, self.variance_epsilon) +# return out + + +# class TestRMSNormSubGraph(unittest.TestCase): +# def setUp(self): +# paddle.seed(2022) +# self.prepare_data() + +# def prepare_data(self): +# self.x, self.weight, self.bias = create_paddle_inputs() + +# def train(self, use_cinn): +# if use_cinn: +# net = LayerCase() +# else: +# net = PaddleLayernormSubGraph() +# net.eval() +# net = utils.apply_to_static(net, use_cinn) +# for i in range(10000): +# out = net(self.x, self.weight, self.bias) +# return out + +# def test_train(self): +# cinn_out = self.train(use_cinn=True) +# dy_out = self.train(use_cinn=False) +# np.testing.assert_allclose( +# cinn_out.numpy(), dy_out.numpy(), atol=1e-6, rtol=1e-6 +# ) + + +# if __name__ == '__main__': +# unittest.main() diff --git a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rms_norm.py b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rms_norm_fp32_shape_1_13_4096.py similarity index 100% rename from framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rms_norm.py rename to framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rms_norm_fp32_shape_1_13_4096.py diff --git a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rope.py b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rope_fp32_shape_1_13_4096.py similarity index 100% rename from framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rope.py rename to framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/rope_fp32_shape_1_13_4096.py diff --git a/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/softmax_fp32_shape_1_13_4096.py b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/softmax_fp32_shape_1_13_4096.py new file mode 100644 index 0000000000..6692e14c39 --- /dev/null +++ b/framework/e2e/PaddleLT_new/layercase/perf_monitor/manual_subgraph/softmax_fp32_shape_1_13_4096.py @@ -0,0 +1,67 @@ +'''test softmax subgraph ''' +# FLAGS_pir_apply_shape_optimization_pass=0 FLAGS_enable_pir_api=1 +# FLAGS_prim_enable_dynamic=true FLAGS_prim_all=true +# FLAGS_cinn_new_group_scheduler=1 FLAGS_group_schedule_tiling_first=1 FLAGS_cinn_bucket_compile=True +# FLAGS_cinn_compile_with_nvrtc=True FLAGS_nvrtc_compile_to_cubin=True +# FLAGS_support_reduce_stride_read=1 + +import unittest +import numpy as np +# import utils + +import paddle + +class LayerCase(paddle.nn.Layer): + '''this is the softmax layercase''' + def __init__(self): + super().__init__() + + def forward(self, x, axis=-1): + output = paddle.nn.functional.softmax(x, axis = axis) + return output + +def create_paddle_inputs(): + shape = [1, 13, 4096] + x = paddle.uniform(shape, dtype="float32", min=-0.5, max=0.5) + x.stop_gradient = False + return x + + +# class PaddleSoftmaxSubGraphNet(paddle.nn.Layer): +# def __init__(self): +# super().__init__() +# self.fn = paddle.nn.functional.softmax + +# def forward(self, x, axis=-1): +# out = self.fn(x, axis=axis) +# return out + + +# class TestSoftmaxSubGraph(unittest.TestCase): +# def setUp(self): +# paddle.seed(2022) +# self.prepare_data() + +# def prepare_data(self): +# self.x = create_paddle_inputs() + +# def train(self, use_cinn): +# if use_cinn: +# net = LayerCase() +# else: +# net = PaddleSoftmaxSubGraphNet() +# net.eval() +# net = utils.apply_to_static(net, use_cinn) +# for i in range(10000): +# out = net(self.x) +# return out + +# def test_train(self): +# cinn_out = self.train(use_cinn=True) +# dy_out = self.train(use_cinn=False) +# np.testing.assert_allclose( +# cinn_out.numpy(), dy_out.numpy(), atol=1e-6, rtol=1e-6 +# ) + +# if __name__ == '__main__': +# unittest.main()