Repository navigation
[mkldnn][10/N] Port forward FP Conv ops from ideep to ATen - #205716
frost-intel wants to merge 5 commits into
Conversation
[ghstack-poisoned]
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (4): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/205716
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 1bfef38 with merge base 4004f7e ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Automated review of b3f19c4: nothing blocking; ready for human review.
This PR ports ideep's floating-point convolution_forward forward path (compute_v3, compute_binary, expected_weights_desc and helpers) into aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp} and switches the ATen call sites to use it. Recommendation: Approve. None of the points raised blocks merging; the review names the Security bounds check as the one most worth adding.
⚪ 4 non-blocking findings
Non-blocking, already in ideep: the file-local expected_weights_desc (lines 372-375) reads weights_dims.size() elements of src_dims without checking its length. mkldnn_reorder_conv2d_weight and mkldnn_reorder_conv3d_weight (MKLDNNConversions.cpp:168-169, 225-226) pass the user's input_size through unchanged, and input_size is an unbounded SymInt\[\]? in native_functions.yaml. So a 4-D mkldnn weight with input_size=\[1\] reads past the end of the vector. ConvPrepack.cpp:56-57 is safe because expand_param_if_needed enforces the length. The PR only renames the callee, so this is not a regression. Now that ATen owns this code, a TORCH_CHECK(src_dims.empty() || src_dims.size() == weights_dims.size(), ...) would be cheap to add here or in the two reorder ops.
Non-blocking: the public names in detail/Conv.h:12,30,49,70 break the convention of the other detail/*.h ports, which map ideep's X::compute to X and X::compute_binary to X_binary (inner_product_forward, inner_product_forward_binary, softmax_forward, pooling_forward, eltwise_forward) and use the parameter names prop_kind and algorithm. This header keeps convolution_forward_compute_v3 / convolution_forward_compute_binary and ideep's aalgorithm / aprop_kind. If _v3 is kept on purpose to distinguish it from the compute_v2 port in # 202611, consider convolution_forward / convolution_forward_binary here and a _v2 suffix on the deprecated one. Otherwise the series ends up with two naming schemes.
Non-blocking: the "for fp32" comments copied from ideep are misleading in an ATen header (detail/Conv.h:11,29,46,67 and detail/Conv.cpp:585,657,727). These paths also handle bf16 and f16 (prepare_parameters, Conv.cpp:92-122). ideep meant "non-quantized", and Conv.cpp:61 already says "non-quantization version", which reads better. The comment for convolution_forward_expected_weights_desc (Conv.h:86-87) should say it is also used for quantized prepack: qconv_prepack.cpp:438-442 and :599-605 pass s8 or f8_e4m3 weights, u8 or f8_e4m3 activations, and scale/zero-point op_attrs, and the function has int8-specific logic (y_dtype = s32 for s8 at Conv.cpp:390-392). The description's claim that quantized ops are left for later, and that this is "the same fp overload", understates this.
Non-blocking: detail/Conv.cpp carries over ideep state that nothing in ATen uses. convolution_forward_params::pd_use_threads (lines 29, 42, 51) is never read, and its comment ("only used outside ideep Set in do_prepare()") is wrong here because the constructors set it. The 5-argument constructor (31-42) and the bias_attr member are unused. all_scales / all_zero_points are never assigned, so the loops in do_compute (476-489) and do_compute_binary (564-577) never run. The src_attr / weights_attr / bias_attr outputs of prepare_parameters (76-78) are never written or read. op_attr(op_attr) (lines 26, 39) copies from an ideep::attr_t&& parameter where it should use std::move. The InnerProduct port trimmed its params struct to the fields it uses (InnerProduct.cpp:14-21). Doing the same here, and adding fields back in # 202611 if the int8 path needs them, would keep the two ports consistent.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
Starting merge as part of PR stack under #205717 |
## Linked issue or supporting maintainer Part of #154444 ## BC-breaking? No ## Summary (human written only) Port of the convolution backward ops 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. ## Agent details (if applicable) Developed with assistance from Claude Opus 5.5. > > Ports the floating-point convolution **backward** operators that ATen uses from ideep (`ideep::convolution_backward_data`, `ideep::convolution_backward_weights`) into `aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}` (namespace `at::native::mkldnn`), based on #201224 (conv forward). The port is line-for-line and changes no behavior: it still takes `ideep::tensor` / `ideep::attr_t` and uses ideep's engine and stream. > > This is one of the convolution PRs (split for size). It adds the backward functions to the same `detail/Conv.{h,cpp}` as the forward port. > > ### Ported > Public (`detail/Conv.h`): > - `convolution_backward_data_compute_v2` (`ideep::attr_t op_attr` by value, as in ideep) > - `convolution_backward_weights_compute_v2`: with and without bias > > File-local (`detail/Conv.cpp`): > - `backward_weights_compute_impl<with_diff_bias>`: ideep's `convolution_backward_weights::compute_impl`, renamed to avoid clashing with the forward helpers. > > Both functions keep ideep's aarch64 and x86 primitive-descriptor variants. > > The forward primitive descriptor used as a hint comes from the ported `get_primitive_desc`, exactly as ideep's backward does. On x86 that lookup goes through ideep's forward primitive cache, as before. > > ### Call sites switched > - `mkldnn/Conv.cpp`: `mkldnn_convolution_backward_input` (backward data) and `mkldnn_convolution_backward_weights` (with and without bias). > > ### Dropped (no ATen callers / unused) > - The `algorithm` parameter of both functions; it was always `convolution_direct`, which is now fixed locally. > - The `engine` parameters. > - Backward weights: `diff_weight_type` and the branch that only ran with a non-default value. > > ### Other changes > - `IDEEP_CHECK` (bf16/f16 on avx2_vnni_2) becomes an unconditional `dnnl::error::wrap_c_api`, as in ideep. ideep's backward functions have no `IDEEP_ENFORCE`, so there is no debug-only check here. > - Called directly from ideep for now: `ideep::utils::get_compatible_dilates`. > > ### 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,494 of them convolution backward. > - `quantization/core/test_quantized_op.py -k "qconv and pt2e and not fp8"`: 257 distinct lines. > - `nn/test_convolution.py -k mkldnn` and the Inductor mkldnn pattern tests: covered by the whole-series A/B comparison against `main` in #204808, with identical per-test outcomes and identical oneDNN primitive logs. (`test_mkldnn_fusion.py` no longer exists upstream.) > > (`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 #201229. Pull Request resolved: #205717 Approved by: https://github.com/albanD ghstack dependencies: #205709, #205710, #205711, #205712, #205713, #205714, #205715, #205716
## Linked issue or supporting maintainer Part of #154444 Supported by @albanD ## BC-breaking? No ## Summary (human written only) Third of convolution PRs split for size, along #205716 (forward) and #205717 (backward). In ideep, this op is marked as `DEPRECATED`, but current code in ATen still calls this, so I'm porting without changes for now. I expect that we could switch to the v3 version, but the goal of this stack is no behavior change on a line-to-line level, so that's left for a follow-up. ## Agent details (if applicable) Developed with assistance from Claude Opus 5.5. > > Ports ideep's **deprecated** `convolution_forward::compute_v2` into `aten/src/ATen/native/mkldnn/detail/Conv.{h,cpp}` (namespace `at::native::mkldnn`). Its only caller is `ConvPrepack.cpp`, which backs the `mkldnn_prepacked::conv2d_*` ops used by the TorchScript TensorExpr fuser. 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 is the third of the convolution PRs (split for size), after #205716 (forward) and #205717 (backward). It adds to the forward port's `detail/Conv.{h,cpp}`. > > ### Ported > Public (`detail/Conv.h`), each with ideep's `// DEPRECATED` comment: > - `convolution_forward_compute_v2`: with and without bias. > > File-local (`detail/Conv.cpp`), same names as in ideep: > - `compute_dispatch`: the scales/zero-points overload. > > Shared (`detail/Conv.h`, defined at namespace scope in `detail/Conv.cpp`): > - `conv_deconv_utils::prepare_parameters`: the quantization overload (scales and zero points), ported here. The fp32 overload from #205716 moves out of `Conv.cpp`'s anonymous namespace unchanged. Both are declared in `Conv.h` so that the transposed-convolution ports (14/N, 15/N) can share them, as ideep shares them between `conv.hpp` and `deconv.hpp`. > > ideep routes `compute_v2` through these int8-capable functions even for fp32. `ConvPrepack` always passes empty scales and zero points, so only their fp32 branches run today. They are kept line-for-line and will be reused by the quantized-conv port (13/N). The call chain is the same as ideep's: `compute_v2` → scales/zero-points `compute_dispatch<with_bias, true, true>` → int8 `prepare_parameters` → `get_primitive_desc` / `do_compute`. The last two come from #205716. > > ### Call sites switched > - `mkldnn/ConvPrepack.cpp`: `compute_v2` with and without bias. > > ### Dropped (no ATen callers / unused) > - `compute_v2`'s `algorithm`, `prop_kind`, `lowp_kind` and `engine` parameters. ATen never passes them; the internal `compute_dispatch` defaults, identical to ideep's, apply. > - The unused local `weights_zero_point` in the int8 `prepare_parameters`. ideep has it unused too; it is hidden there because ideep's headers are included as system headers, but here it fails `WERROR` builds. > > ### Other changes > - `IDEEP_ENFORCE` becomes a debug-only `dnnl::error::wrap_c_api(...)` under `#ifndef NDEBUG`, as in ideep. > - Called directly from ideep for now: `ideep::utils::get_compatible_dilates`, `ideep::utils::tensor_scale_mask`, `ideep::utils::tensor_zp_mask`, `ideep::utils::conv_weight_scale_mask`, `ideep::IDEEP_DEF_SCALE`. > > ### Testing > - **Coverage:** no test in CI reaches `compute_v2` today. Its only callers are the `mkldnn_prepacked::conv2d_*` ops, which only the TorchScript TensorExpr fuser inserts, and the tests that reached them (`test_mkldnn_fusion.py`, `test_freezing.py`) no longer exist upstream. Before their removal they called the ported `compute_v2` 40 times (20 with bias, 20 without), which I checked with temporary instrumentation. I'm not adding a new test, since TorchScript is being removed. > - **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. > - `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. > - `quantization/core/test_quantized_op.py -k "qconv and pt2e and not fp8"`: 257 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 #202611. Pull Request resolved: #205972 Approved by: https://github.com/albanD
## 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
Stack from ghstack (oldest at bottom):
sum,binary, anddirect_copyops from ideep into ATen #205710Linked 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.
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01