Skip to content

Add support for quantized LeakyReLU #1

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions backends/xnnpack/partition/xnnpack_partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ def __init__(self):
torch.nn.ReLU,
torch.nn.functional.relu,
torch.nn.functional.relu_,
torch.nn.functional.leaky_relu,
torch.nn.functional.leaky_relu_,
torch.nn.LeakyReLU,
]

# Modules which support dynamic quantization
Expand Down
41 changes: 41 additions & 0 deletions backends/xnnpack/test/test_xnnpack_quantized.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,47 @@ def test_xnnpack_qhardtanh(self):
example_inputs = (torch.randn(1, 1, 1),)
self.quantize_and_test_model(torch.nn.Hardtanh(), example_inputs)

def test_xnnpack_leaky_relu(self):
example_inputs = (torch.randn(1, 3, 3),)

class LeakyReLUModule(torch.nn.Module):
def __init__(self):
super().__init__()
self.leaky_relu_out_of_place = torch.nn.LeakyReLU(negative_slope=0.2)

def forward(self, x):
return self.leaky_relu_out_of_place(x)

self.quantize_and_test_model(LeakyReLUModule(), example_inputs)

def test_xnnpack_leaky_relu2(self):
example_inputs = (torch.randn(1, 3, 3),)

class LeakyReLUModule(torch.nn.Module):
def __init__(self):
super().__init__()
self.leaky_relu_in_place = torch.nn.LeakyReLU(
negative_slope=0.08, inplace=True
)

def forward(self, x):
return self.leaky_relu_in_place(x)

self.quantize_and_test_model(LeakyReLUModule(), example_inputs)

def test_xnnpack_leaky_relu3(self):
example_inputs = (torch.randn(1, 3, 3),)

class LeakyReLUModule(torch.nn.Module):
def __init__(self):
super().__init__()
self.leaky_relu_functional_default = torch.nn.functional.leaky_relu

def forward(self, x):
return self.leaky_relu_functional_default(x)

self.quantize_and_test_model(LeakyReLUModule(), example_inputs)

def test_xnnpack_qlinear(self):
in_size = 1
input_size = 3
Expand Down