Skip to content

adds quantized implementation of hard sigmoid#34607

Closed
vkuzo wants to merge 5 commits intogh/vkuzo/7/basefrom
gh/vkuzo/7/head
Closed

adds quantized implementation of hard sigmoid#34607
vkuzo wants to merge 5 commits intogh/vkuzo/7/basefrom
gh/vkuzo/7/head

Conversation

@vkuzo
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo commented Mar 11, 2020

Stack from ghstack:

Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp. Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D20480546

Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@vkuzo vkuzo requested a review from apaszke as a code owner March 11, 2020 20:00
vkuzo added a commit that referenced this pull request Mar 11, 2020
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: e19f098
Pull Request resolved: #34607
@vkuzo vkuzo self-assigned this Mar 11, 2020
@vkuzo vkuzo added the oncall: quantization Quantization support in PyTorch label Mar 11, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Mar 11, 2020

💊 CircleCI build failures summary and remediations

As of commit 5fee38c (more details on the Dr. CI page):


None of the build failures appear to be your fault 💚


  • 1/1 broken upstream at merge base ae0c88d since Mar 16

    Please rebase on the viable/strict branch (expand for instructions)

    If your commit is newer than viable/strict, you can try basing on an older, stable commit:

    git fetch https://github.com/pytorch/pytorch viable/strict
    git rebase --onto FETCH_HEAD $(git merge-base origin/master HEAD)
    

    If your commit is older than viable/strict:

    git fetch https://github.com/pytorch/pytorch viable/strict
    git rebase FETCH_HEAD
    

    Check out the recency history of this "viable master" tracking branch.


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

This comment has been revised 44 times.

Comment thread aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp Outdated
@supriyar
Copy link
Copy Markdown
Contributor

LGTM, do we have some perf numbers as well for this?
I wonder if it would be possible to get some benchmark numbers on mobile as well for the elementwise operators you've implemented so far. Vec256 wouldn't give any speedup on mobile and it would be nice to track what the perf is on mobile as well for future optimizations.

Comment thread aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp Outdated
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 12, 2020
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: d476af7
Pull Request resolved: #34607
@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Mar 12, 2020

LGTM, do we have some perf numbers as well for this?
I wonder if it would be possible to get some benchmark numbers on mobile as well for the elementwise operators you've implemented so far. Vec256 wouldn't give any speedup on mobile and it would be nice to track what the perf is on mobile as well for future optimizations.

sure thing, here is the output of the current benchmark: https://our.internmc.facebook.com/intern/paste/P127415136/

I will follow up offline on the best way to benchmark all of these things on mobile!

Copy link
Copy Markdown
Contributor

@supriyar supriyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the benchmarks! I usually also compare against float to see the speedup.
But looks good overall

Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 16, 2020
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 864c47a
Pull Request resolved: #34607
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D20480546](https://our.internmc.facebook.com/intern/diff/D20480546)

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 17, 2020
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 8a3fbbf
Pull Request resolved: #34607
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D20480546](https://our.internmc.facebook.com/intern/diff/D20480546)

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 17, 2020
Summary:

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 6ddd123
Pull Request resolved: #34607
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 58c5b6d.

@mrshenli
Copy link
Copy Markdown
Contributor

Looks like this PR breaks master:

Mar 18 00:56:58 ======================================================================
Mar 18 00:56:58 FAIL [0.974s]: test_qhardsigmoid (__main__.TestQuantizedOps)
Mar 18 00:56:58 ----------------------------------------------------------------------
Mar 18 00:56:58 Traceback (most recent call last):
Mar 18 00:56:58   File "test_quantized.py", line 244, in test_qhardsigmoid
Mar 18 00:56:58     elements=hu.floats(-1e3, 1e3, allow_nan=False, allow_infinity=False),
Mar 18 00:56:58   File "/var/lib/jenkins/.local/lib/python3.6/site-packages/hypothesis/core.py", line 1116, in wrapped_test
Mar 18 00:56:58     raise the_error_hypothesis_found
Mar 18 00:56:58   File "test_quantized.py", line 271, in test_qhardsigmoid
Mar 18 00:56:58     message="Hardsigmoid failed: {} vs. {}".format(qY, qY_hat))
Mar 18 00:56:58   File "/opt/conda/lib/python3.6/site-packages/torch/testing/_internal/common_utils.py", line 880, in assertEqual
Mar 18 00:56:58     exact_dtype=exact_dtype)
Mar 18 00:56:58   File "/opt/conda/lib/python3.6/site-packages/torch/testing/_internal/common_utils.py", line 882, in assertEqual
Mar 18 00:56:58     assertTensorsEqual(x, y)
Mar 18 00:56:58   File "/opt/conda/lib/python3.6/site-packages/torch/testing/_internal/common_utils.py", line 848, in assertTensorsEqual
Mar 18 00:56:58     self.assertLessEqual(max_err, prec, message)
Mar 18 00:56:58 AssertionError: tensor(1, dtype=torch.int32) not less than or equal to 1e-05 : Hardsigmoid failed: tensor([0.5000], size=(1,), dtype=torch.qint32,
Mar 18 00:56:58        quantization_scheme=torch.per_tensor_affine, scale=2.3283064365386963e-10,
Mar 18 00:56:58        zero_point=0) vs. tensor([-0.5000], size=(1,), dtype=torch.qint32,
Mar 18 00:56:58        quantization_scheme=torch.per_tensor_affine, scale=2.3283064365386963e-10,
Mar 18 00:56:58        zero_point=0)

e.g.:

https://app.circleci.com/pipelines/github/pytorch/pytorch/141312/workflows/9036f70f-a41d-4968-aedc-4cab6b4307f0/jobs/4849783
https://app.circleci.com/pipelines/github/pytorch/pytorch/141312/workflows/9036f70f-a41d-4968-aedc-4cab6b4307f0/jobs/4849602

@mrshenli
Copy link
Copy Markdown
Contributor

@vkuzo I am reverting this PR to fix test signals on master. Please resubmit with a fix. Thanks!

@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Mar 18, 2020

@vkuzo I am reverting this PR to fix test signals on master. Please resubmit with a fix. Thanks!

sorry about that, will do!

vkuzo added a commit that referenced this pull request Mar 18, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 18, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: d58ebb5
Pull Request resolved: #34959
vkuzo added a commit that referenced this pull request Mar 19, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D20514212](https://our.internmc.facebook.com/intern/diff/D20514212)

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 19, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 66b9504
Pull Request resolved: #34959
vkuzo added a commit that referenced this pull request Mar 19, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D20514212](https://our.internmc.facebook.com/intern/diff/D20514212)

[ghstack-poisoned]
vkuzo added a commit that referenced this pull request Mar 19, 2020
Summary:

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:

tests
benchmarks

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 6dcd01c
Pull Request resolved: #34959
facebook-github-bot pushed a commit that referenced this pull request Mar 19, 2020
Summary:
Pull Request resolved: #34959

Adds quantized implementation of hardsigmoid.

Original PR was #34607 and had to
be reverted for a test breakage, trying again.

Test Plan:
tests
benchmarks

Imported from OSS

Differential Revision: D20514212

fbshipit-source-id: cc7ae3b67757e2dde5c313c05ce60a0f2625d961
@facebook-github-bot facebook-github-bot deleted the gh/vkuzo/7/head branch March 21, 2020 14:17
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#34607

Adds quantized version of hardsigmoid activation.

Note: not implementing the _ and .out versions is
currently intended, because the implementation changes the scale and
zp and it's nice to not allow the user to specify scale
and zp.  Lmk if we should handle this differently.

Test Plan:
tests
benchmarks

Imported from OSS

Differential Revision: D20480546

fbshipit-source-id: 9febcb44afd920125ed2ca4900492f0b712078ea
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#34959

Adds quantized implementation of hardsigmoid.

Original PR was pytorch#34607 and had to
be reverted for a test breakage, trying again.

Test Plan:
tests
benchmarks

Imported from OSS

Differential Revision: D20514212

fbshipit-source-id: cc7ae3b67757e2dde5c313c05ce60a0f2625d961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: quantization Quantization support in PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants