Skip to content

Conversation

AleksaArsic
Copy link

@AleksaArsic AleksaArsic commented Aug 12, 2025

Motivation

The command bazel test -s --config=rocm //tensorflow/python/kernel_tests/nn_ops:ctc_loss_op_test_gpu will produce failure of CTCLossDeterministicTest.testForwardAndBackward on gfx11xx and gfx12xx. The failure occured due to one element that represents the difference between gradients is greater than the previous absolute tolerance.

Log:

======================================================================
FAIL: testForwardAndBackward2 (True, False) (__main__.CTCLossDeterministicTest) [graph_mode]
CTCLossDeterministicTest.testForwardAndBackward2 (True, False)
testForwardAndBackward(True, False)
----------------------------------------------------------------------
...
Mismatched elements: 1 / 32000 (0.00313%)
Max absolute difference among violations: 7.075071e-05
Max relative difference among violations: 0.00036804
...
======================================================================
FAIL: testForwardAndBackward3 (True, True) (__main__.CTCLossDeterministicTest) [graph_mode]
CTCLossDeterministicTest.testForwardAndBackward3 (True, True)
testForwardAndBackward(True, True)
----------------------------------------------------------------------
...
Mismatched elements: 1 / 32000 (0.00313%)
Max absolute difference among violations: 5.2332878e-05
Max relative difference among violations: 0.00028655
...
----------------------------------------------------------------------

Technical Details

Increase the absolute tolerance between gradients in CTCLossDeterministicTest.testForwardAndBackward due to the floating-point arithmetic.

@AleksaArsic AleksaArsic marked this pull request as ready for review August 12, 2025 15:46
@AleksaArsic AleksaArsic requested a review from i-chaochen August 12, 2025 15:46
i-chaochen

This comment was marked as duplicate.

@AleksaArsic AleksaArsic force-pushed the fix-ctc-loss-op-test-fail branch 3 times, most recently from 0d3905b to c8301b6 Compare August 19, 2025 20:17
@AleksaArsic AleksaArsic force-pushed the fix-ctc-loss-op-test-fail branch from c8301b6 to 1fce875 Compare August 20, 2025 08:01
…sticTest.testForwardAndBackward due to the floating-point arithmetics for gfx11xx and gfx12xx. Implement test_util.gpu_gcn_arch() which returns the information on the current gcn architecture. Implement unit test for test_util.gpu_gcn_arch(). Modify GetShortDeviceDescription() in gpu_device.cc to return gcn arch as well.
@AleksaArsic AleksaArsic force-pushed the fix-ctc-loss-op-test-fail branch from 1fce875 to 574fddb Compare August 20, 2025 08:02
@@ -1970,6 +1970,7 @@ static string GetShortDeviceDescription(
#elif TENSORFLOW_USE_ROCM
return strings::StrCat("device: ", platform_device_id.value(),
", name: ", desc.name(),
", gcn arch: ", desc.rocm_compute_capability().gcn_arch_name(),
Copy link

@ScXfjiang ScXfjiang Aug 20, 2025

Choose a reason for hiding this comment

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

Would it be better if we use the same key-value pairs as CUDA, though they return the same thing?

compute capability: desc.rocm_compute_capability().ToString()

Copy link
Author

@AleksaArsic AleksaArsic Aug 21, 2025

Choose a reason for hiding this comment

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

Here we return a specific part of the compute capability; therefore I've used getter specific for returning the gcn_arch_name.
Otherwise, if we inspect device_description.h we can observe that CudaComputeCapability has method ToString() that returns the version of the software in a format "major"."minor". Inspecting RocmComputeCapability we can see that there is no equivalent method in it. Nevertheless, it would not fit our needs. :)

@@ -189,6 +189,29 @@ def gpu_device_name() -> str:
return compat.as_str(x.name)
return ""

@tf_export("test.gpu_gcn_arch")

Choose a reason for hiding this comment

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

Does CUDA have the counterpart? What's the behavior if this API is called on the CUDA platform?

Should we add the rocm_ prefix here?

Copy link
Author

Choose a reason for hiding this comment

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

If this method is called on a system with CUDA support, it will just return empty string, as the CUDA description is not the same as the the ROCm one.

We could be more descriptive with the name and detail design comment.

Copy link
Collaborator

@i-chaochen i-chaochen left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants