Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add softmax and layernorm #2750

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
å
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()