Skip to content

Commit

Permalink
Plt Support torch test, test=model
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeref996 committed Dec 30, 2024
1 parent 84eb2cf commit 6882db6
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 0 deletions.
2 changes: 2 additions & 0 deletions framework/e2e/PaddleLT_new/layerApicase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import layerApicase.perf_monitor
import layerApicase.nn_sublayer
import layerApicase.nn_extreme_size
import layerApicase.math_sublayer
import layerApicase.math_extreme_size
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的 .py 文件路径
py_files = glob.glob(os.path.join(current_dir, "*.py"))

# 动态导入所有 .py 文件
for py_file in py_files:
# 获取文件名(不含扩展名)
module_name = os.path.basename(py_file)[:-3]
# 导入模块
__import__('layerApicase.math_extreme_size.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
import paddle


class LayerCase(paddle.nn.Layer):
"""
case名称: abs_base
api简介: 求绝对值
"""

def __init__(self):
super(LayerCase, self).__init__()

def forward(self, x, ):
"""
forward
"""

paddle.seed(33)
np.random.seed(33)
out = paddle.abs(x, )
return out



def create_inputspec():
inputspec = (
paddle.static.InputSpec(shape=(-1, -1, -1, -1, -1), dtype=paddle.float32, stop_gradient=False),
)
return inputspec

def create_tensor_inputs():
"""
paddle tensor
"""
inputs = (paddle.to_tensor(-1 + (1 - -1) * np.random.random([1024, 256, 128, 100, 2]).astype('float32'), dtype='float32', stop_gradient=False), )
return inputs


def create_numpy_inputs():
"""
numpy array
"""
inputs = (-1 + (1 - -1) * np.random.random([1024, 256, 128, 100, 2]).astype('float32'), )
return inputs

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import numpy as np
import paddle


class LayerCase(paddle.nn.Layer):
"""
case名称: Conv2D_giant_size_class
api简介: 2维卷积
"""

def __init__(self):
super(LayerCase, self).__init__()
self.func = paddle.nn.Conv2D(kernel_size=[3, 3], in_channels=256, out_channels=1, )

def forward(self, data, ):
"""
forward
"""

paddle.seed(33)
np.random.seed(33)
out = self.func(data, )
return out



def create_inputspec():
inputspec = (
paddle.static.InputSpec(shape=(-1, 256, -1, -1), dtype=paddle.float32, stop_gradient=False),
)
return inputspec

def create_tensor_inputs():
"""
paddle tensor
"""
inputs = (paddle.to_tensor(-1 + (1 - -1) * np.random.random([1024, 256, 128, 200]).astype('float32'), dtype='float32', stop_gradient=False), )
return inputs


def create_numpy_inputs():
"""
numpy array
"""
inputs = (-1 + (1 - -1) * np.random.random([1024, 256, 128, 200]).astype('float32'), )
return inputs

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的 .py 文件路径
py_files = glob.glob(os.path.join(current_dir, "*.py"))

# 动态导入所有 .py 文件
for py_file in py_files:
# 获取文件名(不含扩展名)
module_name = os.path.basename(py_file)[:-3]
# 导入模块
__import__('layerApicase.nn_extreme_size.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的 .py 文件路径
py_files = glob.glob(os.path.join(current_dir, "*.py"))

# 动态导入所有 .py 文件
for py_file in py_files:
# 获取文件名(不含扩展名)
module_name = os.path.basename(py_file)[:-3]
# 导入模块
__import__('torch_case.layerApicase.math_extreme_size.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import torch
import torch.nn as nn


class LayerCase(nn.Module):
"""
case名称: abs_base
api简介: 求绝对值
"""

def __init__(self):
super(LayerCase, self).__init__()

def forward(self, x):
"""
forward
"""
torch.manual_seed(33)
np.random.seed(33)
out = torch.abs(x)
return out


def create_tensor_inputs():
"""
PyTorch tensor
"""
inputs = (torch.tensor((-1 + 2 * np.random.random([1024, 256, 128, 100, 2])).astype(np.float32), dtype=torch.float32, requires_grad=True), )
return inputs


def create_numpy_inputs():
"""
numpy array
"""
# 生成一个形状为[1024, 256, 128, 100, 2]的随机numpy数组,数据范围在[-1, 1)
inputs = ((-1 + 2 * np.random.random([1024, 256, 128, 100, 2])).astype('float32'),)
return inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import torch
import torch.nn as nn


class LayerCase(nn.Module):
"""
case名称: Conv2D_giant_size_class
api简介: 2维卷积
"""

def __init__(self):
super(LayerCase, self).__init__()
self.func = nn.Conv2d(in_channels=256, out_channels=1, kernel_size=3, stride=1, padding=1)

def forward(self, data):
"""
forward
"""
torch.manual_seed(33)
np.random.seed(33)
out = self.func(data)
return out


def create_tensor_inputs():
"""
PyTorch tensor
"""
inputs = (torch.tensor((-1 + 2 * np.random.random([1024, 256, 128, 200])).astype(np.float32), dtype=torch.float32, requires_grad=True), )
return inputs


def create_numpy_inputs():
"""
numpy array
"""
inputs = ((-1 + 2 * np.random.random([1024, 256, 128, 200])).astype('float32'),)
return inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import glob

# 获取当前文件所在目录
current_dir = os.path.dirname(__file__)

# 获取当前目录下所有的 .py 文件路径
py_files = glob.glob(os.path.join(current_dir, "*.py"))

# 动态导入所有 .py 文件
for py_file in py_files:
# 获取文件名(不含扩展名)
module_name = os.path.basename(py_file)[:-3]
# 导入模块
__import__('torch_case.layerApicase.nn_extreme_size.' + module_name, globals(), locals(), [])
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import torch
import torch.nn as nn


class LayerCase(nn.Module):
"""
case名称: AdaptiveAvgPool3D_8
api简介: 3维自适应池化
"""

def __init__(self):
super(LayerCase, self).__init__()
self.func = nn.AdaptiveAvgPool3d(output_size=(1, 1, 1))

def forward(self, data):
"""
forward
"""
torch.manual_seed(33)
np.random.seed(33)
out = self.func(data)
return out


def create_tensor_inputs():
"""
PyTorch tensor
"""
inputs = (torch.tensor(-10 + (10 - -10) * np.random.random([2, 3, 8, 32, 32]).astype('float32'), dtype=torch.float32, requires_grad=True), )
return inputs


def create_numpy_inputs():
"""
numpy array
"""
inputs = (-10 + (10 - -10) * np.random.random([2, 3, 8, 32, 32]).astype('float32'), )
return inputs

0 comments on commit 6882db6

Please sign in to comment.