Skip to content

[mkldnn][13/N] Port ideep quantized convolution into ATen - #205973

Closed
frost-intel wants to merge 4 commits into
gh/frost-intel/11/basefrom
gh/frost-intel/11/head
Closed

frost-intel wants to merge 4 commits into
gh/frost-intel/11/basefrom
gh/frost-intel/11/head

Conversation

@frost-intel

@frost-intel frost-intel commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

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.

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

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:

This PR ports ideep's int8 convolution entry points (prepare, compute with
pre-prepared params, and the int8 2-in-1 compute) into
aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}, moves
convolution_forward_params into Conv.h, and switches qconv.cpp to the ported
functions. Recommendation: Approve. The two earlier findings are fixed at HEAD,
and every remaining point is non-blocking.

Findings (4):

[minor] aten/src/ATen/native/mkldnn/detail/Conv.cpp:1039
Non-blocking, carried over from the last review: the new int8
`do_prepare<with_bias>` (Conv.cpp:1039-1154) still repeats the int8
`compute_dispatch` (Conv.cpp:853-967) step for step: the locals,
`prepare_parameters`, `get_primitive_desc`, building the aarch64/x86 params, and
filling the scales/zero-point maps. The two copies even write the same step
differently: `std::get<0>(std::get<1>(arg_scale_pair))` at :1137/:1149 versus
`arg_scale_pair.second.first` at :949/:960. Reducing the int8 `compute_dispatch`
to `do_prepare<with_bias>(...)` followed by `do_compute<with_bias, reorder_src,
reorder_weight>(...)` would behave the same, and `compute_binary_dispatch`
already has that shape. Two adjustments are needed: move `do_prepare` above
`compute_dispatch` or forward-declare it, and keep the default arguments on
`compute_dispatch` because the fp32 v2 callers rely on them. The fp32 pair has
the same duplication, so a follow-up could fix both.

[minor] aten/src/ATen/native/mkldnn/detail/Conv.h:107
Non-blocking: the comment on `pd_use_threads` ("From IPEX. Set in
`do_prepare()`, only used outside ideep.") was copied unchanged from ideep. It
is misleading in a header that quantized code uses through `ConvParams`. Both
constructors set the field (Conv.h:87 and :100), and nothing in the tree reads
it. Reword the comment to say the field is kept only to match ideep's layout, or
drop it.

[minor] aten/src/ATen/native/mkldnn/detail/Conv.h:9
Non-blocking: the moved struct in Conv.h now uses `std::move` (:82-83, :95-99).
This PR added `<memory>` and `<unordered_map>` to the header's includes but not
`<utility>`, which Conv.cpp:9 does include. The header builds today only because
`<utility>` comes in indirectly through MKLDNNCommon.h and ideep.

[minor] aten/src/ATen/native/mkldnn/detail/Conv.h:298
Non-blocking, PR description only: the description says each public function
comes "with ideep's comments" and that ideep's "without bias" comment on the
2-in-1 compute "is kept verbatim". At HEAD those comments are rewritten
(Conv.h:298-300 and :339-342). Update the description before it becomes the
commit message.

Reviewed commit: 00f4722 (NOT the current head 44df1bc)

Review run

🐛 Report a bad review

🔗 Helpful Links

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

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

✅ No Failures

As of commit 44df1bc with merge base 47eb5c6 (image):
💚 Looks good so far! There are no failures yet. 💚

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

github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
@frost-intel

Copy link
Copy Markdown
Collaborator Author

Addressing bot comments:

  • Dropped the default template arguments on the pre-prepared compute.
  • Rewrote the copied comments to describe the code, including the channels-last difference between prepare and the 2-in-1 compute.
  • The channels-last difference and the compute_dispatch/do_prepare duplication are noted as follow-ups after ideep is removed.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of 00f4722: nothing blocking; ready for human review.

This PR ports ideep's int8 convolution entry points (prepare, compute with pre-prepared params, and the int8 2-in-1 compute) into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}, moves convolution_forward_params into Conv.h, and switches qconv.cpp to the ported functions. Recommendation: Approve. The two earlier findings are fixed at HEAD, and every remaining point is non-blocking.

⚪ 4 non-blocking findings

// Ported from ideep::convolution_forward::do_prepare.

Non-blocking, carried over from the last review: the new int8 do_prepare&lt;with_bias&gt; (Conv.cpp:1039-1154) still repeats the int8 compute_dispatch (Conv.cpp:853-967) step for step: the locals, prepare_parameters, get_primitive_desc, building the aarch64/x86 params, and filling the scales/zero-point maps. The two copies even write the same step differently: std::get&lt;0&gt;(std::get&lt;1&gt;(arg_scale_pair)) at :1137/:1149 versus arg_scale_pair.second.first at :949/:960. Reducing the int8 compute_dispatch to do_prepare&lt;with_bias&gt;(...) followed by do_compute&lt;with_bias, reorder_src, reorder_weight&gt;(...) would behave the same, and compute_binary_dispatch already has that shape. Two adjustments are needed: move do_prepare above compute_dispatch or forward-declare it, and keep the default arguments on compute_dispatch because the fp32 v2 callers rely on them. The fp32 pair has the same duplication, so a follow-up could fix both.


// From IPEX. Set in `do_prepare()`, only used outside ideep.

Non-blocking: the comment on pd_use_threads ("From IPEX. Set in do_prepare(), only used outside ideep.") was copied unchanged from ideep. It is misleading in a header that quantized code uses through ConvParams. Both constructors set the field (Conv.h:87 and :100), and nothing in the tree reads it. Reword the comment to say the field is kept only to match ideep's layout, or drop it.


#include <unordered_map>

Non-blocking: the moved struct in Conv.h now uses std::move (:82-83, :95-99). This PR added &lt;memory&gt; and &lt;unordered_map&gt; to the header's includes but not &lt;utility&gt;, which Conv.cpp:9 does include. The header builds today only because &lt;utility&gt; comes in indirectly through MKLDNNCommon.h and ideep.


// Ported from ideep::convolution_forward::prepare.

Non-blocking, PR description only: the description says each public function comes "with ideep's comments" and that ideep's "without bias" comment on the 2-in-1 compute "is kept verbatim". At HEAD those comments are rewritten (Conv.h:298-300 and :339-342). Update the description before it becomes the commit message.

This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review

@pytorch-bot pytorch-bot Bot added ready for review Automated review passed, ready for a final review by a maintainer. and removed in progress PR is being worked on by the author, until the automated review accepts it labels Nov 21, 2026
[ghstack-poisoned]
@frost-intel

Copy link
Copy Markdown
Collaborator Author

Addressing bot comments:

  • Reworded the pd_use_threads comment and added the include.
  • The do_prepare/compute_dispatch duplication is a follow-up after ideep is removed.
  • The description was already updated.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #205977

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #205977

1 similar comment
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #205977

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 transposed convolution ops from ideep to ATen. Verbose logs form ONEDNN_VERBOSE were used to verify exact matching behavior before/after this change. We dropped unused params and an unused overload.

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

>
> Ports the fp32 transposed-convolution operators that ATen uses from ideep's `deconv.hpp` into `aten/src/ATen/native/mkldnn/detail/Deconv.{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/Deconv.h`), with ideep's comments and default arguments. Comments that no longer describe the code are rewritten: the backward-data weights layout (`{o, i, ...}`, as the caller passes), what `is_channels_last` controls in `expected_weights_desc` (src/dst format only), the `transposed` default, and which template arguments are instantiated:
> - `convolution_transpose_forward_compute_v3<reorder_src, reorder_weight>`: with and without bias. Explicitly instantiated for `<true, true>`.
> - `convolution_transpose_forward_expected_weights_desc<is_channels_last, transposed>`: instantiated for `<true, true>`, `<false, true>` and `<true, false>`, the combinations ATen uses.
> - `convolution_transpose_backward_data_compute_v3`
> - `convolution_transpose_backward_weights_compute_v3`: with and without bias.
>
> File-local (`detail/Deconv.cpp`), same names as in ideep:
> - `deconv_forward_params`, default constructor only (ideep's member-wise constructors are unused)
> - `get_primitive_desc<with_bias>`
> - `do_prepare` (fp32)
> - `do_compute`
> - `compute_impl` (fp32)
> - `backward_weights_compute_impl`: ideep's `convolution_transpose_backward_weights::compute_impl`, renamed to avoid clashing with the forward `compute_impl`, as in the conv port.
>
> ideep's deconvolution has no aarch64-specific code.
>
> `get_primitive_desc` uses ideep's thread-local `computation_cache<dnnl::deconvolution_forward::primitive_desc>`, the same store ideep's own `convolution_transpose_forward` uses (still used by quantized deconvolution). The cache key fields and their order are unchanged.
>
> ### Shared with conv
> - The fp32 `conv_deconv_utils::prepare_parameters` is shared with the conv port through `Conv.h` (declared there in 12/N). ideep shares it the same way between `conv.hpp` and `deconv.hpp`. This PR does not edit `detail/Conv.{h,cpp}`.
>
> ### Call sites switched
> - `mkldnn/Conv.cpp`: forward ×2, backward data, backward weights ×2.
> - `mkldnn/MKLDNNConversions.cpp`: `expected_weights_desc<true>` / `<false>` (`_reorder_convolution_transpose_weight`).
> - `quantized/cpu/qconv_prepack.cpp`: `expected_weights_desc<true, false>`, for the quantized transposed-conv weight prepack. It uses the same fp weight-descriptor function.
>
> Still on ideep: quantized deconvolution in `quantized/cpu/qconv.cpp` (`prepare` / `compute`), ported in 15/N.
>
> ### Dropped / changed
> - The `engine` parameters, as in the earlier ports.
> - The unused non-`_v3` `compute` overloads and all int8 overloads (no fp callers).
> - `expected_weights_desc`: two loop indices changed from `int` to `size_t` (sign-compare; ideep hides this as a system header).
> - `do_prepare`: `std::move(super(pd))` becomes `dnnl::deconvolution_forward(pd)`; moving a temporary is a no-op.
> - The commented-out `is_nhwc` block in backward data is removed.
> - Four `// May replace ...` comments are added at the `reinit_if_possible` calls, following the convention of the earlier ports. They are new, not from ideep.
>
> ### 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, 1,598 of them deconvolution. Calls to the ported entry points from these tests and the quantized tests below:
>
>   | Entry point | Calls |
>   |---|---|
>   | forward, with bias | 432 |
>   | forward, without bias | 436 |
>   | backward data | 392 |
>   | backward weights, with bias | 196 |
>   | backward weights, without bias | 196 |
>   | `expected_weights_desc` | 11 |
>
>   (Counted with temporary instrumentation, not included in the PR.)
> - `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): 675 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.
>
> 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/jit/test_freezing.py` was later deleted upstream by #203621, and `test_mkldnn_fusion.py` no longer exists upstream. The final A/B comparison of the whole series against `main`, described in #204808, re-checks these paths without them.)
>
> Previously submitted as #203645.

Pull Request resolved: #205974
Approved by: https://github.com/albanD
ghstack dependencies: #205972, #205973
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
…205975)

## Linked issue or supporting maintainer
Part of #154444
Supported by @albanD

## BC-breaking?
No

## Summary (human written only)
Ports the int8 quantized transposed conv (deconv) from ideep. I don't port functions not used in ATen, and drop unused overloads and engine params.

This PR ports the last of the ops ideep ops used in ATen.

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

>
> Ports the int8 paths of `ideep::convolution_transpose_forward` that quantized `conv_transpose` uses into `aten/src/ATen/native/mkldnn/detail/Deconv.{h,cpp}`. The port is line for line, with no behavior change, and still uses ideep's primitive cache.
>
> - `deconv_forward_params` moves into `Deconv.h`; `DeconvParams` in `OnednnUtils.h` now points at it.
> - Ported: int8 `prepare`, `compute` with prepared params, and int8 2-in-1 `compute`, plus the int8 `do_prepare` and `compute_impl` behind them. Call sites in `qconv.cpp` are switched over.
> - These use the int8 `conv_deconv_utils::prepare_parameters`, which 12/N declares in `Conv.h`. This PR does not edit `detail/Conv.{h,cpp}`.
>
> Not ported, because ATen never reaches them: `compute_v2`, `prepare_v3`, and the no-bias int8 overloads. Changes from ideep: the `engine` parameter is dropped (ATen only ever passes `ideep::engine::cpu_engine()`, which the ported code uses directly), and the prepared-params `compute` loses its default template arguments, since only `<false, false>` is instantiated. Header comments that no longer match the code (defaults the parameters don't have, "for compatibility", "for both fp32 and int8") are rewritten.
>
> After this PR every ideep convolution and transposed-convolution operator ATen uses is ported. The remaining ideep operator, matmul (fp32 and quantized), is ported in 16/N.
>
> Testing: A/B oneDNN verbose logs (before vs. after) are identical for:
> - the quantized conv/deconv tests, with fixed random seeds
> - `test_mkldnn`
> - a probe that reuses packed deconv weights with new input scales and shapes to reach the cache-miss path; its outputs are also bitwise equal
>
> Previously submitted as #204615.

Pull Request resolved: #205975
Approved by: https://github.com/albanD
ghstack dependencies: #205972, #205973, #205974
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)
Port of the matmul op from ideep to ATen. Unused params and functions were dropped, but otherwise this is a line-for-line port with identical functionality, verified by tests and onednn_verbose log checking.

Ports int8 matmul_forward used by quantized linear into ATen. This is a line-by-line copy, no behavioral change. Functionality not used in ATen was dropped, along with unused params.

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

>
> Ports the matmul paths that ATen uses from ideep (`ideep::matmul_forward`) into `aten/src/ATen/native/mkldnn/detail/Matmul.{h,cpp}` (namespace `at::native::mkldnn`): the floating-point path used by `mkldnn/Matmul.cpp` and the int8 paths used by quantized linear. 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.
>
> This combines two earlier PRs, the fp32 port (#202547) and the quantized port (#204617). Code that #202547 had removed as unused on the fp path (`do_prepare`'s `dst_type` override, `do_compute`'s zero-point arguments, `compute_impl`'s int8 branches) is kept, because the quantized paths reach it.
>
> ### Ported
> Public (`detail/Matmul.h`), each with ideep's comments:
> - `matmul_forward_params` and `matmul_forward_dyn_quant_params`, with their default constructors only. ideep's member-wise constructors are unused and are dropped (the `matmul_forward_params` one also read `pd` after moving from it), as is the `bias_attr` member, which only that constructor set. `LinearParams` in `OnednnUtils.h` now points at the ported struct.
> - `matmul_forward(src, weights, dst, dst_coeff, sum_coeff, attr)`: ideep's **deprecated** no-bias 2-in-1 `compute`, which all three fp calls in ATen resolve to. ideep's deprecation comment is kept.
> - `matmul_forward_prepare<is_dynamic>`: static and dynamic int8 `prepare`.
> - `matmul_forward_compute`: with pre-prepared params (fp32 and static int8), with pre-prepared params (dynamic int8), and the int8 2-in-1 compute.
> - Both `matmul_forward_expected_weights_desc` overloads.
>
> File-local (`detail/Matmul.cpp`), same names as in ideep:
> - `do_prepare<with_bias>` (fp32)
> - `do_prepare_static_quant`, `do_prepare_dynamic_quant`
> - `do_compute<with_bias, reorder_src, reorder_weight>`, `do_compute_dynamic_quant`
> - `compute_impl<with_bias, reorder_src, reorder_weight>`: all three branches (fp32, static and dynamic int8)
>
> The call chains are the same as ideep's. The fp path is `compute_impl<false, true, true>` with ideep's empty scales and zero points, so only its fp32 branch runs. The aarch64 path (uncached primitive descriptor, `format_tag::any` weights) is kept.
>
> ### Call sites switched
> - `mkldnn/Matmul.cpp`: all three `ideep::matmul_forward::compute` calls: the bf16/fp16/bf32/tf32 `mkldnn_gemm`, bf16→fp32 `mkldnn_gemm`, and `mkldnn_matmul`. The three empty `std::vector<float>()` scale arguments are dropped. `alpha` and `beta` map to `dst_coeff` and `sum_coeff` as before.
> - `quantized/cpu/qlinear.cpp`, `qlinear_dynamic.cpp` and `qlinear_prepack.cpp`: `prepare`, `compute` and `expected_weights_desc`.
>
> ### Not ported, because ATen never reaches them
> - `compute_binary` and its helpers
> - `compute_v2`
> - `compute_dynamic`
> - the deprecated `compute`/`prepare` overloads that take `bin_post_params` or put `dst_coeff` first, and the deprecated with-bias fp overload
> - the fp32 with-bias `prepare`/`compute` overloads
> - the no-bias int8 overloads
>
> ### Deviations from ideep
> - The `engine` parameters are dropped; ATen only ever passes `ideep::engine::cpu_engine()`, which the ported code uses directly.
> - The deprecated fp `matmul_forward` drops the three scale parameters, `bin_post_params` (always `{}`), `dst_type` (always `undef`) and `lowp_kind`; it passes ideep's defaults to `compute_impl`.
> - Unused local references are dropped (`bias_attr`, `wei_zero_point`, and `dst_scales_in` in the dynamic compute) because they fail `-Werror`.
> - In `do_prepare_static_quant`, the zero-point size variables are declared inside `#ifndef NDEBUG`, since only that check uses them, and the unused `src_strides` vector is dropped (the src descriptor uses `format_tag::any`).
> - `IDEEP_ENFORCE` becomes a debug-only `dnnl::error::wrap_c_api(...)` under `#ifndef NDEBUG`, as in ideep. The weights/bias dtype `||` chains are written with `one_of` from `mkldnn/Utils.h`, which computes the same thing.
>
> ### Other changes
> - Called directly from ideep for now: `ideep::utils::create_key`, `ideep::utils::computation_cache`, `ideep::utils::op_scale_mask`, `ideep::utils::tensor_scale_mask`, `ideep::utils::tensor_zp_mask`, and the `IDEEP_DEF_SCALE` / `IDEEP_DEF_ZP` / `IDEEP_EMPTY_SCALE` / `IDEEP_EMPTY_ZP` constants.
> - The primitive cache is ideep's thread-local `computation_cache<dnnl::matmul::primitive_desc>`. The key fields and their order are unchanged.
>
> ### Testing
> oneDNN verbose logs (`ONEDNN_VERBOSE=1`, timings stripped, sorted counts) are identical before and after:
> - `test_mkldnn.py -k "matmul or mm or bmm or dot or mv or bf32 or tf32 or reduced"` plus `test_linalg.py -k "cpu and (addmm or bmm or matmul or addmv or mv or dot or _mm_ or linear) and (bfloat16 or float16 or half)"`: 524 distinct lines, 521 of them matmul (bf16/fp16, `alpha` source scales, `beta` sum post-op).
> - A probe of fp32 `addmm`/`mm`/`bmm`/`baddbmm`/`mv` with `torch.backends.mkldnn.matmul.fp32_precision` set to `bf16` and `tf32`: logs identical, outputs bitwise equal. On bf16/AMX hardware these paths are also covered by the `@reduced_f32_on_and_off` float32 tests in `test_linalg.py` (`addmm`, `mm`, `bmm`, `addbmm`, `baddbmm`, `inner`, `tensordot`), which the A/B filter above leaves out; `mv` has no such test.
> - `test_quantized_op -k linear` (fixed test seeds).
> - Full `test_mkldnn.py` plus `test_freezing.py -k mkldnn`: 6,572 distinct lines.
> - Re-run against `main` including the `test_linalg.py` `*_cpu_float32` tests (`addmm`, `mm`, `bmm`, `baddbmm`, `addbmm`, `inner`, `tensordot`) that `@reduced_f32_on_and_off` runs with bf16 and tf32 fp32-precision: oneDNN logs identical (1,015 distinct lines, 237 matmul each with `fpmath:bf16` and `fpmath:tf32`).
>
> A probe that reuses packed quantized weights with new input scales and shapes, to reach the cache-miss paths, gives identical logs and bitwise-equal outputs.
>
> (`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 #202547 and #204617.

Pull Request resolved: #205976
Approved by: https://github.com/albanD
ghstack dependencies: #205972, #205973, #205974, #205975
pytorchmergebot pushed a commit that referenced this pull request Nov 25, 2026
…5977)

## Linked issue or supporting maintainer
Part of #154444
Supported by @albanD

## BC-breaking?
No

## Summary (human written only)
This PR ports oneDNN primitive cache and attr_t from ideep to ATen, as well as renames for uses within ATen.

Tests verified the same number of cache-misses for a fixed workload with A/B testing.

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

>
> Three parts, each line-for-line with no behavior change:
>
> 1. **Primitive cache.** `detail/PrimitiveCache.h` ports `ideep::utils::lru_cache`, `computation_cache` and the `to_bytes`/`create_key` key builders. Behavior is unchanged: one thread-local store per descriptor type, capacity 1024 (1 on aarch64), overridable with `LRU_CACHE_CAPACITY`, and byte-identical keys. The conv, deconv, inner-product and matmul ports, plus `clear_computation_cache`, now use it. The ideep store is no longer used by ATen.
> 2. **`Attr` alias.** Mechanical rename of `ideep::attr_t` to `at::native::mkldnn::Attr` (233 uses).
> 3. **`Attr` class.** `detail/Attr.h` ports `ideep::attr_t`: the constructors ATen uses, deep-copy assignment, scale/zero-point storage, `has_op_kind`, `non_negative_output` (ideep spells it `non_negitive_output`), `to_bytes`, and the 15 factory helpers ATen uses. Unused helpers and constructors are not ported. ideep's note in `to_bytes` saying scales and zero points are not encoded is out of date (they are), so it is rewritten to list what is actually left out. A conversion to `ideep::attr_t` that carries the scale and zero-point maps remains until `ideep::tensor` is ported (21/N), because its reorders still take `ideep::attr_t`.
>
> Testing:
> - oneDNN verbose logs before vs. after are identical for `test_mkldnn`, quantized conv/deconv/linear, and the fp matmul tests. The cache-miss probes for quantized linear/deconv and the fp32 matmul probe also give bitwise-equal outputs.
> - Per-op primitive-descriptor cache-miss counts are identical before vs. after, at the default capacity and with `LRU_CACHE_CAPACITY=1`.
> - A standalone probe checks that `Attr` and `ideep::attr_t` produce byte-identical cache keys for every factory and constructor ATen uses, and that copying and conversion keep scales and zero points.
>
> Previously submitted as #204801.
Pull Request resolved: #205977
Approved by: https://github.com/albanD
ghstack dependencies: #205972, #205973, #205974, #205975, #205976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot Merged module: cpu CPU specific problem (e.g., perf, algorithm) open source ready for review Automated review passed, ready for a final review by a maintainer. release notes: quantization release notes category topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants