Skip to content

fake_quant: make qparams shape consistent#38587

Closed
vkuzo wants to merge 4 commits intogh/vkuzo/66/basefrom
gh/vkuzo/66/head
Closed

fake_quant: make qparams shape consistent#38587
vkuzo wants to merge 4 commits intogh/vkuzo/66/basefrom
gh/vkuzo/66/head

Conversation

@vkuzo
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo commented May 15, 2020

Stack from ghstack:

Summary:

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent. This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D21605532

Summary:

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: c090edd
Pull Request resolved: #38587
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented May 16, 2020

💊 CI failures summary and remediations

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


  • 4/4 failures possibly* introduced in this PR
    • 1/4 non-CircleCI failure(s)

🕵️ 2 new failures recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build pytorch_windows_vs2019_py36_cpu_build (1/2)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C3861: 'runtime_error': identifier not found

de -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmI8Spmdm.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmI8Spmdm.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

\include -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmFP16.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmFP16.cc 
FAILED: third_party/fbgemm/CMakeFiles/fbgemm_generic.dir/src/FbgemmFP16.cc.obj  
\include -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmFP16.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmFP16.cc 
..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C2039: 'runtime_error': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): note: see declaration of 'std'
..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C3861: 'runtime_error': identifier not found
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

nclude -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\PackAMatrix.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\PackAMatrix.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

 -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\EmbeddingSpMDM.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\EmbeddingSpMDM.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

See CircleCI build pytorch_windows_vs2019_py36_cuda10.1_build (2/2)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C3861: 'runtime_error': identifier not found

..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmFloat16Convert.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmFloat16Convert.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

\include -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmFP16.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmFP16.cc 
FAILED: third_party/fbgemm/CMakeFiles/fbgemm_generic.dir/src/FbgemmFP16.cc.obj  
\include -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\FbgemmFP16.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\FbgemmFP16.cc 
..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C2039: 'runtime_error': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\vector(24): note: see declaration of 'std'
..\third_party\fbgemm\include\fbgemm/FbgemmFP16.h(100): error C3861: 'runtime_error': identifier not found
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

nclude -I..\cmake\..\third_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\PackAMatrix.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\PackAMatrix.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

rd_party\googletest\googlemock\include -I..\cmake\..\third_party\googletest\googletest\include -I..\third_party\protobuf\src -Iwin_tmp\mkl\include /DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental /wd4244 /wd4267 /wd4305 /wd4309 /MD /O2 /Ob2 /DNDEBUG /w /bigobj   -std:c++14 /showIncludes /Fothird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\src\PackAWithQuantRowOffset.cc.obj /Fdthird_party\fbgemm\CMakeFiles\fbgemm_generic.dir\ /FS -c ..\third_party\fbgemm\src\PackAWithQuantRowOffset.cc 
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

1 failure not recognized by patterns:

Job Step Action
CircleCI binary_windows_libtorch_3_7_cpu_release_build Build 🔁 rerun

ci.pytorch.org: 1 failed


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 or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 16 times.

Summary:

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
Summary:

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: a8244db
Pull Request resolved: #38587
x = torch.rand(4, 4, 4, 4)
m(x)
scale_shape_after = m.linear.activation_post_process.scale.shape
zero_point_shape_after = m.linear.activation_post_process.zero_point.shape
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.

Looks good, should we also check for per-channel quant (i.e the weights?)

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.

just double checked, we expect the per-channel params to change (for C > 1), so it did not have the issue solved by this diff

Summary:

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

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

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:

```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: eab594c
Pull Request resolved: #38587
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in 8d8b586.

@facebook-github-bot facebook-github-bot deleted the gh/vkuzo/66/head branch May 25, 2020 14:16
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#38587

Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.

This diff makes the shape stay consistent.  This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.

Test Plan:
```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```

Imported from OSS

Differential Revision: D21605532

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants