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

[feat] add some GB ops #1361

Open
wants to merge 20 commits into
base: main
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
249 changes: 245 additions & 4 deletions diopi_test/python/configs/diopi_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,197 @@


diopi_configs = {
'has_inf': dict(
name=["isinf"],
interface=["torch"],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ['input'],
"shape": ((), (1024,), (2, 4096), (64, 28, 28), (32, 64, 112, 112), (64, 3, 7, 28, 28), (0,), (256, 0), (8, 0, 128)),
"dtype": [np.float16, np.float32, np.float64, np.int16, np.int32, np.int64, np.uint8, np.int8],
},
],
),
),

'trunc': dict(
name=["trunc"],
interface=["torch"],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ['input'],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

'round': dict(
name=["round"],
interface=["torch"],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ['input'],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

'round': dict(
name=["hardsigmoid"],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ['input'],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

'elu': dict(
name=["elu"],
atol=1e-3,
rtol=1e-4,
para=dict(
alpha=[0.234, 4.8, -10, 1.0],
),
tensor_para=dict(
args=[
{
"ins": ["input"],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

'prelu': dict(
name=["prelu"],
atol=1e-3,
rtol=1e-4,
dtype=[np.float32, np.float16, np.float64],
tensor_para=dict(
args=[
{
"ins": ["input"],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
},
{
"ins": ["weight"],
"shape": ((16,), (64,), (96,), (1,)),
},
],
),
),

'selu': dict(
name=["selu"],
dtype=[np.float32, np.float16, np.float64],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ["input"],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
},
],
),
),

'softplus': dict(
name=["softplus"],
atol=1e-3,
rtol=1e-4,
para=dict(
beta=[0.234, 4.8, -10, 1.0],
threshold=[0.234, 4.8, -10, 1.0]
),
tensor_para=dict(
args=[
{
"ins": ["input"],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

'softsign': dict(
name=["softsign"],
atol=1e-3,
rtol=1e-4,
tensor_para=dict(
args=[
{
"ins": ["input"],
"shape": ((2, 16, 32, 56, 56), (2, 64, 32, 32), (2, 96, 28), (2, 16)),
"dtype": [np.float32, np.float16, np.float64],
},
],
),
),

"batch_norm_GB": dict(
name=["batch_norm_GB"],
interface=['CustomizedTest'],
dtype=[np.float32, np.float16, np.float64],
atol=1e-2,
rtol=1e-2,
atol_half=1e-1,
rtol_half=1e-2,
para=dict(
training=[True, True, True],
momentum=[0.01, 0.01, 0.01],
axis=[0, 1, 2],
eps=[1e-4, 1e-4, 1e-4],
),
tensor_para=dict(
args=[
{
"ins": ["input"],
"requires_grad": [True],
"shape": ((2, 64, 32, 32),(2, 64, 32, 32),(2, 64, 32, 32)),
"gen_fn": "Genfunc.randn",
},
{
"ins": ["running_mean"],
"shape": ((2,), (64,), (32,)),
"gen_fn": "Genfunc.zeros",
},
{
"ins": ["running_var"],
"shape": ((2,), (64,), (32,)),
"gen_fn": "Genfunc.ones",
},
{
"ins": ["weight", "bias"],
"requires_grad": [True],
"shape": ((2,), (64,), (32,)),
"gen_fn": "Genfunc.randn",
},
]
),
),

# FIXME batch_norm输入0size的张量报错
'batch_norm': dict(
name=["batch_norm"],
Expand Down Expand Up @@ -507,17 +698,34 @@
args=[
{
"ins": ['input'],
"requires_grad": [True],
"shape": ((), (1024,), (2, 4096), (64, 28, 28),
(32, 64, 112, 112), (64, 3, 7, 28, 28),
(0,), (256, 0), (8, 0, 128)),
"dtype": [np.float16, np.float32, np.float64,
np.int16, np.int32, np.int64,
np.uint8, np.int8],
"dtype": [np.float16, np.float32, np.float64],
"gen_fn": 'Genfunc.randn',
},
],
),
),

'erf': dict(
name=['erf'],
interface=['torch'],
dtype=[np.float16, np.float32, np.float64],
tensor_para=dict(
gen_fn='Genfunc.randn',
args=[
{
"ins": ['input'],
"requires_grad": [True],
"shape": ((), (1, ), (1024,), (364800, 4), (2, 128, 3072),
(256, 128, 3, 3),
(2, 31, 512, 6, 40), (0,), (16, 0)),
},
],
),
),

'relu_no_contiguous': dict(
name=["relu"],
Expand Down Expand Up @@ -4902,6 +5110,8 @@
name=["dropout"],
no_output_ref=True,
is_inplace=True,
atol=1e-3,
rtol=1e-3,
para=dict(
p=[0.5, 0, 0.1, 0.4],
training=[True, True, True, False]
Expand All @@ -4911,7 +5121,7 @@
{
"ins": ['input'],
"shape": ((2, 4096), (32, 49, 256), (2, 16, 64, 64), (1, 2304, 1, 1, 1)),
"dtype": [np.float16, np.float32, np.float64],
"dtype": [np.float32, np.float64],
"gen_fn": 'Genfunc.positive',
},
],
Expand Down Expand Up @@ -6996,6 +7206,37 @@
]
),
),

'group_norm_GB': dict(
name=['group_norm_GB'],
interface=['CustomizedTest'],
atol=1e-4,
rtol=1e-5,
para=dict(
num_groups=[32, 4, 5, 1],
eps=[1e-05, 1e-05, 1e-05, 1e-05],
reduced_axes = [[2, 3], [1, 3], [0, 3], [2, 3]],
channel_axis = [1, 2, 1, 0]
),
tensor_para=dict(
args=[
{
"ins": ["input"],
"requires_grad": [True],
"shape": ((2, 256, 7, 10), (2, 256, 12, 12),
(12, 15, 8, 9),(3, 6, 9, 0)),
"dtype": [np.float32, np.float64, np.float16],
},
{
"ins": ["weight", "bias"],
"requires_grad": [True],
"shape": ((256,), (12,),
(15,), (3,)),
"dtype": [np.float32, np.float64, np.float16],
},
]
),
),

'unique': dict(
name=['unique'],
Expand Down
56 changes: 56 additions & 0 deletions diopi_test/python/conformance/customized_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,59 @@ def pool3d(input, kernel_size, stride, padding, dilation, ceil_mode, count_inclu
def layer_normGB(input, weight, bias, eps, normalized_shape):
return torch.nn.functional.layer_norm(input=input, weight=weight, bias=bias, eps=eps, normalized_shape=normalized_shape)

def batch_norm_GB(input, running_mean, running_var, weight, bias, training=False, momentum=0.1, eps=1e-05, axis=1):
dim = input.dim()
dims = list(range(dim))
dims.remove(axis)
dims.insert(1, axis)
permuted_input = input.permute(dims)
out = torch.nn.functional.batch_norm(
permuted_input,
running_mean,
running_var,
weight=weight,
bias=bias,
training=training,
momentum=momentum,
eps=eps,
)
out = out.permute(dims)
return out

def group_norm_GB(input, num_groups, weight=None, bias=None, eps=1e-05, reduced_axes=[2, 3], channel_axis=1):

input_dims = list(input.size())
reduced_axes_set = set(reduced_axes)
dims = []
non_reduced_dims = []

for i, size in enumerate(input_dims):
if i == channel_axis:
continue
elif i in reduced_axes_set:
continue
else:
non_reduced_dims.append(i)
N = 1
for i in non_reduced_dims:
N = N * input.size(i)
HxW = 1
for i in reduced_axes:
HxW = HxW * input.size(i)
C = input.size(channel_axis)
dims = non_reduced_dims + [channel_axis] + reduced_axes
permuted_input = input.permute(dims)
reshaped_input = permuted_input.reshape([N, C, HxW, 1]).contiguous()
out = torch.nn.functional.group_norm(
reshaped_input,
num_groups,
weight=weight,
bias=bias,
eps=eps
)

reversed_order = [0]*len(dims)
for i in range(1, len(dims)):
reversed_order[dims[i]] = i
return out.reshape(permuted_input.shape).permute(reversed_order)

Loading