Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25308
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 138 PendingAs of commit 8f4a6b6 with merge base 78e83b9 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@apullin has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128386182. |
This PR needs a
|
…h#25308) Summary: `FuseQuantizedActivationPass` removes a ReLU, or a hardtanh with a 0 lower bound, that follows a conv or a linear. Since pytorch#21974 it also does this when the activation's output zero point is above qmin, and sets the following quantize op's qmin to the zero point, which keeps the quantized model clamping at 0. The TOSA lowering drops that clamp: `RewriteConvPass` lowers the conv's output to a RESCALE, which saturates only at the int8 range. So negative values passed the removed ReLU whenever its output zero point was above -128, which happens when the ReLU's output shares its qparams with negative values. For `torch.cat([y, torch.relu(conv(x))])` the TOSA graph was `CONV2D -> RESCALE (zero point -3) -> CONCAT`, without any clamp. The pass again fuses only activations whose output zero point is qmin, as before pytorch#21974, so the RESCALE's saturation is the clamp. Other ReLUs stay, and are lowered as clamps. The unit tests that expected fusion with a zero point above qmin now use a zero point of -128, or expect no fusion, and `test_relu_with_zero_point_above_qmin_tosa_INT` lowers `torch.cat([y, torch.relu(conv(x))])` for TOSA INT and compares the outputs. Differential Revision: D128386182
277048e to
f5282ca
Compare
|
Hi @apullin , For your model with the change in |
f5282ca to
0b6f937
Compare
…h#25308) Summary: `FuseQuantizedActivationPass` removes a ReLU, or a hardtanh with a 0 lower bound, that follows a conv or a linear. Since pytorch#21974 it also does this when the activation's output zero point is above `qmin`, and sets the following quantize op's `qmin` to the zero point, which keeps the quantized model clamping at 0. The TOSA lowering drops that clamp: `RewriteConvPass` lowers the conv's output to a `RESCALE`, which saturates only at the `int8` range. So negative values passed the removed ReLU whenever its output zero point was above -128, which happens when the ReLU's output shares its qparams with negative values. For `torch.cat([y, torch.relu(conv(x))])` the TOSA graph was `CONV2D -> RESCALE (zero point -3) -> CONCAT`, without any clamp. The pass again fuses only activations whose output zero point is `qmin`, as before pytorch#21974, so the `RESCALE`'s saturation is the clamp. `CheckProperQuantization` now checks whether a `conv` or `linear` and its following 0-lower-bound activation are quantized together (`_is_quantized_activation`) separately from whether the activation can be erased (`_is_fuseable_quantized_activation`), so unfused pairs stay delegated instead of falling back to CPU, and `FuseQuantizedActivationPass` inserts the intermediate `Q -> DQ` pair on the quantized producer when the activation stays so both `conv` and `linear` lower cleanly with `CLAMP`. Differential Revision: D128386182
|
@gggekov Cleaned up now. And rebased. This was pulled out of a much larger stack bugfind/fix stack where the test passed
Updated and rebased the PR to:
|
|
@claude review this |
|
Claude finished @gggekov's task in 3m 43s —— View job The fix looks correct and nothing blocks merging, but test coverage has gaps: int16 (a16w8) models now always take the new CLAMP path and no test covers it, and the new end-to-end test should be parametrized. Detailed reviewPR Review: #25308SummaryThe PR stops Code Quality
Testing
Performance
RecommendationNeeds Discussion. The fix is correct. Before merging, please answer the RESCALE question, since it decides whether the extra |
There was a problem hiding this comment.
Should you not amend the copyright(make the year 2025-2026 and perhaps include the copyright of your company) ?
There was a problem hiding this comment.
Also, could you rename the file name to sth test_conv_relu_branch ?
There was a problem hiding this comment.
Could you parameterize these so that in case of failure, you see which model fails ?
gggekov
left a comment
There was a problem hiding this comment.
Could you also add a test case when quantizing the conv2d to 16x8 as per claude's suggestion ?
…h#25308) Summary: Pull Request resolved: pytorch#25308 `FuseQuantizedActivationPass` removes a ReLU, or a hardtanh with a 0 lower bound, that follows a conv or a linear. Since pytorch#21974 it also does this when the activation's output zero point is above `qmin`, and sets the following quantize op's `qmin` to the zero point, which keeps the quantized model clamping at 0. The TOSA lowering drops that clamp: `RewriteConvPass` lowers the conv's output to a `RESCALE`, which saturates only at the `int8` range. So negative values passed the removed ReLU whenever its output zero point was above -128, which happens when the ReLU's output shares its qparams with negative values. For `torch.cat([y, torch.relu(conv(x))])` the TOSA graph was `CONV2D -> RESCALE (zero point -3) -> CONCAT`, without any clamp. The pass again fuses only activations whose output zero point is `qmin`, as before pytorch#21974, so the `RESCALE`'s saturation is the clamp. `CheckProperQuantization` now checks whether a `conv` or `linear` and its following 0-lower-bound activation are quantized together (`_is_quantized_activation`) separately from whether the activation can be erased (`_is_fuseable_quantized_activation`), so unfused pairs stay delegated instead of falling back to CPU, and `FuseQuantizedActivationPass` inserts the intermediate `Q -> DQ` pair on the quantized producer when the activation stays so both `conv` and `linear` lower cleanly with `CLAMP`. Differential Revision: D128386182
0b6f937 to
8f4a6b6
Compare
Summary:
FuseQuantizedActivationPassremoves a ReLU, or a hardtanh with a 0 lower bound, that follows a conv or a linear. Since #21974 it also does this when the activation's output zero point is aboveqmin, and sets the following quantize op'sqminto the zero point, which keeps the quantized model clamping at 0. The TOSA lowering drops that clamp:RewriteConvPasslowers the conv's output to aRESCALE, which saturates only at theint8range. So negative values passed the removed ReLU whenever its output zero point was above -128, which happens when the ReLU's output shares its qparams with negative values. Fortorch.cat([y, torch.relu(conv(x))])the TOSA graph wasCONV2D -> RESCALE (zero point -3) -> CONCAT, without any clamp.The pass again fuses only activations whose output zero point is
qmin, as before #21974, so theRESCALE's saturation is the clamp.CheckProperQuantizationnow checks whether aconvorlinearand its following 0-lower-bound activation are quantized together (_is_quantized_activation) separately from whether the activation can be erased (_is_fuseable_quantized_activation), so unfused pairs stay delegated instead of falling back to CPU, andFuseQuantizedActivationPassinserts the intermediateQ -> DQpair on the quantized producer when the activation stays so bothconvandlinearlower cleanly withCLAMP.Differential Revision: D128386182