Skip to content
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
13 changes: 9 additions & 4 deletions benchmarks/NPUKernelBench/level3/10_ConvTranspose2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()

def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, bias=True) -> torch.Tensor:
def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, bias=True, seed=0) -> torch.Tensor:
"""
Applies transpose 2D convolution to the input tensor.

Expand All @@ -22,11 +22,15 @@ def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, strid
stride (int or tuple, optional): Stride of the convolution. Default: 1.
padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0.
bias (bool, optional): If True, adds a learnable bias to the output. Default: True.
seed (int, optional): RNG seed for deterministic conv weight init. Required so
ref Model.forward and candidate ModelNew.forward produce IDENTICAL random
weights when invoked back-to-back inside one verification case. Default: 0.

Returns:
torch.Tensor: Output tensor after performing nn.ConvTranspose2d.
"""
conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias=bias)
torch.manual_seed(seed)
conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, bias=bias).to(x.device)
return conv(x)


Expand Down Expand Up @@ -57,8 +61,9 @@ def get_input_groups():
stride = attr_inputs.get("stride", 1)
padding = attr_inputs.get("padding", 0)
bias = attr_inputs.get("bias", True)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, bias])
seed = attr_inputs.get("seed", 0)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, bias, seed])
return input_groups


Expand Down
15 changes: 11 additions & 4 deletions benchmarks/NPUKernelBench/level3/6_ConvStandard1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()

def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True) -> torch.Tensor:
def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, seed=0) -> torch.Tensor:
"""
Applies standard 1D convolution to the input tensor.

Expand All @@ -24,11 +24,17 @@ def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, strid
dilation (int or tuple, optional): Spacing between kernel elements. Default: 1.
groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1.
bias (bool, optional): If True, adds a learnable bias to the output. Default: True.
seed (int, optional): RNG seed used to initialize conv weights deterministically.
Required so that ref Model.forward and candidate ModelNew.forward produce
IDENTICAL random weights when the verification harness invokes both
back-to-back inside one test case. Without this, RNG advances between the
two calls and ref ≠ cand by construction. Default: 0.

Returns:
torch.Tensor: Output tensor after performing nn.Conv1d.
"""
conv = nn.Conv1d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias)
torch.manual_seed(seed)
conv = nn.Conv1d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias).to(x.device)
return conv(x)


Expand Down Expand Up @@ -61,8 +67,9 @@ def get_input_groups():
dilation = attr_inputs.get("dilation", 1)
groups = attr_inputs.get("groups", 1)
bias = attr_inputs.get("bias", True)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias])
seed = attr_inputs.get("seed", 0)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, seed])
return input_groups


Expand Down
13 changes: 9 additions & 4 deletions benchmarks/NPUKernelBench/level3/7_ConvStandard2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()

def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True) -> torch.Tensor:
def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, seed=0) -> torch.Tensor:
"""
Applies standard 2D convolution to the input tensor.

Expand All @@ -24,11 +24,15 @@ def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, strid
dilation (int or tuple, optional): Spacing between kernel elements. Default: 1.
groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1.
bias (bool, optional): If True, adds a learnable bias to the output. Default: True.
seed (int, optional): RNG seed for deterministic conv weight init. Required so
ref Model.forward and candidate ModelNew.forward produce IDENTICAL random
weights when invoked back-to-back inside one verification case. Default: 0.

Returns:
torch.Tensor: Output tensor after performing nn.Conv2d.
"""
conv = nn.Conv2d(in_channels, out_channels, (kernel_size, kernel_size), stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias)
torch.manual_seed(seed)
conv = nn.Conv2d(in_channels, out_channels, (kernel_size, kernel_size), stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias).to(x.device)
return conv(x)


Expand Down Expand Up @@ -61,8 +65,9 @@ def get_input_groups():
dilation = attr_inputs.get("dilation", 1)
groups = attr_inputs.get("groups", 1)
bias = attr_inputs.get("bias", True)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias])
seed = attr_inputs.get("seed", 0)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, seed])
return input_groups


Expand Down
13 changes: 9 additions & 4 deletions benchmarks/NPUKernelBench/level3/8_ConvStandard3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()

def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True) -> torch.Tensor:
def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, seed=0) -> torch.Tensor:
"""
Applies standard 3D convolution to the input tensor.

Expand All @@ -24,11 +24,15 @@ def forward(self, x: torch.Tensor, in_channels, out_channels, kernel_size, strid
dilation (int or tuple, optional): Spacing between kernel elements. Default: 1.
groups (int, optional): Number of blocked connections from input channels to output channels. Default: 1.
bias (bool, optional): If True, adds a learnable bias to the output. Default: True.
seed (int, optional): RNG seed for deterministic conv weight init. Required so
ref Model.forward and candidate ModelNew.forward produce IDENTICAL random
weights when invoked back-to-back inside one verification case. Default: 0.

Returns:
torch.Tensor: Output tensor after performing nn.Conv3d.
"""
conv = nn.Conv3d(in_channels, out_channels, (kernel_size, kernel_size, 1), stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias)
torch.manual_seed(seed)
conv = nn.Conv3d(in_channels, out_channels, (kernel_size, kernel_size, 1), stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias).to(x.device)
return conv(x)


Expand Down Expand Up @@ -61,8 +65,9 @@ def get_input_groups():
dilation = attr_inputs.get("dilation", 1)
groups = attr_inputs.get("groups", 1)
bias = attr_inputs.get("bias", True)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias])
seed = attr_inputs.get("seed", 0)

input_groups.append([x, in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias, seed])
return input_groups


Expand Down
13 changes: 9 additions & 4 deletions benchmarks/NPUKernelBench/level3/9_ConvDepthwise2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()

def forward(self, x: torch.Tensor, in_channels, kernel_size, stride=1, padding=0, bias=True) -> torch.Tensor:
def forward(self, x: torch.Tensor, in_channels, kernel_size, stride=1, padding=0, bias=True, seed=0) -> torch.Tensor:
"""
Applies depthwise 2D convolution to the input tensor.

Expand All @@ -21,11 +21,15 @@ def forward(self, x: torch.Tensor, in_channels, kernel_size, stride=1, padding=0
stride (int or tuple, optional): Stride of the convolution. Default: 1.
padding (int or tuple, optional): Zero-padding added to both sides of the input. Default: 0.
bias (bool, optional): If True, adds a learnable bias to the output. Default: True.
seed (int, optional): RNG seed for deterministic conv weight init. Required so
ref Model.forward and candidate ModelNew.forward produce IDENTICAL random
weights when invoked back-to-back inside one verification case. Default: 0.

Returns:
torch.Tensor: Output tensor of shape (batch, in_channels, height, width) after performing depthwise nn.Conv2d. Depthwise convolution processes each input channel independently, so output channels equal input channels.
"""
conv = nn.Conv2d(in_channels, in_channels, kernel_size=(kernel_size, kernel_size), stride=stride, padding=padding, groups=in_channels, bias=bias)
torch.manual_seed(seed)
conv = nn.Conv2d(in_channels, in_channels, kernel_size=(kernel_size, kernel_size), stride=stride, padding=padding, groups=in_channels, bias=bias).to(x.device)
return conv(x)


Expand Down Expand Up @@ -55,8 +59,9 @@ def get_input_groups():
stride = attr_inputs.get("stride", 1)
padding = attr_inputs.get("padding", 0)
bias = attr_inputs.get("bias", True)

input_groups.append([x, in_channels, kernel_size, stride, padding, bias])
seed = attr_inputs.get("seed", 0)

input_groups.append([x, in_channels, kernel_size, stride, padding, bias, seed])
return input_groups


Expand Down