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
[quant] Add quantized Sigmoid module #45883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,3 +149,24 @@ def _get_name(self): | |
def from_float(cls, mod): | ||
scale, zero_point = mod.activation_post_process.calculate_qparams() | ||
return cls(float(scale), int(zero_point), mod.negative_slope, mod.inplace) | ||
|
||
class Sigmoid(torch.nn.Sigmoid): | ||
r"""This is the quantized equivalent of :class:`~torch.nn.LeakyReLU`. | ||
|
||
Args: | ||
scale: quantization scale of the output tensor | ||
zero_point: quantization zero point of the output tensor | ||
""" | ||
|
||
def __init__(self, output_scale: float, output_zero_point: int): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have default args? It is safe to assume those for this function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure, it's not likely that user is going to construct quantized model from quantized modules from scratch anyways, what is the benefit of having default args? |
||
super().__init__() | ||
self.output_scale = output_scale | ||
self.output_zero_point = output_zero_point | ||
|
||
def forward(self, input): | ||
return torch.ops.quantized.sigmoid(input, self.output_scale, self.output_zero_point) | ||
|
||
@classmethod | ||
def from_float(cls, mod): | ||
output_scale, output_zero_point = mod.activation_post_process.calculate_qparams() | ||
return cls(float(output_scale), int(output_zero_point)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs are off here, can we refer to sigmoid instead of leakyRelu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry, will fix in next PR