Skip to content

Fix tf32 for real. - #41481

Merged
tensorflow-copybara merged 3 commits into
tensorflow:masterfrom
reedwm:tf32_actual_fix
Jul 20, 2020
Merged

tensorflow-copybara merged 3 commits into
tensorflow:masterfrom
reedwm:tf32_actual_fix

Conversation

@reedwm

@reedwm reedwm commented Jul 17, 2020

Copy link
Copy Markdown
Contributor

I thought I fixed this in #40957, but when I fixed the build error on Windows, I inadvertently caused tf32 to stop working again.

@reedwm
reedwm requested a review from av8ramit July 17, 2020 04:13
@google-ml-butler google-ml-butler Bot added the size:XS CL Change Size: Extra Small label Jul 17, 2020
@reedwm reedwm added the kokoro:force-run Tests on submitted change label Jul 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jul 17, 2020
@gbaned gbaned self-assigned this Jul 17, 2020
@reedwm

reedwm commented Jul 17, 2020

Copy link
Copy Markdown
Contributor Author

Ugh I still fail Linux CPU and MacOS CPU. I tested Windows CPU and Linux GPU and assumed that would be enough.

I will take a look tomorrow.

@av8ramit

Copy link
Copy Markdown

Are the failures related? Might be broken at HEAD. I'll force a rerun.

@av8ramit av8ramit added the kokoro:force-run Tests on submitted change label Jul 17, 2020
@kokoro-team kokoro-team removed kokoro:force-run Tests on submitted change labels Jul 17, 2020
@av8ramit

Copy link
Copy Markdown

So just to clarify, you're moving the dependency to if_static, but what if the user accesses the API from open source? What is the expected behavior?

@reedwm

reedwm commented Jul 17, 2020

Copy link
Copy Markdown
Contributor Author

The expected behavior is the API is always accessible and there is one copy of the global variable. In the static case, it will directly be linked in. In the dynamic case, it will be linked in libtensorflow_framework but not any pywrap_tensorflow_internal or any other shared libraries.

I think I fixed the issue, but we will see :)

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jul 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jul 17, 2020
@tensorflow-copybara
tensorflow-copybara merged commit 67f914e into tensorflow:master Jul 20, 2020
copybara-service Bot pushed a commit that referenced this pull request Apr 24, 2026
…r LayoutNormalization

Imported from GitHub PR openxla/xla#41481

📝 Summary of Changes
Fix intermittent RET_CHECK in xla/service/layout_normalization.cc:431 fail
hit by jax.nn.dot_product_attention(impl='xla') under multi-GPU pytest.

Root cause:
- When the autotuner picks hipBLASLt over Triton for a dot, GemmRewriter
  pins the __cublas$lt$matmul output to the canonical layout
  {n-1, ..., 1, 0}.
- Layout assignment had already planned the downstream reshape assuming
  a non-canonical layout, so after the pin the reshape is no longer a
  bitcast.
- LayoutNormalization then fails its ShapeUtil::ReshapeIsBitcast
  invariant and aborts.

Fix:
- Insert a ReshapeDecomposer pass before each post-GemmRewriter
  LayoutNormalization in gpu_compiler.cc.
- Any downstream non-bitcast reshape left behind by the layout pin is
  decomposed into transpose + bitcast, restoring the
  ReshapeIsBitcast invariant LayoutNormalization relies on.

Without this, many JAX tests fail intermittently with:
  RET_CHECK failure in external/xla/xla/service/layout_normalization.cc:431
whenever autotuning flips the dot backend to hipBLASLt.

🚀 Kind of Contribution
Please remove what does not apply: 🐛 Bug Fix

Copybara import of the project:

--
0214ff852a379a2549efcf123193a89e26a501e0 by magaonka <[email protected]>:

[XLA:GPU] Insert ReshapeDecomposer before post-GemmRewriter LayoutNormalization

Restores the bitcast-only invariant of LayoutNormalization on the cuBLAS-LT
custom-call path. After GemmRewriter pins a "__cublas$lt$matmul" output
layout to {n-1,...,1,0}, a downstream reshape whose layout was
consumer-pulled to a non-canonical permutation is no longer
bitcast-compatible. LayoutNormalization::HandleReshape RET_CHECKs on this.
Re-decompose any non-bitcast reshape so the precondition holds, mirroring
the existing ReshapeDecomposer that already runs before
LayoutNormalization at the cuDNN-conv site.

Both insertion sites are protected:

- After AddGemmRewriterPasses + GemmBroadcastFoldingRewriter (covers dots
  that GemmFusion declined to wrap in __triton_gemm).
- After AddConvAndGemmAutotuningPass + GemmBroadcastFoldingRewriter (covers
  dots that GemmFusion wrapped, where the autotuner later fissions back to
  __cublas$lt$matmul).

Merging this change closes #41481

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#41481 from magaonka-amd:fix/reshape-decomposer-before-layout-normalization 0214ff852a379a2549efcf123193a89e26a501e0
PiperOrigin-RevId: 904877102
copybara-service Bot pushed a commit that referenced this pull request Apr 24, 2026
…r LayoutNormalization

Imported from GitHub PR openxla/xla#41481

📝 Summary of Changes
Fix intermittent RET_CHECK in xla/service/layout_normalization.cc:431 fail
hit by jax.nn.dot_product_attention(impl='xla') under multi-GPU pytest.

Root cause:
- When the autotuner picks hipBLASLt over Triton for a dot, GemmRewriter
  pins the __cublas$lt$matmul output to the canonical layout
  {n-1, ..., 1, 0}.
- Layout assignment had already planned the downstream reshape assuming
  a non-canonical layout, so after the pin the reshape is no longer a
  bitcast.
- LayoutNormalization then fails its ShapeUtil::ReshapeIsBitcast
  invariant and aborts.

Fix:
- Insert a ReshapeDecomposer pass before each post-GemmRewriter
  LayoutNormalization in gpu_compiler.cc.
- Any downstream non-bitcast reshape left behind by the layout pin is
  decomposed into transpose + bitcast, restoring the
  ReshapeIsBitcast invariant LayoutNormalization relies on.

Without this, many JAX tests fail intermittently with:
  RET_CHECK failure in external/xla/xla/service/layout_normalization.cc:431
whenever autotuning flips the dot backend to hipBLASLt.

🚀 Kind of Contribution
Please remove what does not apply: 🐛 Bug Fix

Copybara import of the project:

--
0214ff852a379a2549efcf123193a89e26a501e0 by magaonka <[email protected]>:

[XLA:GPU] Insert ReshapeDecomposer before post-GemmRewriter LayoutNormalization

Restores the bitcast-only invariant of LayoutNormalization on the cuBLAS-LT
custom-call path. After GemmRewriter pins a "__cublas$lt$matmul" output
layout to {n-1,...,1,0}, a downstream reshape whose layout was
consumer-pulled to a non-canonical permutation is no longer
bitcast-compatible. LayoutNormalization::HandleReshape RET_CHECKs on this.
Re-decompose any non-bitcast reshape so the precondition holds, mirroring
the existing ReshapeDecomposer that already runs before
LayoutNormalization at the cuDNN-conv site.

Both insertion sites are protected:

- After AddGemmRewriterPasses + GemmBroadcastFoldingRewriter (covers dots
  that GemmFusion declined to wrap in __triton_gemm).
- After AddConvAndGemmAutotuningPass + GemmBroadcastFoldingRewriter (covers
  dots that GemmFusion wrapped, where the autotuner later fissions back to
  __cublas$lt$matmul).

Merging this change closes #41481

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#41481 from magaonka-amd:fix/reshape-decomposer-before-layout-normalization 0214ff852a379a2549efcf123193a89e26a501e0
PiperOrigin-RevId: 904877102
copybara-service Bot pushed a commit that referenced this pull request Apr 24, 2026
…r LayoutNormalization

Imported from GitHub PR openxla/xla#41481

📝 Summary of Changes
Fix intermittent RET_CHECK in xla/service/layout_normalization.cc:431 fail
hit by jax.nn.dot_product_attention(impl='xla') under multi-GPU pytest.

Root cause:
- When the autotuner picks hipBLASLt over Triton for a dot, GemmRewriter
  pins the __cublas$lt$matmul output to the canonical layout
  {n-1, ..., 1, 0}.
- Layout assignment had already planned the downstream reshape assuming
  a non-canonical layout, so after the pin the reshape is no longer a
  bitcast.
- LayoutNormalization then fails its ShapeUtil::ReshapeIsBitcast
  invariant and aborts.

Fix:
- Insert a ReshapeDecomposer pass before each post-GemmRewriter
  LayoutNormalization in gpu_compiler.cc.
- Any downstream non-bitcast reshape left behind by the layout pin is
  decomposed into transpose + bitcast, restoring the
  ReshapeIsBitcast invariant LayoutNormalization relies on.

Without this, many JAX tests fail intermittently with:
  RET_CHECK failure in external/xla/xla/service/layout_normalization.cc:431
whenever autotuning flips the dot backend to hipBLASLt.

🚀 Kind of Contribution
Please remove what does not apply: 🐛 Bug Fix

Copybara import of the project:

--
0214ff852a379a2549efcf123193a89e26a501e0 by magaonka <[email protected]>:

[XLA:GPU] Insert ReshapeDecomposer before post-GemmRewriter LayoutNormalization

Restores the bitcast-only invariant of LayoutNormalization on the cuBLAS-LT
custom-call path. After GemmRewriter pins a "__cublas$lt$matmul" output
layout to {n-1,...,1,0}, a downstream reshape whose layout was
consumer-pulled to a non-canonical permutation is no longer
bitcast-compatible. LayoutNormalization::HandleReshape RET_CHECKs on this.
Re-decompose any non-bitcast reshape so the precondition holds, mirroring
the existing ReshapeDecomposer that already runs before
LayoutNormalization at the cuDNN-conv site.

Both insertion sites are protected:

- After AddGemmRewriterPasses + GemmBroadcastFoldingRewriter (covers dots
  that GemmFusion declined to wrap in __triton_gemm).
- After AddConvAndGemmAutotuningPass + GemmBroadcastFoldingRewriter (covers
  dots that GemmFusion wrapped, where the autotuner later fissions back to
  __cublas$lt$matmul).

Merging this change closes #41481

FUTURE_COPYBARA_INTEGRATE_REVIEW=openxla/xla#41481 from magaonka-amd:fix/reshape-decomposer-before-layout-normalization 0214ff852a379a2549efcf123193a89e26a501e0
PiperOrigin-RevId: 904924797
copybara-service Bot pushed a commit that referenced this pull request Apr 24, 2026
…r LayoutNormalization

Imported from GitHub PR openxla/xla#41481

📝 Summary of Changes
Fix intermittent RET_CHECK in xla/service/layout_normalization.cc:431 fail
hit by jax.nn.dot_product_attention(impl='xla') under multi-GPU pytest.

Root cause:
- When the autotuner picks hipBLASLt over Triton for a dot, GemmRewriter
  pins the __cublas$lt$matmul output to the canonical layout
  {n-1, ..., 1, 0}.
- Layout assignment had already planned the downstream reshape assuming
  a non-canonical layout, so after the pin the reshape is no longer a
  bitcast.
- LayoutNormalization then fails its ShapeUtil::ReshapeIsBitcast
  invariant and aborts.

Fix:
- Insert a ReshapeDecomposer pass before each post-GemmRewriter
  LayoutNormalization in gpu_compiler.cc.
- Any downstream non-bitcast reshape left behind by the layout pin is
  decomposed into transpose + bitcast, restoring the
  ReshapeIsBitcast invariant LayoutNormalization relies on.

Without this, many JAX tests fail intermittently with:
  RET_CHECK failure in external/xla/xla/service/layout_normalization.cc:431
whenever autotuning flips the dot backend to hipBLASLt.

🚀 Kind of Contribution
Please remove what does not apply: 🐛 Bug Fix

Copybara import of the project:

--
0214ff852a379a2549efcf123193a89e26a501e0 by magaonka <[email protected]>:

[XLA:GPU] Insert ReshapeDecomposer before post-GemmRewriter LayoutNormalization

Restores the bitcast-only invariant of LayoutNormalization on the cuBLAS-LT
custom-call path. After GemmRewriter pins a "__cublas$lt$matmul" output
layout to {n-1,...,1,0}, a downstream reshape whose layout was
consumer-pulled to a non-canonical permutation is no longer
bitcast-compatible. LayoutNormalization::HandleReshape RET_CHECKs on this.
Re-decompose any non-bitcast reshape so the precondition holds, mirroring
the existing ReshapeDecomposer that already runs before
LayoutNormalization at the cuDNN-conv site.

Both insertion sites are protected:

- After AddGemmRewriterPasses + GemmBroadcastFoldingRewriter (covers dots
  that GemmFusion declined to wrap in __triton_gemm).
- After AddConvAndGemmAutotuningPass + GemmBroadcastFoldingRewriter (covers
  dots that GemmFusion wrapped, where the autotuner later fissions back to
  __cublas$lt$matmul).

Merging this change closes #41481

PiperOrigin-RevId: 904952544
pull Bot pushed a commit to A-Archives-and-Forks/tensorflow that referenced this pull request May 6, 2026
…Normalization in AutotunerAndPostCleanup

Imported from GitHub PR openxla/xla#41980

📝 Summary of Changes
Add the missing pipeline.AddPass<ReshapeDecomposer>() before LayoutNormalization in GpuCompiler::AutotunerAndPostCleanup — the third call site introduced by xla 6874dd2 without ReshapeDecomposer, mirroring the inline pattern at the three pre-existing sites. One-line change.

🎯 Justification
tensorflow#41481 added ReshapeDecomposer ahead of two LayoutNormalization sites to prevent a RET_CHECK when GemmRewriter pins a __cublas$lt$matmul output and a downstream reshape becomes non-bitcast. xla 6874dd23a1 added a third LayoutNormalization site without the precondition and reopened the bug, most visibly on ROCm under multi-process pytest (tests/nn_test.py::testDotProductAttention*, tests/pallas/gpu_paged_attention_test.py).

AutotunerAndPostCleanup is the autotuner's boundary in the main pipeline: FissionBackend::ApplyConfig + InlineFissionedComputation can re-introduce a non-bitcast reshape there when the hipBLASLt candidate wins. Only that LayoutNormalization invocation is downstream of the layout shift, so the cleanup belongs at exactly that one site.

The fix preserves --xla_disable_hlo_passes=reshape-decomposer (no encapsulation) and stays in a single named pipeline (no HLO-dump pollution).

🚀 Kind of Contribution
🐛 Bug Fix

🧪 Execution Test
xla/tools/run_hlo_module on the jit_dot_general HLO from jax.nn.dot_product_attention(impl='xla'), using the cuBLAS-LT-first hack from #817 + XLA_FLAGS=--xla_gpu_autotune_level=0 to deterministically force the failing path on a single MI355X gfx950.
Copybara import of the project:

--
94b1d0cf77c759a40830902af3815b56cfc32019 by Ruturaj4 <[email protected]>:

[XLA:GPU] Insert ReshapeDecomposer before LayoutNormalization in AutotunerAndPostCleanup

Restores LayoutNormalization::HandleReshape's ShapeUtil::ReshapeIsBitcast
precondition on the GpuCompiler::AutotunerAndPostCleanup path. PR tensorflow#41481
(commit 788f269) added ReshapeDecomposer before two LayoutNormalization
invocations in xla/service/gpu/gpu_compiler.cc to satisfy that
precondition after GemmRewriter pins __cublas$lt$matmul output layouts
to {n-1,...,1,0}. Commit 6874dd2 ("Move gemm-conv autotuner pass after
fusion passes behind a flag.") introduced a third LayoutNormalization
invocation inside the new AutotunerAndPostCleanup helper without a
matching ReshapeDecomposer, reopening the RET_CHECK whenever the
autotuner fissions __triton_gemm back to __cublas$lt$matmul.

Add the missing ReshapeDecomposer call, mirroring the inline pattern at
the three pre-existing sites. AutotunerAndPostCleanup is the autotuner's
boundary in the main pipeline; FissionBackend::ApplyConfig +
InlineFissionedComputation can re-introduce a non-bitcast reshape there
when the hipBLASLt candidate wins, and only that LayoutNormalization
invocation is downstream of the layout shift. The fix preserves
`--xla_disable_hlo_passes=reshape-decomposer` (no encapsulation) and stays
in a single named pipeline (no HLO-dump pollution).

Reproduces the original 41481 failure mode on ROCm under multi-process
pytest (tests/nn_test.py::testDotProductAttention*,
tests/pallas/gpu_paged_attention_test.py) once the autotuner picks the
hipBLASLt fission backend. See PR #817's cuBLAS-LT-first patch +
`XLA_FLAGS=--xla_gpu_autotune_level=0` for a deterministic single-process
reproducer.

Co-authored-by: magaonka <[email protected]>

Merging this change closes tensorflow#41980

PiperOrigin-RevId: 911205496
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes ready to pull PR ready for merge process size:XS CL Change Size: Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants