Skip to content

Adding quantized::linear function for pytorch mobile in c10#26135

Closed
supriyar wants to merge 13 commits intogh/supriyar/14/basefrom
gh/supriyar/14/head
Closed

Adding quantized::linear function for pytorch mobile in c10#26135
supriyar wants to merge 13 commits intogh/supriyar/14/basefrom
gh/supriyar/14/head

Conversation

@supriyar
Copy link
Copy Markdown
Contributor

@supriyar supriyar commented Sep 12, 2019

Stack from ghstack:

Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D17434885

Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
@pytorchbot pytorchbot added module: build Build system issues module: operators oncall: quantization Quantization support in PyTorch labels Sep 12, 2019
supriyar added a commit that referenced this pull request Sep 12, 2019
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 55e37d5
Pull Request resolved: #26135
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
Comment thread CMakeLists.txt Outdated
option(USE_OPENMP "Use OpenMP for parallel code" ON)
option(USE_PROF "Use profiling" OFF)
option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" ON)
option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" OFF)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we set it to OFF on line 300 instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am currently testing QNNPACK on pytorch server builds too (x86) using the python tests. If I turn off USE_QNNPACK only for mobile then I won't be able to test it on x86.
I think the main issue is that we didn't rename the kernels when we forked QNNPACK so at runtime it picks up kernels from third_party instead.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm... we'd need to fix it (rename the kernels), otherwise buck build will be broken too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah Ashkan has a PR out for this. #26238

Comment thread aten/src/ATen/native/quantized/cpu/qnnpack/src/conv-prepack.cc
Comment thread cmake/Dependencies.cmake Outdated
Comment thread CMakeLists.txt Outdated
option(USE_OPENMP "Use OpenMP for parallel code" ON)
option(USE_PROF "Use profiling" OFF)
option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" ON)
option(USE_QNNPACK "Use QNNPACK (quantized 8-bit operators)" OFF)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm... we'd need to fix it (rename the kernels), otherwise buck build will be broken too

Comment thread aten/src/ATen/native/quantized/cpu/qlinear.cpp Outdated
Comment thread aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp
}
#endif

inline uint8_t QuantizeUint8(float scale, int32_t zero_point, float value) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

btw, this seems to be similar to fbgemm implementation used in quantize_val. Can they be the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks similar, but that function calls fbgemm::Quantize function. I wanted to avoid calling fbgemm functions from pytorch mobile build because I don't think they will be built on mobile.

Comment thread test/test_quantized.py Outdated
use_channelwise=st.booleans())
def test_qlinear(self, batch_size, input_channels, output_channels,
use_bias, use_relu, use_multi_dim_input, use_channelwise):
torch.backends.quantized.engine = torch.fbgemm
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same comment that you'd need a context manager probably

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it'd be even better to lift it into the test's base class to make sure that we run tests agains both engines without duplicating the tests

Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
@supriyar supriyar requested a review from dzhulgakov September 15, 2019 00:31
Copy link
Copy Markdown
Collaborator

@dzhulgakov dzhulgakov left a comment

Choose a reason for hiding this comment

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

It looks good, but I'd fix the build mode issue before landing

Comment thread test/test_quantized.py Outdated
use_channelwise=st.booleans())
def test_qlinear(self, batch_size, input_channels, output_channels,
use_bias, use_relu, use_multi_dim_input, use_channelwise):
torch.backends.quantized.engine = torch.fbgemm
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it'd be even better to lift it into the test's base class to make sure that we run tests agains both engines without duplicating the tests

supriyar added a commit to supriyar/pytorch that referenced this pull request Sep 15, 2019
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 90b7304
Pull Request resolved: pytorch#26135
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:
@pytorchbot pytorchbot added the module: internals Related to internal abstractions in c10 and ATen label Sep 16, 2019
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:
This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack
Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in bb1efb3.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 18, 2019
Summary:
Pull Request resolved: pytorch/pytorch#26135

This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack

Imported from OSS

Differential Revision: D17434885

fbshipit-source-id: 084698026938f4529f61d12e86dfe82534ec73dd
@facebook-github-bot facebook-github-bot deleted the gh/supriyar/14/head branch October 28, 2019 22:20
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…26135)

Summary:
Pull Request resolved: pytorch#26135

This change adds the support to call QNNPACK using the refactored API for Linear operators (Fully Connected)
It also has certain cmake changes to enable builing and using pytorch_qnnpack inside aten
I have disabled USE_QNNPACK in CMakeLists.txt. Enabling it results in picking kernels from third_party/QNNPACK during runtime since the function names are the same.

Test Plan:
python test/test_quantized.py TestQNNPackOps.test_qlinear_qnnpack

Imported from OSS

Differential Revision: D17434885

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

Labels

Merged module: build Build system issues module: internals Related to internal abstractions in c10 and ATen oncall: quantization Quantization support in PyTorch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants