forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PyTorch Edge] Add Quantized Softmax Op (Naive Implementation) (pytor…
…ch#75017) Summary: Pull Request resolved: pytorch#75017 This version just does dequantize, fp32 softmax, quantize. Another version of actual quantized softmax using qnnpack will be added next Test Plan: From fbcode: ```buck test caffe2/test:quantization -- test_qsoftmax``` Benchmarking: See summary of D34996486 Reviewed By: kimishpatel Differential Revision: D34943147 fbshipit-source-id: 426a0780803597a21460139c67960891d6e9cc81 (cherry picked from commit 524eede)
- Loading branch information
1 parent
8b8f3e8
commit 8d7242a
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <ATen/ATen.h> | ||
#include <torch/library.h> | ||
|
||
namespace at { | ||
namespace native { | ||
|
||
namespace { | ||
|
||
Tensor qsoftmax( | ||
const Tensor& qx, | ||
const int64_t dim, | ||
const double output_scale, | ||
const int64_t output_zero_point) { | ||
Tensor rx = at::dequantize(qx); | ||
Tensor ry = at::softmax(rx, dim); | ||
return at::quantize_per_tensor( | ||
ry, output_scale, output_zero_point, qx.scalar_type()); | ||
} | ||
|
||
TORCH_LIBRARY_IMPL(quantized, QuantizedCPU, m) { | ||
m.impl(TORCH_SELECTIVE_NAME("quantized::softmax"), TORCH_FN(qsoftmax)); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace native | ||
} // namespace at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters