Skip to content

fix at::from_blob_quantized_per_tensor_affine strides calculation #79314

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

Conversation

yzyz
Copy link
Contributor

@yzyz yzyz commented Jun 10, 2022

Summary: There seems to be a off-by-one bug in at::from_blob_quantized_per_tensor_affine. For an input with sizes {N, C, H, W}, before strides would be calculated as {NCH, CH, H, 1}, now strides is calculated as {CHW, HW, W, 1}. The updated unit test catches this problem.

Test Plan:

buck test mode/dev-nosan //caffe2:quantized_test

before fix:

    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (15.632)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.004)
    ✗ Fail: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.002)
Test output:
> caffe2/aten/src/ATen/test/quantized_test.cpp:247
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0

stdout: Note: Google Test filter = TestQTensor.FromBlobQuantizedPerTensor
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TestQTensor
[ RUN      ] TestQTensor.FromBlobQuantizedPerTensor
caffe2/aten/src/ATen/test/quantized_test.cpp:247: Failure
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor (2 ms)
[----------] 1 test from TestQTensor (2 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor

 1 FAILED TEST

after fix:

    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (16.051)
    ✓ Pass: caffe2:quantized_test - TestQTensor.RoundingMode (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4dChannelsLast (0.217)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyPerchannelQuantized (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyQuantized (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerChannel (0.004)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4d (0.005)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.Item (0.002)
Summary
  Pass: 9
  ListingSuccess: 1

Differential Revision: D37061355

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jun 10, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

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

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D37061355

…torch#79314)

Summary:
Pull Request resolved: pytorch#79314

There seems to be a off-by-one bug in `at::from_blob_quantized_per_tensor_affine`. For an input with sizes {N, C, H, W}, before strides would be calculated as {NCH, CH, H, 1}, now strides is calculated as {CHW, HW, W, 1}. The updated unit test catches this problem.

Test Plan:
```
buck test mode/dev-nosan //caffe2:quantized_test
```

before fix:
```
    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (15.632)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.004)
    ✗ Fail: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.002)
Test output:
> caffe2/aten/src/ATen/test/quantized_test.cpp:247
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0

stdout: Note: Google Test filter = TestQTensor.FromBlobQuantizedPerTensor
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TestQTensor
[ RUN      ] TestQTensor.FromBlobQuantizedPerTensor
caffe2/aten/src/ATen/test/quantized_test.cpp:247: Failure
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor (2 ms)
[----------] 1 test from TestQTensor (2 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor

 1 FAILED TEST
```

after fix:
```
    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (16.051)
    ✓ Pass: caffe2:quantized_test - TestQTensor.RoundingMode (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4dChannelsLast (0.217)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyPerchannelQuantized (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyQuantized (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerChannel (0.004)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4d (0.005)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.Item (0.002)
Summary
  Pass: 9
  ListingSuccess: 1
```

Reviewed By: jerryzh168

Differential Revision: D37061355

fbshipit-source-id: 7ed77159192c2ce238905c2b3cebff3c0ef6898f
@yzyz yzyz force-pushed the export-D37061355 branch from 1cccaa0 to 9525d80 Compare June 15, 2022 02:17
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D37061355

@facebook-github-bot
Copy link
Contributor

@pytorchbot merge

(Initiating merge automatically since Phabricator Diff has merged)

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Contributor

Hey @yzyz.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit that referenced this pull request Jun 16, 2022
…9314)

Summary:
Pull Request resolved: #79314

There seems to be a off-by-one bug in `at::from_blob_quantized_per_tensor_affine`. For an input with sizes {N, C, H, W}, before strides would be calculated as {NCH, CH, H, 1}, now strides is calculated as {CHW, HW, W, 1}. The updated unit test catches this problem.

Test Plan:
```
buck test mode/dev-nosan //caffe2:quantized_test
```

before fix:
```
    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (15.632)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.004)
    ✗ Fail: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.002)
Test output:
> caffe2/aten/src/ATen/test/quantized_test.cpp:247
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0

stdout: Note: Google Test filter = TestQTensor.FromBlobQuantizedPerTensor
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TestQTensor
[ RUN      ] TestQTensor.FromBlobQuantizedPerTensor
caffe2/aten/src/ATen/test/quantized_test.cpp:247: Failure
Expected equality of these values:
  qtensor[h][w].item<float>()
    Which is: -0.5
  (custom_data[i] - zero_point) * scale
    Which is: 0
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor (2 ms)
[----------] 1 test from TestQTensor (2 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestQTensor.FromBlobQuantizedPerTensor

 1 FAILED TEST
```

after fix:
```
    ✓ ListingSuccess: caffe2:quantized_test : 9 tests discovered (16.051)
    ✓ Pass: caffe2:quantized_test - TestQTensor.RoundingMode (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4dChannelsLast (0.217)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantDequantAPIs (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyPerchannelQuantized (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.EmptyQuantized (0.002)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerChannel (0.004)
    ✓ Pass: caffe2:quantized_test - TestQTensor.QuantizePerChannel4d (0.005)
    ✓ Pass: caffe2:quantized_test - TestQTensor.FromBlobQuantizedPerTensor (0.003)
    ✓ Pass: caffe2:quantized_test - TestQTensor.Item (0.002)
Summary
  Pass: 9
  ListingSuccess: 1
```

Reviewed By: jerryzh168

Differential Revision: D37061355

fbshipit-source-id: c37b1f0459cfe948cdbafc9253701de9610ba0ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants