fix(tf2xla): register EuclideanNorm reduction OpKernel by adi-IL · Pull Request #126936 · tensorflow/tensorflow · GitHub
Skip to content

fix(tf2xla): register EuclideanNorm reduction OpKernel - #126936

Merged
copybara-service[bot] merged 4 commits into
tensorflow:masterfrom
adi-IL:fix-tf2xla-euclidean-norm
Sep 10, 2026
Merged

copybara-service[bot] merged 4 commits into
tensorflow:masterfrom
adi-IL:fix-tf2xla-euclidean-norm

Conversation

@adi-IL

@adi-IL adi-IL commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Why

In commit 8e01ae8 (August 2020), an inverted commit during an automated import accidentally removed the EuclideanNormOp kernel registration, the PreprocessInput hook on XlaReductionOp, and testReduceEuclideanNorm from tf2xla.

Since then, compiling any graph containing tf.math.reduce_euclidean_norm under XLA (jit_compile=True) fails with InvalidArgumentError: Detected unsupported operations when trying to compile graph ... on XLA_CPU_JIT: EuclideanNorm (No registered 'EuclideanNorm' OpKernel for XLA_CPU_JIT devices compatible with node).

This patch restores the PreprocessInput extension point to XlaReductionOp and registers the EuclideanNorm reduction OpKernel in tf2xla.

Scope

  • In tensorflow/compiler/tf2xla/kernels/reduction_ops.h, added virtual xla::XlaOp PreprocessInput(xla::XlaBuilder* builder, const xla::XlaOp& data) with default pass-through behavior.
  • In tensorflow/compiler/tf2xla/kernels/reduction_ops_common.cc, implemented default PreprocessInput and called it in XlaReductionOp::Compile prior to the reduction computation.
  • In tensorflow/compiler/tf2xla/kernels/reduction_ops.cc, implemented and registered EuclideanNormOp using xla::Mul(data, xla::MaybeConjugate(data, true)) in PreprocessInput, xla::Add in BuildReducer, and xla::Sqrt in BuildFinalizer.
  • In tensorflow/compiler/tests/reduce_ops_test.py, restored testReduceEuclideanNorm covering float32 and float64.

Blast Radius

This change affects the XLA lowering path for EuclideanNorm. Standard non-XLA execution paths are unaffected. Existing reductions (Sum, Prod, Min, Max, Mean, All, Any) inherit the default PreprocessInput pass-through with no behavioral changes.

Verification

  • Minimal reproduction script verified red before change with InvalidArgumentError: No registered 'EuclideanNorm' OpKernel for XLA_CPU_JIT devices.
  • Unit test in tensorflow/compiler/tests/reduce_ops_test.py validates reduction across axes against a NumPy reference implementation for float32 and float64.

@google-ml-butler google-ml-butler Bot added the size:M CL Change Size: Medium label Sep 6, 2026
@keerthanakadiri
keerthanakadiri requested a review from a team September 7, 2026 04:15
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Sep 7, 2026
@github-project-automation github-project-automation Bot moved this to Assigned Reviewer in PR Queue Sep 7, 2026
@keerthanakadiri

Copy link
Copy Markdown
Contributor

@dmiltr3 dmiltr3 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.

Thanks for restoring the EuclideanNormOp kernel registration!

The GitHub CI tests (e.g., Linux x86 CUDA) have failed during compilation. Our internal local validation shows that the compilation fails with error: no member named 'MaybeConjugate' in namespace 'xla'.

To fix this, could you please add the following includes to tensorflow/compiler/tf2xla/kernels/reduction_ops.cc:

#include "xla/hlo/builder/lib/math.h"
#include "xla/primitive_util.h"

You might also need to update the Bazel .BUILD dependencies for reduction_ops to include //tensorflow/compiler/xla/hlo/builder/lib:math to resolve linker/compilation errors.

Once you have pushed those fixes, we'll rerun tests and get this merged!

@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Reviewer Requested Changes in PR Queue Sep 8, 2026
@adi-IL

adi-IL commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @dmiltr3. Pushed two commits:

  1. 5177b47. reduction_ops BUILD now depends on @xla//xla/hlo/builder/lib:math (needed for xla::MaybeConjugate). The #includes for math.h and primitive_util.h were already on the branch; primitive_util comes through existing @xla//xla:shape_util.
  2. 5ac4a15. added EuclideanNorm to the RED entry in GetAllowlistTable() so XlaCompilationTest.XLALiteAllowlist does not trip on the new registration (same gate as fix(tf2xla): register XLA OpKernels for BesselI0 and BesselI1 #126935).

CI should rebuild on the new tip.

@dmiltr3
dmiltr3 self-requested a review September 8, 2026 13:45
@google-ml-butler google-ml-butler Bot added the kokoro:force-run Tests on submitted change label Sep 8, 2026
@github-project-automation github-project-automation Bot moved this from Reviewer Requested Changes to Approved by Reviewer in PR Queue Sep 8, 2026
@google-ml-butler google-ml-butler Bot added the ready to pull PR ready for merge process label Sep 8, 2026
@nithyak0204 nithyak0204 removed awaiting review Pull request awaiting review kokoro:force-run Tests on submitted change labels Sep 9, 2026

@dmiltr3 dmiltr3 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.

Thank you for your contribution!

While the automated test suite passed, the PR cannot be merged yet due to an upstream merge conflict in tensorflow/compiler/jit/mark_for_compilation_pass.cc.

Root Cause

PR #126935 was recently merged into upstream master, which added BesselI0 and BesselI1 to GetAllowlistTable() in tensorflow/compiler/jit/mark_for_compilation_pass.cc. This causes a conflict with the changes on this branch that add EuclideanNorm.

Required Fix

Please rebase your branch on the latest upstream master and ensure both changes are retained in tensorflow/compiler/jit/mark_for_compilation_pass.cc:

git fetch upstream
git rebase upstream/master

In tensorflow/compiler/jit/mark_for_compilation_pass.cc, verify that GetAllowlistTable() retains both BesselI0/BesselI1 in the unary ops list and EuclideanNorm in the reduction ops list:

// Unary / pointwise allowlist (from #126935):
"Lgamma", "Digamma", "BesselI0", "BesselI1",

// Reduction allowlist:
{"All", "Any", "Min", "Max", "Mean", "Prod", "Sum", "EuclideanNorm"}},

Once rebased, please push the updated branch to GitHub so our automated synchronization pipeline can cleanly import and complete the merge.

@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Reviewer Requested Changes in PR Queue Sep 10, 2026
adi-IL and others added 4 commits September 10, 2026 18:13
Compilation failed with no member MaybeConjugate in namespace xla.
Includes were present; reduction_ops BUILD lacked @xla//xla/hlo/builder/lib:math.
Newly registered XLA EuclideanNorm must appear in GetAllowlistTable.
Add it to the RED category with Sum/Prod/Mean.
@adi-IL
adi-IL force-pushed the fix-tf2xla-euclidean-norm branch from 5ac4a15 to c51805a Compare September 10, 2026 12:43
@google-ml-butler google-ml-butler Bot removed the ready to pull PR ready for merge process label Sep 10, 2026
@adi-IL

adi-IL commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased

@nithyak0204
nithyak0204 requested a review from dmiltr3 September 10, 2026 14:45
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Sep 10, 2026

@dmiltr3 dmiltr3 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.

The C++ changes introduced in this PR look good and provide the missing includes to correctly build reduction_ops targets. I successfully verified the code in Google's internal TAP CI, and it builds properly out-of-the-box.

I noticed a couple of our longer-running CI targets timed out during my verify (//learning/brain/google/client:remote_session_test_gpu and //third_party/tensorflow/python/data/kernel_tests:repeat_test), but these timeouts appear to be pre-existing infrastructure flakiness totally unrelated to your changes. Therefore I'm approving this PR to go ahead. Thank you for the contribution!

@google-ml-butler google-ml-butler Bot added the kokoro:force-run Tests on submitted change label Sep 10, 2026
@google-ml-butler google-ml-butler Bot added the ready to pull PR ready for merge process label Sep 10, 2026
@github-project-automation github-project-automation Bot moved this from Reviewer Requested Changes to Approved by Reviewer in PR Queue Sep 10, 2026
@adi-IL

adi-IL commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@copybara-service
copybara-service Bot merged commit 5d2d621 into tensorflow:master Sep 10, 2026
17 of 18 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Sep 10, 2026
@nithyak0204 nithyak0204 removed the awaiting review Pull request awaiting review label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kokoro:force-run Tests on submitted change ready to pull PR ready for merge process size:M CL Change Size: Medium

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

5 participants