You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Quant model conv1x1 uses fallback codegen flow #8149
Can you clarify the difference? The _q prefix means it is executing the quantized variant of the operation. We do not execute the other variant as it is the floating point version.
Currently for the quant conv1x1 op, it is treated as just another convolution, which is yet to have a good codegen flow; however, it should be treated as matmul, same as in the floating point version, which IREE already has a better codegen path in place.
With quantized variant not being mapped to the naming matching functions, the codegen uses a fallback lowing pass, which generates a lot of repetition/inefficient inner loop ops. For example, following is the current codegen behavior for the conv1x1 in mobilenet_v1_0.25_quantized model
There are unfortunately unnecessary memory updates in c71c for the partial accumulation result. @MaheshRavishankar suggested this is a signal that the op is lowered with in the fallback path.
I think the conclusion was that even the quantized conv 1x1 ops should be converted to matmuls. Better codegen for convolution is being worked on, but for this case there is no reason to wait for that.
Enable --print-ir-after-all during iree-translate, I can see tosa.conv2d converted to linalg.quantized_matmul, but don't see IR change after the ConvertConv2D1x1ConvToMatmul pass. I am not sure if quantized_matmul is vectorized efficiently in this case.
I dont have the python stuff built to try this out easily. But if you think you can do that, this should get vectorized, but will have to see the IR to make sure.
I am not sure I understand why the change would be in python. The IR dump I provided above was from running iree-translate CLI with the .mlir as the text file input. At which point would python code being used?
That is the op definition of the linalg.quantized_matmul operation. That needs to define the ContractionOpInterface for it to get picked up by the vectorization path.
Activity
rsuderman commentedon Jan 21, 2022
Can you clarify the difference? The
_qprefix means it is executing the quantized variant of the operation. We do not execute the other variant as it is the floating point version.hcindyl commentedon Jan 21, 2022
Summary of the email discussion:
Currently for the quant conv1x1 op, it is treated as just another convolution, which is yet to have a good codegen flow; however, it should be treated as matmul, same as in the floating point version, which IREE already has a better codegen path in place.
With quantized variant not being mapped to the naming matching functions, the codegen uses a fallback lowing pass, which generates a lot of repetition/inefficient inner loop ops. For example, following is the current codegen behavior for the conv1x1 in mobilenet_v1_0.25_quantized model
There are unfortunately unnecessary memory updates in c71c for the partial accumulation result. @MaheshRavishankar suggested this is a signal that the op is lowered with in the fallback path.
MaheshRavishankar commentedon Jan 21, 2022
I think the conclusion was that even the quantized conv 1x1 ops should be converted to matmuls. Better codegen for convolution is being worked on, but for this case there is no reason to wait for that.
rsuderman commentedon Jan 22, 2022
Reopened until we can validate
rsuderman commentedon Jan 27, 2022
Verified it should be at head. If there is a memory regression keep me up to date.
hcindyl commentedon Feb 4, 2022
Use
candidate-20220128.31to build a very simple example of mlir as followingEnable
--print-ir-after-allduringiree-translate, I can seetosa.conv2dconverted tolinalg.quantized_matmul, but don't see IR change after theConvertConv2D1x1ConvToMatmulpass. I am not sure if quantized_matmul is vectorized efficiently in this case.build_conv1x1.txt.tar.gz
MaheshRavishankar commentedon Feb 4, 2022
No it is not. The quantized_matmul needs to have the contraction operation interface for it to get picked up for vectorization.
2 remaining items
MaheshRavishankar commentedon Feb 4, 2022
@rsuderman this is the change to add the contraction op interface upstream.
I dont have the python stuff built to try this out easily. But if you think you can do that, this should get vectorized, but will have to see the IR to make sure.
hcindyl commentedon Feb 4, 2022
I am not sure I understand why the change would be in python. The IR dump I provided above was from running
iree-translateCLI with the .mlir as the text file input. At which point would python code being used?MaheshRavishankar commentedon Feb 4, 2022
That is the op definition of the
linalg.quantized_matmuloperation. That needs to define theContractionOpInterfacefor it to get picked up by the vectorization path.bjacob commentedon Feb 15, 2022
Filed Issue #8330 for
quantized_matmultomatmullowering pattern.allieculp commentedon Jul 13, 2022
@not-jenni Can you help review and prioritize this on frontend rotation this week?
rsuderman commentedon Jul 14, 2022
#8330 is now merged which fixes this issue.