Skip to content

[mkldnn][14/N] Port ideep int8 quantized convolution op into ATen - #202622

Closed
frost-intel wants to merge 7 commits into
pytorch:mainfrom
frost-intel:ideep-removal/14-port-quantized-conv
Closed

frost-intel wants to merge 7 commits into
pytorch:mainfrom
frost-intel:ideep-removal/14-port-quantized-conv

Conversation

@frost-intel

@frost-intel frost-intel commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Linked issue or supporting maintainer

Part of #154444

BC-breaking?

No

Summary (human written only)

Ports quantized convolution ops from ideep to ATen. Verbose logs form ONEDNN_VERBOSE were used to verify exact matching behavior before/after this change.

Depends on #202611

Fake stack

Agent details (if applicable)

Developed with assistance from Claude Opus 5.5.

Part of #154444. Depends on #202611.

Ports the int8 convolution entry points that quantized/cpu/qconv.cpp uses from ideep (ideep::convolution_forward) into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp} (namespace at::native::mkldnn). The port is line-for-line and changes no behavior: it still takes ideep::tensor / ideep::attr_t and uses ideep's engine, stream and primitive cache.

Ported

Public (detail/Conv.h), each with ideep's comments:

  • convolution_forward_prepare: ideep's int8 prepare (with bias, without the is_channels_last argument).
  • convolution_forward_compute<reorder_src, reorder_weight>(const convolution_forward_params&, ...): compute with pre-prepared params. Explicitly instantiated for <false, false>.
  • convolution_forward_compute<reorder_src, reorder_weight>(src, weights, bias, ..., scales, zero points, ...): ideep's int8 2-in-1 compute. qconv uses it when its primitive cache misses. Explicitly instantiated for <true, true>. ideep's comment on this function says "without bias", but it takes a bias tensor; the comment is kept verbatim.

File-local (detail/Conv.cpp):

  • do_prepare<with_bias>: ideep's int8 overload.

These reuse the int8 prepare_parameters and the scales/zero-points compute_dispatch from #202611, and get_primitive_desc / do_compute from #201224.

Type change

  • convolution_forward_params, already ported, moves unchanged from Conv.cpp's anonymous namespace into Conv.h. OnednnUtils.h now defines using ConvParams = at::native::mkldnn::convolution_forward_params;. qconv only reads params.pd, and stores and copies the struct in ConvPrimitiveCache, which works the same with the moved struct.

Call sites switched

  • quantized/cpu/qconv.cpp, in PackedConvWeightsOnednn::apply_impl:
    • prepare on the cache fill
    • compute<false, false>(params, ...) on a cache hit
    • the int8 2-in-1 compute on a cache miss
  • quantized/cpu/qconv.cpp, in _quantized_convolution_onednn: prepare / compute<false, false>. These sit in the #else of IDEEP_PREREQ(3, 1, 0, 0), which is never compiled with oneDNN 3.x; they are switched for consistency.

The ideep::engine::cpu_engine() argument is dropped from each call; it equals the default.

Still on ideep: quantized deconvolution in qconv.cpp (next PR), and t_store().clear() in IDeepRegistration.cpp.

Dropped

  • The engine parameters, as in the earlier ports.
  • In the 2-in-1 compute: ideep computes a local is_channels_last and never uses it (it passes true to compute_dispatch). The unused local is removed; it fails -Werror=unused-variable builds outside ideep's system-header include.

Testing

oneDNN verbose logs (ONEDNN_VERBOSE=1, timings stripped, sorted counts) are identical before and after:

  • quantization/core/test_quantized_op.py -k "(qconv or conv_transpose or qconvtranspose) and not fp8 and not cudnn" with PYTORCH_HYPOTHESIS_PROFILE=pytorch_ci (derandomized; identical across repeated baseline runs): 675 distinct lines. These tests call prepare and compute(params) 232 times each.
  • A probe that reuses one prepacked weight with new input scales and shapes, to exercise the cache-miss 2-in-1 compute: logs identical, outputs bitwise equal.
  • quantization/core/test_quantized_op.py -k "qconv and pt2e and not fp8": 257 distinct lines.
  • test_mkldnn.py plus test_freezing.py -k mkldnn: 6,572 distinct lines.

(test/jit/test_freezing.py was later deleted upstream by #203621. The final A/B comparison of the whole series against main, described in #204808, re-checks these paths without it.)

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01

@pytorch-bot pytorch-bot Bot added module: cpu CPU specific problem (e.g., perf, algorithm) release notes: quantization release notes category labels Oct 29, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/202622

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Unclassified Failure

As of commit 3d50b6c with merge base 780bf8e (image):

NEW FAILURE - The following job has failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Part of pytorch#154444.

Replace ideep type aliases with the oneDNN (or std) types they name.
Each is a plain `using` in ideep, so this is a pure spelling change
with no effect on generated code. It removes about a third of the
remaining ideep references from ATen CPU code.
Part of pytorch#154444. Move ideep::eltwise_forward/backward into aten.
Switch all CPU callers (relu, sigmoid, tanh, gelu, scalar mul,
dense GELU, JIT frozen scalar mul). Line-for-line port.
Part of pytorch#154444. Depends on pytorch#201055.

Port the floating-point convolution forward, backward-data and
backward-weights operators ATen uses from ideep into
aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}. The port is
line-for-line, still takes ideep::tensor/attr_t, and shares ideep's
primitive cache, so behavior is unchanged.

Switch the call sites in mkldnn/Conv.cpp, ConvPrepack.cpp,
MKLDNNConversions.cpp and quantized/cpu/qconv_prepack.cpp
(expected_weights_desc only). Quantized prepare/compute and transposed
convolution remain on ideep for now.

Drop code ATen never reaches: use_gemm, unused overloads/parameters,
backward_weights' diff_weight_type, and the fixed algorithm parameter on
backward. Remove an unused variable and fix sign-compare loop indices
that surface outside ideep's system-header include.
Keep only the fp32 forward port (compute_v3, compute_binary,
expected_weights_desc and their helpers) to stay under the PR size limit.
Backward data/weights and compute_v2 with its int8 prepare_parameters /
compute_dispatch path move to separate PRs; their call sites in
mkldnn/Conv.cpp and ConvPrepack.cpp go back to ideep until those land.
Part of pytorch#154444. Depends on pytorch#201224.

Port ideep's deprecated convolution_forward::compute_v2 (with and
without bias) and the code it routes through, the scale/zero-point
compute_dispatch and the int8 conv_deconv_utils::prepare_parameters,
into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}. The port is
line-for-line, still takes ideep::tensor/attr_t, and shares ideep's
primitive cache, so behavior is unchanged.

Switch the two compute_v2 calls in mkldnn/ConvPrepack.cpp. Drop the
algorithm, prop_kind, lowp_kind and engine parameters ATen never passes,
and an unused weights_zero_point local.
Move the fp32 and int8 prepare_parameters overloads out of Conv.cpp's
anonymous namespace and declare both in Conv.h. The transposed
convolution port reuses them from Deconv.cpp; with only the fp32
overload at namespace scope, the int8 one in the anonymous namespace
hides it and the fp32 calls fail to compile.
Part of pytorch#154444. Depends on pytorch#202611.

Port the int8 convolution entry points qconv uses into
aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}: convolution_forward::
prepare (int8, with bias), compute with pre-prepared params, the int8
2-in-1 compute used on a primitive-cache miss, and the int8 do_prepare
they share. The port is line-for-line, still takes ideep::tensor/attr_t,
and shares ideep's primitive cache, so behavior is unchanged.

Move the ported convolution_forward_params into Conv.h and point
OnednnUtils.h's ConvParams at it. Switch the calls in qconv.cpp, dropping
the engine argument (always cpu_engine()). Drop an unused is_channels_last
local in the 2-in-1 compute that ideep computes but never reads.
@frost-intel
frost-intel force-pushed the ideep-removal/14-port-quantized-conv branch from e0d0af2 to 3d50b6c Compare November 13, 2026 20:13
pytorchmergebot pushed a commit that referenced this pull request Nov 19, 2026
…1053)

## Linked issue or supporting maintainer
Part of #154444

## BC-breaking?
No

## Summary (human written only)
See #154444 for ideep removal discussion.
Replace ideep type aliases with the oneDNN or std types they name. Each is a plain `using` in ideep, so this is a pure spelling change with no effect on generated code. It removes about a third of the remaining ideep references from ATen CPU code.

#### Fake Stack
* #201052
* -> #201053
* Port ops:
* #201055
* #201059
* #201062
* #201080
* #201083
* #201126
* #201194
* #201224
* #201229
* #202547
* #202611
* #202622
* #203645
* #204617
* #204615
* Port classes and utils:
* #204801
* #204805
* #204806
* #204807
* Final removal:
* #204808

## Agent details (if applicable)

Developed with assistance from Claude Opus 5.5
Summary:
> Replace ideep type aliases with the oneDNN (or std) types they name:
> data_type, dims, format_tag/tag, prop_kind, algorithm, scale_t,
> zero_point_t and exec_args. Each is a plain `using` in ideep, so this is
> a pure spelling change with no effect on generated code. It removes
> about a third of the remaining ideep references from ATen CPU code
> without touching any ideep-specific behavior.

Pull Request resolved: #201053
Approved by: https://github.com/albanD, https://github.com/malfet
pytorchmergebot pushed a commit that referenced this pull request Nov 20, 2026
## Linked issue or supporting maintainer
Part of #154444

## BC-breaking?
No

## Summary (human written only)
Ports floating-point conv **forward** operators from ideep.  Only ops called within ATen are ported over. Backward and quantized ops are left for a follow-up PR

Ports are line-for-line and do not change any behavior.

## Agent details (if applicable)
Developed with assistance from Claude Opus 5.5.

> Ports the floating-point convolution **forward** operators that ATen uses from ideep (`ideep::convolution_forward`) into `aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}` (namespace `at::native::mkldnn`). The port is line-for-line and changes no behavior: it still takes `ideep::tensor` / `ideep::attr_t` and uses ideep's engine, stream and primitive cache.
>
> To stay under the PR size limit, convolution is split across three PRs:
> - **This PR:** fp32 forward.
> - **#201229, backward:** `convolution_backward_data` / `convolution_backward_weights`, in `detail/Conv.{h,cpp}`.
> - **#202611, `compute_v2`:** ideep's deprecated `compute_v2` and the int8 `prepare_parameters` / `compute_dispatch` it routes through. Used only by `ConvPrepack.cpp`. Stacked on this PR.
>
> ### Ported
> Public (`detail/Conv.h`), each with ideep's comment:
> - `convolution_forward_compute_v3`: with and without bias.
> - `convolution_forward_compute_binary<reorder_src, reorder_weight>`: with and without bias. Explicitly instantiated for `<true, true>`, the only combination ATen uses.
> - `convolution_forward_expected_weights_desc`: the overload that takes `is_channels_last` at runtime.
>
> File-local (`detail/Conv.cpp`), same names as in ideep:
> - `convolution_forward_params`
> - `conv_deconv_utils::prepare_parameters` (fp32 overload)
> - `get_primitive_desc`: the uncached aarch64 variant and the cached x86 variant
> - `expected_weights_desc<is_channels_last>`
> - `do_compute`, `do_compute_binary`
> - `compute_dispatch` (fp32)
> - `do_prepare` (fp32)
> - `compute_binary_dispatch`
>
> ### Call sites switched
> - `mkldnn/Conv.cpp`: `compute_v3` ×2, `compute_binary` ×2.
> - `mkldnn/ConvPrepack.cpp`: `expected_weights_desc`.
> - `mkldnn/MKLDNNConversions.cpp`: `expected_weights_desc` ×2 (conv2d/conv3d weight reorder).
> - `quantized/cpu/qconv_prepack.cpp`: `expected_weights_desc` ×2. This is a quantized file, but the call is the same fp `expected_weights_desc` overload.
>
> Still on ideep:
> - backward data and weights (backward PR)
> - `ConvPrepack.cpp` `compute_v2` (`compute_v2` PR)
> - quantized `prepare` / `compute` in `qconv.cpp`
> - transposed convolution
> - `t_store().clear()` in `IDeepRegistration.cpp`
>
> ### Dropped (no ATen callers / unused)
> - `convolution_forward::use_gemm`
> - unused overloads, and the `engine` / `lowp_kind` parameters on the public functions
> - the int8 `do_prepare` and the param-based `prepare` / `compute(params, ...)` overloads (moving with quantized conv)
>
> ### Other changes
> - `IDEEP_ENFORCE` becomes a debug-only `dnnl::error::wrap_c_api(...)` under `#ifndef NDEBUG`. `IDEEP_CHECK` becomes an unconditional `wrap_c_api`. Both behave as in ideep.
> - Called directly from ideep for now: `ideep::utils::get_compatible_dilates`, `ideep::utils::group_dims`, `ideep::utils::create_key`, `ideep::utils::computation_cache`.
> - The primitive cache is ideep's thread-local `computation_cache<dnnl::convolution_forward::primitive_desc>`, the same store ideep uses. `clear_computation_cache()` therefore needs no change.
> - Two loop indices in `expected_weights_desc` changed from `int` to `size_t` (sign-compare; ideep hides this as a system header).
> - Fixed typos in a comment copied from ideep: "workaroud", "detials", "weihgts".
>
> ### Testing
> oneDNN verbose logs (`ONEDNN_VERBOSE=1`, timings stripped, sorted counts) are identical before and after:
> - `test_mkldnn.py` plus `test_freezing.py -k mkldnn`: 6,572 distinct lines.
> - `quantization/core/test_quantized_op.py -k "qconv and pt2e and not fp8"`: 257 distinct lines.
> - `test_mkldnn_fusion.py`, `nn/test_convolution.py -k mkldnn`, and `inductor/test_mkldnn_pattern_matcher.py -k "conv and not qconv and not quant and not woq"`: 1,284 distinct lines, 772 of them convolution.
>
> Four Inductor tests fail identically with and without this change: `test_conv{2,3}d_binary_broadcast_shapes_cpu` and `test_conv_transpose{2,3}d_unary_cpu`, all with bf16 tolerance errors. `test_conv2d_unary_cpu` is flaky at its fp32 tolerance.
>
> Convolution is split across PRs for size: forward (#201224), backward (#201229), `compute_v2` (#202611), quantized (#202622) and transposed (#203645). Backward lives in `detail/Conv.{h,cpp}` alongside forward.
>
> (`test/jit/test_freezing.py` and `test/test_mkldnn_fusion.py` were later deleted upstream by #203621. The final A/B comparison of the whole series against `main`, described in #204808, re-checks these paths without it.)
>
> Previously submitted as #201224.

Pull Request resolved: #205716
Approved by: https://github.com/albanD
ghstack dependencies: #205709, #205710, #205711, #205712, #205713, #205714, #205715
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
## Linked issue or supporting maintainer
Part of #154444
Supported by @albanD

## BC-breaking?
No

## Summary (human written only)
Ports quantized convolution ops from ideep to ATen. Verbose logs form ONEDNN_VERBOSE were used to verify exact matching behavior before/after this change.

## Agent details (if applicable)
Developed with assistance from Claude Opus 5.5.

>
> Ports the int8 convolution entry points that `quantized/cpu/qconv.cpp` uses from ideep (`ideep::convolution_forward`) into `aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}` (namespace `at::native::mkldnn`). The port is line-for-line and changes no behavior: it still takes `ideep::tensor` / `ideep::attr_t` and uses ideep's engine, stream and primitive cache.
>
> ### Ported
> Public (`detail/Conv.h`), with ideep's comments. Where ideep's comments no longer describe the code, they are rewritten:
> - `convolution_forward_prepare`: ideep's int8 `prepare` (with bias, without the `is_channels_last` argument).
> - `convolution_forward_compute<reorder_src, reorder_weight>(const convolution_forward_params&, ...)`: compute with pre-prepared params. Explicitly instantiated for `<false, false>` only, so its default template arguments are dropped; a call relying on them would fail to link.
> - `convolution_forward_compute<reorder_src, reorder_weight>(src, weights, bias, ..., scales, zero points, ...)`: ideep's int8 2-in-1 compute. qconv uses it when its primitive cache misses. Explicitly instantiated for `<true, true>`. ideep's comment says "without bias", but the function takes a bias and uses it if non-empty. The comment now says that, and notes that this path always passes `is_channels_last = true`, while `prepare` infers it from src and weights (as in ideep).
>
> File-local (`detail/Conv.cpp`):
> - `do_prepare<with_bias>`: ideep's int8 overload.
>
> These reuse the int8 `prepare_parameters` and the scales/zero-points `compute_dispatch` from 12/N, and `get_primitive_desc` / `do_compute` from #205716.
>
> ### Type change
> - `convolution_forward_params`, already ported, moves unchanged from `Conv.cpp`'s anonymous namespace into `Conv.h`. `OnednnUtils.h` now defines `using ConvParams = at::native::mkldnn::convolution_forward_params;`. qconv only reads `params.pd`, and stores and copies the struct in `ConvPrimitiveCache`, which works the same with the moved struct.
>
> ### Call sites switched
> - `quantized/cpu/qconv.cpp`, in `PackedConvWeightsOnednn::apply_impl`:
>   - `prepare` on the cache fill
>   - `compute<false, false>(params, ...)` on a cache hit
>   - the int8 2-in-1 `compute` on a cache miss
> - `quantized/cpu/qconv.cpp`, in `_quantized_convolution_onednn`: `prepare` / `compute<false, false>`. These sit in the `#else` of `IDEEP_PREREQ(3, 1, 0, 0)`, which is never compiled with oneDNN 3.x; they are switched for consistency.
>
> The `ideep::engine::cpu_engine()` argument is dropped from each call; it equals the default.
>
> Still on ideep: quantized deconvolution in `qconv.cpp` (15/N), and `t_store().clear()` in `IDeepRegistration.cpp`.
>
> ### Dropped
> - The `engine` parameters, as in the earlier ports. ATen only ever passes `ideep::engine::cpu_engine()`, which the ported code uses directly.
> - In the 2-in-1 compute: ideep computes a local `is_channels_last` and never uses it (it passes `true` to `compute_dispatch`). The unused local is removed; it fails `-Werror=unused-variable` builds outside ideep's system-header include.
>
> ### Testing
> oneDNN verbose logs (`ONEDNN_VERBOSE=1`, timings stripped, sorted counts) are identical before and after:
> - `quantization/core/test_quantized_op.py -k "(qconv or conv_transpose or qconvtranspose) and not fp8 and not cudnn"` with `PYTORCH_HYPOTHESIS_PROFILE=pytorch_ci` (derandomized; identical across repeated baseline runs): 675 distinct lines. These tests call `prepare` and `compute(params)` 232 times each.
> - A probe that reuses one prepacked weight with new input scales and shapes, to exercise the cache-miss 2-in-1 compute: logs identical, outputs bitwise equal.
> - `quantization/core/test_quantized_op.py -k "qconv and pt2e and not fp8"`: 257 distinct lines.
> - `test_mkldnn.py` plus `test_freezing.py -k mkldnn`: 6,572 distinct lines.
>
> (`test/jit/test_freezing.py` was later deleted upstream by #203621. The final A/B comparison of the whole series against `main`, described in #204808, re-checks these paths without it.)
>
> Previously submitted as #202622.

Pull Request resolved: #205973
Approved by: https://github.com/albanD
ghstack dependencies: #205972
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: cpu CPU specific problem (e.g., perf, algorithm) open source release notes: quantization release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants