Skip to content
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

Ignoring Gemm -> Q/Dq -> Softmax in GemmToQLinearMatMul transform #1343

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/sparseml/exporters/transforms/gemm_to_qlinearmatmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

from onnx import ModelProto, helper, numpy_helper

from sparseml.exporters.transforms.onnx_transform import OnnxTransform
Expand All @@ -31,15 +29,14 @@

__all__ = ["GemmToQLinearMatMul"]

_LOGGER = logging.getLogger(__name__)


class GemmToQLinearMatMul(OnnxTransform):
"""
Transforms Gemm nodes to QLinearMatMul.

NOTE: Does not match if the structure is
`Gemm -> QuantizeLinear -> DequantizeLinear -> Gemm`
1. `Gemm -> QuantizeLinear -> DequantizeLinear -> Gemm`
2. `Gemm -> QuantizeLinear -> DequantizeLinear -> Softmax`

Transforms
```
Expand Down Expand Up @@ -93,7 +90,10 @@ def transform(self, model: ModelProto) -> ModelProto:
output_dequant = match.children[0][1]
if output_dequant is not None:
output_dequant_child = graph.get_node_single_child(output_dequant)
if output_dequant_child and output_dequant_child.op_type == "Gemm":
if output_dequant_child and output_dequant_child.op_type in {
"Gemm",
"Softmax",
corey-nm marked this conversation as resolved.
Show resolved Hide resolved
}:
# output quant is not a QDQ block for the current Gemm Node but,
# the input QDQ block for a new Gemm block this Gemm should be
# skipped and processed by _convert_quantizable_gemm_no_activations
Expand Down