Skip to content

[mkldnn][3/N] Port ideep eltwise operators into ATen - #201055

Closed
frost-intel wants to merge 2 commits into
pytorch:mainfrom
frost-intel:ideep-removal/03-port-eltwise
Closed

frost-intel wants to merge 2 commits into
pytorch:mainfrom
frost-intel:ideep-removal/03-port-eltwise

Conversation

@frost-intel

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

Copy link
Copy Markdown
Collaborator

Linked issue or supporting maintainer

Part of #154444

BC-breaking?

No

Summary (human written only)

This PR directly ports the element-wise operators from ideep into ATen. This includes:
relu, sigmoid, tanh, gelu, scalar mul, dense GELU, and JIT from scalar mul.

Code is a line-for-line port from ideep, with identical functionality. 'mkldnn' tests pass with identical behavior.

Fake stack

Agent details (if applicable)

Developed with assistance from Claude Opus 5.5.

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

@pytorch-bot

pytorch-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 9d0548f with merge base 780bf8e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added module: cpu CPU specific problem (e.g., perf, algorithm) release notes: quantization release notes category labels Oct 15, 2026
@frost-intel frost-intel changed the title [onednn][3/N] Port ideep eltwise operators into ATen [mkldnn][3/N] Port ideep eltwise operators into ATen Oct 15, 2026
@frost-intel
frost-intel force-pushed the ideep-removal/03-port-eltwise branch from df3dc84 to 8b0ddac Compare October 29, 2026 16:04
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055

Move ideep::sum, ideep::binary and ideep::direct_copy into
aten/src/ATen/native/mkldnn/detail/{Binary,DirectCopy}.{h,cpp} and switch
all CPU callers (add/add_/add_out, mul_out, copy_, clone, batch_norm
running-stat update). The port is line-for-line, including destination
reinit when the destination layout differs. It still operates on
ideep::tensor.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move ideep::softmax_forward, ideep::prelu_forward and
ideep::prelu_backward into aten/src/ATen/native/mkldnn/detail/
{Softmax,Prelu}.{h,cpp} and switch the callers in SoftMax.cpp and
Prelu.cpp. The port is line-for-line; prelu_backward drops ideep's unused
prop_kind parameter. ideep::softmax_backward has no ATen callers and is
not ported.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move ideep::pooling_forward and ideep::pooling_backward into
aten/src/ATen/native/mkldnn/detail/Pooling.{h,cpp} and switch the callers
in Pooling.cpp. The port is line-for-line, including storing max-pool
indices as a workspace on the output tensor for use by the backward pass.
ideep::pooling_v2_* (dilated pooling) has no ATen callers and is not
ported.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move the ideep batch_normalization_forward_inference/forward_training/
backward and layer_normalization_forward operators used by ATen into
aten/src/ATen/native/mkldnn/detail/{BatchNorm,LayerNorm}.{h,cpp} and switch
the callers in Normalization.cpp. The port is line-for-line for the
code paths ATen uses; flags are fixed to ideep's defaults (the only values
ATen ever passed), so ideep's unused fused-relu/workspace branches and the
ignored momentum parameter are dropped.

Verified with ONEDNN_VERBOSE=1: the primitive create/exec log of
test_mkldnn.py and the mkldnn freezing tests is identical before and
after. A new test_mkldnn_layer_norm in test_freezing.py is added, since
not previously covered by tests.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move the ideep lstm_forward_inference (compute and expected_weights_desc),
lstm_forward_training (prepare and compute) and lstm_backward operators
used by ATen into aten/src/ATen/native/mkldnn/detail/Lstm.{h,cpp} and
switch the callers in RNN.cpp and MKLDNNConversions.cpp. The port is
line-for-line for the code paths ATen uses, including ideep's u8 branch;
parameters that ATen never passed or ideep ignored are dropped.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests (all primitive create/exec lines identical before and after), and
by comparing the output of mkldnn._reorder_mkldnn_rnn_layer_weight across
24 configurations (byte-identical packed layouts and values).
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055 (only the top commit is new).

Move the ideep inner_product_forward (compute, compute_binary,
expected_weights_desc), inner_product_backward_data and
inner_product_backward_weights code paths used by ATen into
aten/src/ATen/native/mkldnn/detail/InnerProduct.{h,cpp} and switch the
callers in Linear.cpp and MKLDNNConversions.cpp. The port is
line-for-line; ideep's private helpers keep their names. Primitive
descriptors still come from ideep's computation_cache with the same keys,
so the cache is shared with ideep until it is ported separately.

Verified with ONEDNN_VERBOSE=1: the primitive create/exec logs of
test_mkldnn.py, the mkldnn freezing tests, test_mkldnn_fusion.py and the
Inductor mkldnn linear pattern tests are identical before and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
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.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Port the floating-point matmul path ATen uses (ideep's deprecated
no-bias matmul_forward::compute) into
aten/src/ATen/native/mkldnn/detail/Matmul.{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 three call sites in mkldnn/Matmul.cpp. Quantized linear
remains on ideep for now.

Drop code ATen never reaches: compute_impl's int8 branches (callers
always pass empty scales and unscaled weights), the scale,
bin_post_params, dst_type, lowp_kind and engine parameters, and the
unused zero-point, bias-attr and dynamic-quant fields.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Port convolution_backward_data::compute_v2 and
convolution_backward_weights::compute_v2 (with its compute_impl) into
aten/src/ATen/native/mkldnn/detail/ConvBackward.{h,cpp}. The port is
line-for-line and still takes ideep::tensor/attr_t. As in ideep, the
forward hint comes from ideep::convolution_forward::get_primitive_desc.

Switch the backward call sites in mkldnn/Conv.cpp. Drop the fixed
algorithm parameter, the engine parameters, and backward_weights'
unused diff_weight_type branch.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Oct 29, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Port convolution_backward_data::compute_v2 and
convolution_backward_weights::compute_v2 (with its compute_impl) into
aten/src/ATen/native/mkldnn/detail/ConvBackward.{h,cpp}. The port is
line-for-line and still takes ideep::tensor/attr_t. As in ideep, the
forward hint comes from ideep::convolution_forward::get_primitive_desc.

Switch the backward call sites in mkldnn/Conv.cpp. Drop the fixed
algorithm parameter, the engine parameters, and backward_weights'
unused diff_weight_type branch.
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.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move ideep::softmax_forward, ideep::prelu_forward and
ideep::prelu_backward into aten/src/ATen/native/mkldnn/detail/
{Softmax,Prelu}.{h,cpp} and switch the callers in SoftMax.cpp and
Prelu.cpp. The port is line-for-line; prelu_backward drops ideep's unused
prop_kind parameter. ideep::softmax_backward has no ATen callers and is
not ported.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move the ideep lstm_forward_inference (compute and expected_weights_desc),
lstm_forward_training (prepare and compute) and lstm_backward operators
used by ATen into aten/src/ATen/native/mkldnn/detail/Lstm.{h,cpp} and
switch the callers in RNN.cpp and MKLDNNConversions.cpp. The port is
line-for-line for the code paths ATen uses, including ideep's u8 branch;
parameters that ATen never passed or ideep ignored are dropped.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests (all primitive create/exec lines identical before and after), and
by comparing the output of mkldnn._reorder_mkldnn_rnn_layer_weight across
24 configurations (byte-identical packed layouts and values).
@frost-intel
frost-intel force-pushed the ideep-removal/03-port-eltwise branch from 8b0ddac to 9d0548f Compare November 10, 2026 14:44
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move the ideep batch_normalization_forward_inference/forward_training/
backward and layer_normalization_forward operators used by ATen into
aten/src/ATen/native/mkldnn/detail/{BatchNorm,LayerNorm}.{h,cpp} and switch
the callers in Normalization.cpp. The port is line-for-line for the
code paths ATen uses; flags are fixed to ideep's defaults (the only values
ATen ever passed), so ideep's unused fused-relu/workspace branches and the
ignored momentum parameter are dropped.

Verified with ONEDNN_VERBOSE=1: the primitive create/exec log of
test_mkldnn.py and the mkldnn freezing tests is identical before and
after. A new test_mkldnn_layer_norm in test_freezing.py is added, since
not previously covered by tests.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055 (only the top commit is new).

Move the ideep inner_product_forward (compute, compute_binary,
expected_weights_desc), inner_product_backward_data and
inner_product_backward_weights code paths used by ATen into
aten/src/ATen/native/mkldnn/detail/InnerProduct.{h,cpp} and switch the
callers in Linear.cpp and MKLDNNConversions.cpp. The port is
line-for-line; ideep's private helpers keep their names. Primitive
descriptors still come from ideep's computation_cache with the same keys,
so the cache is shared with ideep until it is ported separately.

Verified with ONEDNN_VERBOSE=1: the primitive create/exec logs of
test_mkldnn.py, the mkldnn freezing tests, test_mkldnn_fusion.py and the
Inductor mkldnn linear pattern tests are identical before and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Port convolution_backward_data::compute_v2 and
convolution_backward_weights::compute_v2 (with its compute_impl) into
aten/src/ATen/native/mkldnn/detail/ConvBackward.{h,cpp}. The port is
line-for-line and still takes ideep::tensor/attr_t. As in ideep, the
forward hint comes from ideep::convolution_forward::get_primitive_desc.

Switch the backward call sites in mkldnn/Conv.cpp. Drop the fixed
algorithm parameter, the engine parameters, and backward_weights'
unused diff_weight_type branch.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055.

Move ideep::pooling_forward and ideep::pooling_backward into
aten/src/ATen/native/mkldnn/detail/Pooling.{h,cpp} and switch the callers
in Pooling.cpp. The port is line-for-line, including storing max-pool
indices as a workspace on the output tensor for use by the backward pass.
ideep::pooling_v2_* (dilated pooling) has no ATen callers and is not
ported.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
frost-intel added a commit to frost-intel/pytorch that referenced this pull request Nov 10, 2026
Part of pytorch#154444. Depends on pytorch#201055

Move ideep::sum, ideep::binary and ideep::direct_copy into
aten/src/ATen/native/mkldnn/detail/{Binary,DirectCopy}.{h,cpp} and switch
all CPU callers (add/add_/add_out, mul_out, copy_, clone, batch_norm
running-stat update). The port is line-for-line, including destination
reinit when the destination layout differs. It still operates on
ideep::tensor.

Verified with ONEDNN_VERBOSE=1 over test_mkldnn.py and the mkldnn freezing
tests: all 6572 distinct primitive create/exec lines are identical before
and after.
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
@frost-intel

Copy link
Copy Markdown
Collaborator Author

Moved to ghstack:
#205709

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)
This PR directly ports the element-wise operators from ideep into ATen. This includes:
relu, sigmoid, tanh, gelu, scalar mul, dense GELU, and JIT from scalar mul.

Code is a line-for-line port from ideep, with identical functionality. 'mkldnn' tests pass with identical behavior.

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

> `one_of` and `is_avx2_vnni_2`, the helpers the ported operators share, are added to the existing
> `aten/src/ATen/native/mkldnn/Utils.h`.
>
> Previously submitted as #201055.

Pull Request resolved: #205709
Approved by: https://github.com/albanD
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