← Back to Pull requests

[WIP] IFU dev 20261110 v2.22 (upstream 1f251a125) #802

Open
wangye805 opened this pull request with 47760 lines diff across 325 files
View on GitHub
wangye805 wangye805 commented on Nov 12, 2026 15:18 UTC
Author

[agent reply]

Description

Work-in-progress IFU of upstream NVIDIA TransformerEngine main at 1f251a125 (2026-11-10, version 2.22.0.dev0) into ROCm dev at b5c00f432.
The previous IFU, #771, synced to upstream c72db38aa, so this brings in 92 upstream commits.
All 17 commits of upstream release_v2.21 (v2.21.0) are already on main before 1f251a125, so no release-branch cherry-picks are needed.

This is a draft opened to review the first conflict-resolution commit.
It is not ready to merge, and no ci-level label is set: the pytorch and jax files still carry conflict markers.

How the commits are organized

| commit | content | review |
|---|---|---|
| upstream c72db38aa..1f251a125 | upstream history, unchanged | no |
| 2b3c3939e | the merge of 1f251a125, committed as-is with its conflict markers (36 files) and 3 unresolved modify/delete conflicts, so that every resolution below is its own diff; does not build | no |
| 164c10b59 | stage 1: transformer_engine/common and tests/cpp | this round |
| next | stage 2: pytorch extension, pytorch tests, build configuration | pending |
| next | stage 3: jax and jax tests | pending |

Each stage resolves the conflicts of one layer and is validated by that layer's tests before the next starts.
Following the team's development process, the ROCm commits will be squashed into one before merging, in a separate PR merged with "Create a merge commit", so the upstream history is preserved.

Stage 1 (164c10b59)

The commit message lists every resolution file by file; the points a reviewer most likely wants to check:

  • Enum numbering. Both sides added value 11 to NVTEGroupedTensorParam. Upstream's kNVTEGroupedRowScaledNVFP4 keeps 11 and the ROCm MXFP4 shuffle parameters move to 12 and 13, after upstream's values, as ROCm already does in NVTETensorParam. Every use is by name.

  • Requantize port. Upstream #3560 replaced cast/fused_group_requantize.cu with cast/mxfp8/requantize_mxfp8.cu and changed nvte_group_requantize to take grouped tensors, with the caller declaring the output scale layout. The ROCm dispatch moves into the new file and keeps using the existing ROCm kernel, which now also accepts absent tensor offsets and an absent rowwise scale output.

  • Upstream #3743 adopted. An MXFP8 block of 32 values that are all NaN now gets scale 0xFF (the E8M0 NaN code) instead of 0x00, matching CUDA. The ROCm quantize kernel seeds its per-block amax with NaN, with the same three changes as the upstream kernel.

  • pybind_helper.h is resolved in this stage although only the pytorch extension uses it: the hipify pass over transformer_engine/common reads it and fails on conflict markers.
  • New upstream features disabled on ROCm in this IFU

    Each fails with an explicit NVTE_ERROR or a test skip that states the reason; enabling them would need ROCm kernel work outside this IFU.

    | feature | upstream PR |
    |---|---|
    | requantize with GEMM-swizzled output scales | #3560 |
    | requantize with groups whose last dimension differs | #3560 |
    | strided batched GEMM (nvte_cublas_gemm_strided_batched{,_mxfp8}) | #3160 |
    | grouped row-scaled NVFP4 quantization | #3649 |
    | block-scaling to MXFP8 scale swizzle (the source file was already CUDA-only on ROCm) | #3614 |

    Testing

    MI355X (gfx950), CI image from ci/ci_config.json (te-ci:therock_10.1.0_ubuntu24.04_py3.14_pytorch_2.13.0_...).

    setup.py cannot run at this stage because the pytorch and jax build files are still conflicted, so libtransformer_engine.so was built by replaying the CMake configure, build and install commands that pip install -v --no-build-isolation . runs on dev, with the same environment (ROCM_PATH from rocm-sdk path --root, NVTE_ROCM_ARCH=gfx950).
    On dev, the replay's 117 compile commands are identical to pip's after path normalization, and the exported symbols match.
    tests/cpp was built against that library and run the way ci/core.sh does: ctest -j4 --timeout 300, non-GEMM and GEMM suites separately.

    | | non-GEMM | GEMM |
    |---|---|---|
    | dev b5c00f432 (baseline) | 9334 / 9334 | 3965 / 3965 |
    | this branch, full run before the #3743 kernel change | 9326 / 9350 | 3965 / 3965 |
    | this branch at 164c10b59, MXFP8 tests rerun | 7152 / 7152 | not rerun |

    The 24 failures in the full run were all FusedCastMXFP8TestSuite exceptional-input cases where an activation derivative of ±inf yields an all-NaN block: the kernel wrote scale 0x00, the updated reference expects 0xFF.
    After the kernel change only the MXFP8 tests, the ones that kernel serves, were rerun.
    The test count grows from 9334 to 9350 with upstream's new tests.

    Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Infra/Build change

  • Code refactoring
  • Checklist:

  • I have read and followed the contributing guidelines

  • The functionality is complete

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • My changes generate no new warnings

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes
  • 🤖 Generated with Claude Code

    Diff: 47760 lines (+38206 / -9554) across 325 files Reviewer: wangye805 Review duration: 7746m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.86) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.86 · 47760 lines diff across 325 files
    0.86
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.56 · 5 substantive comment(s)
    0.56
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    68%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    30 items
    wangye805 wangye805 commented on code on Nov 12, 2026 15:25 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -17,23 +17,14 @@ add_executable(test_operator
                    test_cast_mxfp8_grouped.cu
                    test_cast_mxfp8_grouped_scaled_swiglu.cu
                    test_cast_nvfp4_transpose.cu
    -<<<<<<< HEAD
                    test_row_scaled_nvfp4_grouped_amax.cu #CUDA-only test
    -=======
    -               test_row_scaled_nvfp4_grouped_amax.cu
    -               test_row_scaled_nvfp4_grouped_cast.cu
    ->>>>>>> 1f251a125
    +               test_row_scaled_nvfp4_grouped_cast.cu #CUDA-only test

    What does cuda only test mean? It cannot be run in rocm? If so, why not we just exclude it from add_executable with ifdef?

    wangye805 wangye805 commented on code on Nov 12, 2026 15:27 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -17,23 +17,14 @@ add_executable(test_operator
                    test_cast_mxfp8_grouped.cu
                    test_cast_mxfp8_grouped_scaled_swiglu.cu
                    test_cast_nvfp4_transpose.cu
    -<<<<<<< HEAD
                    test_row_scaled_nvfp4_grouped_amax.cu #CUDA-only test
    -=======
    -               test_row_scaled_nvfp4_grouped_amax.cu
    -               test_row_scaled_nvfp4_grouped_cast.cu
    ->>>>>>> 1f251a125
    +               test_row_scaled_nvfp4_grouped_cast.cu #CUDA-only test
                    test_cast_float8blockwise.cu
                    test_cast_float8blockwise_grouped.cu #CUDA-only test
                    test_dequantize_mxfp8.cu
                    test_dequantize_mxfp8_grouped.cu
    -<<<<<<< HEAD
    -               test_fused_group_requantize_mxfp8.cu

    Is this a new test file added by nv upstream? If so, you cannot remove it directly here. You should guard it with ifdef, make it not possible to run in our rocm env

    wangye805 wangye805 commented on code on Nov 12, 2026 15:27 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -55,7 +46,7 @@ add_executable(test_operator
                    test_causal_softmax.cu
                    test_swizzle.cu
                    test_multi_swizzle.cu
    -               test_swizzle_block_scaling.cu
    +               test_swizzle_block_scaling.cu #CUDA-only test

    Again, I don't know why you add this cuda-only test flag for

    wangye805 wangye805 commented on code on Nov 12, 2026 15:28 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -66,6 +57,8 @@ if(USE_ROCM)
       list(REMOVE_ITEM test_cuda_sources
                   test_grouped_gemm.cu
                   test_row_scaled_nvfp4_grouped_amax.cu
    +              test_row_scaled_nvfp4_grouped_cast.cu

    Okay, so you have the tool to correctly remove cuda only item, then please do not edit the above add_execute with ifdef?

    wangye805 wangye805 commented on code on Nov 12, 2026 15:29 UTC
    Code Review
    tests/cpp/operator/test_fused_group_requantize_mxfp8.cu:1

    Why you delete it?

    wangye805 wangye805 commented on code on Nov 12, 2026 16:14 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -17,23 +17,14 @@ add_executable(test_operator
                    test_cast_mxfp8_grouped.cu
                    test_cast_mxfp8_grouped_scaled_swiglu.cu
                    test_cast_nvfp4_transpose.cu
    -<<<<<<< HEAD
                    test_row_scaled_nvfp4_grouped_amax.cu #CUDA-only test
    -=======
    -               test_row_scaled_nvfp4_grouped_amax.cu
    -               test_row_scaled_nvfp4_grouped_cast.cu
    ->>>>>>> 1f251a125
    +               test_row_scaled_nvfp4_grouped_cast.cu #CUDA-only test

    [agent reply]

    #CUDA-only test was only a comment, copied from the existing entries; it did not exclude anything. The ROCm exclusion is the list(REMOVE_ITEM ...) in the if(USE_ROCM) block below. Removed in 2fdc920, so this line matches upstream again.

    wangye805 wangye805 commented on code on Nov 12, 2026 16:14 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -55,7 +46,7 @@ add_executable(test_operator
                    test_causal_softmax.cu
                    test_swizzle.cu
                    test_multi_swizzle.cu
    -               test_swizzle_block_scaling.cu
    +               test_swizzle_block_scaling.cu #CUDA-only test

    [agent reply]

    #CUDA-only test was only a comment, copied from the existing entries; it did not exclude anything. The ROCm exclusion is the list(REMOVE_ITEM ...) in the if(USE_ROCM) block below. Removed in 2fdc920, so this line matches upstream again.

    wangye805 wangye805 commented on code on Nov 12, 2026 16:14 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -17,23 +17,14 @@ add_executable(test_operator
                    test_cast_mxfp8_grouped.cu
                    test_cast_mxfp8_grouped_scaled_swiglu.cu
                    test_cast_nvfp4_transpose.cu
    -<<<<<<< HEAD
                    test_row_scaled_nvfp4_grouped_amax.cu #CUDA-only test
    -=======
    -               test_row_scaled_nvfp4_grouped_amax.cu
    -               test_row_scaled_nvfp4_grouped_cast.cu
    ->>>>>>> 1f251a125
    +               test_row_scaled_nvfp4_grouped_cast.cu #CUDA-only test
                    test_cast_float8blockwise.cu
                    test_cast_float8blockwise_grouped.cu #CUDA-only test
                    test_dequantize_mxfp8.cu
                    test_dequantize_mxfp8_grouped.cu
    -<<<<<<< HEAD
    -               test_fused_group_requantize_mxfp8.cu

    [agent reply]

    Not removed for ROCm: upstream removed it. NVIDIA/TransformerEngine#3560 (a66371a54) deleted test_fused_group_requantize_mxfp8.cu and added test_requantize_mxfp8_grouped.cu at this position, so this list matches upstream 1f251a125 here. The old test calls the old nvte_group_requantize signature, which no longer exists, so it would not compile on either platform. Its ROCm adaptations moved into the new test under __HIP_PLATFORM_AMD__.

    wangye805 wangye805 commented on code on Nov 12, 2026 16:14 UTC
    Code Review
    tests/cpp/operator/CMakeLists.txt:1
    @@ -66,6 +57,8 @@ if(USE_ROCM)
       list(REMOVE_ITEM test_cuda_sources
                   test_grouped_gemm.cu
                   test_row_scaled_nvfp4_grouped_amax.cu
    +              test_row_scaled_nvfp4_grouped_cast.cu

    [agent reply]

    Agreed. REMOVE_ITEM is now the only ROCm exclusion: in 2fdc920 the add_executable list matches upstream exactly, including the five older entries that carried #CUDA-only test comments from previous IFUs.

    wangye805 wangye805 commented on code on Nov 12, 2026 16:14 UTC
    Code Review
    tests/cpp/operator/test_fused_group_requantize_mxfp8.cu:1

    [agent reply]

    This was a modify/delete conflict: ROCm had edited the file, and upstream deleted it in NVIDIA/TransformerEngine#3560, replacing it with test_requantize_mxfp8_grouped.cu. Keeping it is not possible because it targets the old nvte_group_requantize signature. The new test runs on ROCm: on MI355X 67 of its 147 cases pass and 80 skip, namely the GEMM-swizzled-output and varying-last-dimension cases that ROCm does not support yet.

    wangye805 wangye805 commented on code on Nov 12, 2026 16:55 UTC
    Code Review
    tests/cpp/operator/test_fused_group_requantize_mxfp8.cu:1

    If it was deleted in NV upstream, why this file deletion is not picked up by your merge as it is commit?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:27 UTC
    Code Review
    tests/cpp/operator/test_fused_group_requantize_mxfp8.cu:1

    [agent reply]

    Because the file was edited on both sides. Since the previous IFU's base c72db38aa, ROCm dev had changed it (e942d0df9, 171fcdb64) while upstream deleted it. Git applies a deletion automatically only when the other side left the file untouched; otherwise it reports a modify/delete conflict and leaves the modified version in the tree (CONFLICT (modify/delete): tests/cpp/operator/test_fused_group_requantize_mxfp8.cu deleted in 1f251a125 and modified in HEAD. Version HEAD of ... left in tree.).

    A modify/delete conflict has no conflict markers that could be committed as-is, so the raw merge commit 2b3c3939e had to carry one version. It kept git's default, the ROCm one, and its commit message lists all three such files and which version was kept. Taking upstream's deletion is the resolution in 164c10b59. transformer_engine/common/cast/fused_group_requantize.cu went the same way.

    wangye805 wangye805 commented on code on Nov 17, 2026 20:30 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -297,9 +299,11 @@ TEST(GroupedRequantizeTest, RejectsUnsupportedScalingModes) {
     }
     
     TEST(GroupedRequantizeTest, OptionalRowwiseOutputsAndAliasRules) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif

    Emm, previously we skip this test and now you enabled it? If so, do you add them to ci and can it pass ci

    wangye805 wangye805 commented on code on Nov 17, 2026 20:33 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -359,9 +376,11 @@ TEST(GroupedRequantizeTest, OptionalRowwiseOutputsAndAliasRules) {
     }
     
     TEST(GroupedRequantizeTest, BF16IntermediateIgnoresFastMath) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif

    Similar question: do we disable it before and you enable it now? Do you add them into ci and can it pass ci?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:34 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -400,16 +419,26 @@ TEST(GroupedRequantizeTest, BF16IntermediateIgnoresFastMath) {
     }
     
     TEST_P(GroupedRequantizeMXFP8TestSuite, MatchesDequantizeThenQuantize) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif
     
       const auto &test_case = std::get<0>(GetParam());
       const DType input_dtype = std::get<1>(GetParam());
       const bool return_dequantized = std::get<2>(GetParam());
       const bool output_swizzled = std::get<3>(GetParam());
       const DType intermediate_dtype = DType::kBFloat16;
       const GroupShapeInfo shape_info = make_shape_info(test_case);
    +#ifdef __HIP_PLATFORM_AMD__
    +  if (output_swizzled) {
    +    GTEST_SKIP() << "ROCm writes compact requantization output scales only";
    +  }
    +  if (!shape_info.same_last_dim) {
    +    GTEST_SKIP() << "ROCm requantization requires groups that share the hidden dimension";
    +  }
    +#endif

    Does those two guards have the entire coverage of MatchesDequantizeThenQuantize?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:35 UTC
    Code Review
    tests/cpp/test_common.h:1
    @@ -119,20 +119,10 @@ struct TypeInfo {
         struct Helper {
             constexpr static DType getType() {
                 constexpr int i = static_cast<int>(current);
    -<<<<<<< HEAD
    -            // DType may list more types than this build provides (e.g. FP8 UE5M3 needs CUDA 13.4)
    -            if constexpr (i >= static_cast<int>(std::tuple_size<types>::value)) {
    -                return DType::kNumTypes;
    -            } else if constexpr (std::is_same<U, typename std::tuple_element<i, types>::type>::value) {
    -                return current;
    -            } else {
    -                return Helper<U, static_cast<DType>(i + 1)>::getType();
    -=======
                 if constexpr (i < static_cast<int>(std::tuple_size<types>::value)) {
                     if (std::is_same<U, typename std::tuple_element<i, types>::type>::value) {
                         return current;
                     }
    ->>>>>>> 1f251a125

    Just want to make sure, this is entire NV upstream changes?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:36 UTC
    Code Review
    tests/cpp/util/CMakeLists.txt:1
    @@ -30,10 +30,6 @@ endif()
     target_compile_options(test_util PRIVATE -O2 -fopenmp)
     
     include(GoogleTest)
    -<<<<<<< HEAD
    -gtest_discover_tests(test_util PROPERTIES DISCOVERY_TIMEOUT 600)
    -=======
     # MALLOC_PERTURB_ makes glibc overwrite freed memory, so a destructor that reads a destroyed object
     # at exit crashes the test process, which ctest reports as a failure, instead of passing silently.
     gtest_discover_tests(test_util DISCOVERY_TIMEOUT 600 PROPERTIES ENVIRONMENT "MALLOC_PERTURB_=165")
    ->>>>>>> 1f251a125

    Just want to make sure, is this entirely NV upstream changes?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:52 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/requantize_mxfp8.cu:1
    @@ -851,9 +865,15 @@ void group_requantize(const GroupedTensor &input, GroupedTensor *output, Tensor
                  "Input and output grouped shape representations must match.");
       NVTE_CHECK(input.data.dptr != output->columnwise_data.dptr,
                  "In-place MXFP8 data requantization is not supported.");
    +#ifdef __HIP_PLATFORM_AMD__
    +  NVTE_CHECK(is_aligned_ptr(input.data.dptr, ROCM_VEC_BYTES) &&
    +                 is_aligned_ptr(output->columnwise_data.dptr, ROCM_VEC_BYTES),
    +             "Input and output data pointers must be 16-byte aligned.");

    ROCM_VEC_BYTES and TMA_GEMM_ALIGNMENT happen to be the same?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:53 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/requantize_mxfp8.cu:1
    @@ -888,6 +908,35 @@ void group_requantize(const GroupedTensor &input, GroupedTensor *output, Tensor
       const int64_t *const first_dims_ptr = reinterpret_cast<const int64_t *>(input.first_dims.dptr);
       const int64_t *const last_dims_ptr = reinterpret_cast<const int64_t *>(input.last_dims.dptr);
     
    +#ifdef __HIP_PLATFORM_AMD__
    +  // The ROCm kernel writes compact scales only, for groups that share the hidden dimension.
    +  NVTE_CHECK(!output->with_gemm_swizzled_scales,
    +             "GEMM-swizzled requantization output scales are not supported on ROCm.");
    +  NVTE_CHECK(shape_rep == ShapeRepresentation::SAME_BOTH_DIMS ||
    +                 shape_rep == ShapeRepresentation::VARYING_FIRST_DIM,
    +             "Grouped MXFP8 requantization with varying last dimensions is not supported on ROCm.");
    +  // Each group's row count must be a multiple of 128 too. Those counts live on the device,
    +  // so that half is the caller's contract rather than an assertion.
    +  NVTE_CHECK(first_logical_dim % 128 == 0 && last_logical_dim % 128 == 0,
    +             "Grouped MXFP8 requantization on ROCm requires dims that are multiples of 128, but "
    +             "got (",
    +             first_logical_dim, ", ", last_logical_dim, ").");
    +  constexpr size_t kMaxInt = static_cast<size_t>(std::numeric_limits<int>::max());
    +  NVTE_CHECK(first_logical_dim <= kMaxInt && last_logical_dim <= kMaxInt,
    +             "Grouped MXFP8 requantization dimensions must fit in int32.");
    +  NVTE_CHECK(first_logical_dim / rocm_colwise_mxfp8::kTileRows <= 65535,
    +             "The number of rows is too large for the 2D launch grid.");
    +  if (first_logical_dim == 0) {
    +    return;
    +  }
    +  TRANSFORMER_ENGINE_TYPE_SWITCH_FP8ONLY(
    +      input.data.dtype, IType,
    +      TRANSFORMER_ENGINE_SWITCH_CONDITION(
    +          return_dequantized, RETURN_DEQUANTIZED,
    +          requantize::rocm_launch_group_requantize<IType, RETURN_DEQUANTIZED>(
    +              input, output, dequantized, static_cast<int>(first_logical_dim),
    +              static_cast<int>(last_logical_dim), stream);););  // NOLINT(*)
    +#else

    Okay, so later we will need TDM version for this as well, right?

    wangye805 wangye805 commented on code on Nov 17, 2026 20:56 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/rocm_quantize_mxfp8_body.inc:1

    Code changes in this entire file is to align with nv upstream pr https://github.com/NVIDIA/TransformerEngine/pull/3743/changes, right?

    wangye805 wangye805 commented on Nov 17, 2026 22:27 UTC
    Reviewer

    For common section

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -297,9 +299,11 @@ TEST(GroupedRequantizeTest, RejectsUnsupportedScalingModes) {
     }
     
     TEST(GroupedRequantizeTest, OptionalRowwiseOutputsAndAliasRules) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif

    [agent reply]

    This is a new upstream test, not one we had disabled.
    NVIDIA/TransformerEngine#3560 replaced test_fused_group_requantize_mxfp8.cu, which had one test (MatchesUnfusedChainReference), with this file, which has four: RejectsUnsupportedScalingModes, OptionalRowwiseOutputsAndAliasRules, BF16IntermediateIgnoresFastMath and MatchesDequantizeThenQuantize.
    Dev already ran the old test on ROCm by wrapping its Blackwell skip in #ifndef __HIP_PLATFORM_AMD__ (test_fused_group_requantize_mxfp8.cu:60 at b5c00f4). I wrapped the new tests' skips the same way, since nvte_group_requantize on ROCm runs the kernel dev already ships.
    In this test ROCm requests compact output scales and checks that a swizzled request throws (the #else branch after line 323), because ROCm rejects GEMM-swizzled requantize output.

    CI: the file is in test_operator's sources (tests/cpp/operator/CMakeLists.txt:26) and not in the ROCm REMOVE_ITEM list, so ci/core.sh runs it in the non-GEMM ctest pass (-E "GEMMTestSuite").
    At 2fdc920 on MI355X (gfx950) it passed, as did the whole non-GEMM pass (9350/9350).
    It has not run on MI300 (gfx942) yet. PR CI covers both, but the PR has no ci-level label, so CI has not run.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -359,9 +376,11 @@ TEST(GroupedRequantizeTest, OptionalRowwiseOutputsAndAliasRules) {
     }
     
     TEST(GroupedRequantizeTest, BF16IntermediateIgnoresFastMath) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif

    [agent reply]

    Same as line 306: a new test from NVIDIA/TransformerEngine#3560, not a disabled one, with the Blackwell skip wrapped the same way. It runs in ci/core.sh's non-GEMM pass and passed on MI355X at 2fdc920; MI300 has not run yet.
    It needed no ROCm change: the ROCm launcher always instantiates the kernel with the BF16 intermediate (kUseFastMath=true at rocm_fused_group_requantize.cuh:105; the parameter name is left over from dev's old API, where the fast-math flag selected the BF16 intermediate). The BF16 intermediate is what this test checks.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    tests/cpp/operator/test_requantize_mxfp8_grouped.cu:1
    @@ -400,16 +419,26 @@ TEST(GroupedRequantizeTest, BF16IntermediateIgnoresFastMath) {
     }
     
     TEST_P(GroupedRequantizeMXFP8TestSuite, MatchesDequantizeThenQuantize) {
    +#ifndef __HIP_PLATFORM_AMD__
       if (test::getDeviceComputeCapability() < test::blackwellComputeCapability) {
         GTEST_SKIP();
       }
    +#endif
     
       const auto &test_case = std::get<0>(GetParam());
       const DType input_dtype = std::get<1>(GetParam());
       const bool return_dequantized = std::get<2>(GetParam());
       const bool output_swizzled = std::get<3>(GetParam());
       const DType intermediate_dtype = DType::kBFloat16;
       const GroupShapeInfo shape_info = make_shape_info(test_case);
    +#ifdef __HIP_PLATFORM_AMD__
    +  if (output_swizzled) {
    +    GTEST_SKIP() << "ROCm writes compact requantization output scales only";
    +  }
    +  if (!shape_info.same_last_dim) {
    +    GTEST_SKIP() << "ROCm requantization requires groups that share the hidden dimension";
    +  }
    +#endif

    [agent reply]

    Yes. The suite is 18 shape cases × 2 input dtypes × with/without dequantized output × swizzled/compact = 144 cases.
    The two ROCm skips match the two ROCm-only rejections in nvte_group_requantize (requantize_mxfp8.cu:913 swizzled output, :915 varying last dim), and nothing else is skipped:

    | cases | count | MI355X |
    |---|---|---|
    | swizzled output | 72 | skipped by the first guard |
    | compact, VaryingLastDim / VaryingBothDims | 8 | skipped by the second guard |
    | compact, every other shape | 64 | passed |

    The kernel's third ROCm-only check, both logical dims multiples of 128 (:920), needs no guard: every upstream shape case satisfies it. If a future upstream case does not, it fails loudly instead of being skipped.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    tests/cpp/test_common.h:1
    @@ -119,20 +119,10 @@ struct TypeInfo {
         struct Helper {
             constexpr static DType getType() {
                 constexpr int i = static_cast<int>(current);
    -<<<<<<< HEAD
    -            // DType may list more types than this build provides (e.g. FP8 UE5M3 needs CUDA 13.4)
    -            if constexpr (i >= static_cast<int>(std::tuple_size<types>::value)) {
    -                return DType::kNumTypes;
    -            } else if constexpr (std::is_same<U, typename std::tuple_element<i, types>::type>::value) {
    -                return current;
    -            } else {
    -                return Helper<U, static_cast<DType>(i + 1)>::getType();
    -=======
                 if constexpr (i < static_cast<int>(std::tuple_size<types>::value)) {
                     if (std::is_same<U, typename std::tuple_element<i, types>::type>::value) {
                         return current;
                     }
    ->>>>>>> 1f251a125

    [agent reply]

    Yes. The lines this PR adds are exactly the lines NVIDIA/TransformerEngine#3649 (89668d9de) adds: the if constexpr (i < tuple_size) guard in Helper and the static_assert in getType. After this PR both are identical to upstream's.
    The lines on the left are dev's own fix for the same problem (DType lists more types than the build provides), from the v2.21 IFU resolution 171fcdb64. Upstream fixed it independently, so I took upstream's version and dropped ours. The rest of the file's ROCm additions are untouched by this PR.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    tests/cpp/util/CMakeLists.txt:1
    @@ -30,10 +30,6 @@ endif()
     target_compile_options(test_util PRIVATE -O2 -fopenmp)
     
     include(GoogleTest)
    -<<<<<<< HEAD
    -gtest_discover_tests(test_util PROPERTIES DISCOVERY_TIMEOUT 600)
    -=======
     # MALLOC_PERTURB_ makes glibc overwrite freed memory, so a destructor that reads a destroyed object
     # at exit crashes the test process, which ctest reports as a failure, instead of passing silently.
     gtest_discover_tests(test_util DISCOVERY_TIMEOUT 600 PROPERTIES ENVIRONMENT "MALLOC_PERTURB_=165")
    ->>>>>>> 1f251a125

    [agent reply]

    Yes. The lines this PR adds are exactly the lines NVIDIA/TransformerEngine#3733 (dd628d3a1) adds; compare git diff b5c00f4 HEAD with git diff c72db38 1f251a1 on this file.
    The removed line was dev's own, from the v2.1 IFU resolution (12112cf90), with an extra PROPERTIES keyword before DISCOVERY_TIMEOUT. Upstream's line replaces it and adds MALLOC_PERTURB_.
    The rest of the file, dev's if(USE_CUDA) / hipify structure, is unchanged by this PR.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/requantize_mxfp8.cu:1
    @@ -851,9 +865,15 @@ void group_requantize(const GroupedTensor &input, GroupedTensor *output, Tensor
                  "Input and output grouped shape representations must match.");
       NVTE_CHECK(input.data.dptr != output->columnwise_data.dptr,
                  "In-place MXFP8 data requantization is not supported.");
    +#ifdef __HIP_PLATFORM_AMD__
    +  NVTE_CHECK(is_aligned_ptr(input.data.dptr, ROCM_VEC_BYTES) &&
    +                 is_aligned_ptr(output->columnwise_data.dptr, ROCM_VEC_BYTES),
    +             "Input and output data pointers must be 16-byte aligned.");

    [agent reply]

    Same value (16), different meaning, and each branch uses its own.
    TMA_GMEM_ALIGNMENT (common.h:1276) is the TMA global-address alignment and is defined only in the CUDA block (#ifndef __HIP_PLATFORM_AMD__ at common.h:1266); ROCm has no TMA.
    ROCM_VEC_BYTES (util/rocm_device_utils.cuh:12) is the 128-bit width the ROCm tile loads and stores use (kVec = ROCM_VEC_BYTES / sizeof(T), rocm_colwise_mxfp8.cuh:32,58), which is the alignment this kernel actually needs.
    Dev's old dispatch had the same #ifdef pair (fused_group_requantize.cu:685 at b5c00f4). The message's "16-byte" holds for both.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/requantize_mxfp8.cu:1
    @@ -888,6 +908,35 @@ void group_requantize(const GroupedTensor &input, GroupedTensor *output, Tensor
       const int64_t *const first_dims_ptr = reinterpret_cast<const int64_t *>(input.first_dims.dptr);
       const int64_t *const last_dims_ptr = reinterpret_cast<const int64_t *>(input.last_dims.dptr);
     
    +#ifdef __HIP_PLATFORM_AMD__
    +  // The ROCm kernel writes compact scales only, for groups that share the hidden dimension.
    +  NVTE_CHECK(!output->with_gemm_swizzled_scales,
    +             "GEMM-swizzled requantization output scales are not supported on ROCm.");
    +  NVTE_CHECK(shape_rep == ShapeRepresentation::SAME_BOTH_DIMS ||
    +                 shape_rep == ShapeRepresentation::VARYING_FIRST_DIM,
    +             "Grouped MXFP8 requantization with varying last dimensions is not supported on ROCm.");
    +  // Each group's row count must be a multiple of 128 too. Those counts live on the device,
    +  // so that half is the caller's contract rather than an assertion.
    +  NVTE_CHECK(first_logical_dim % 128 == 0 && last_logical_dim % 128 == 0,
    +             "Grouped MXFP8 requantization on ROCm requires dims that are multiples of 128, but "
    +             "got (",
    +             first_logical_dim, ", ", last_logical_dim, ").");
    +  constexpr size_t kMaxInt = static_cast<size_t>(std::numeric_limits<int>::max());
    +  NVTE_CHECK(first_logical_dim <= kMaxInt && last_logical_dim <= kMaxInt,
    +             "Grouped MXFP8 requantization dimensions must fit in int32.");
    +  NVTE_CHECK(first_logical_dim / rocm_colwise_mxfp8::kTileRows <= 65535,
    +             "The number of rows is too large for the 2D launch grid.");
    +  if (first_logical_dim == 0) {
    +    return;
    +  }
    +  TRANSFORMER_ENGINE_TYPE_SWITCH_FP8ONLY(
    +      input.data.dtype, IType,
    +      TRANSFORMER_ENGINE_SWITCH_CONDITION(
    +          return_dequantized, RETURN_DEQUANTIZED,
    +          requantize::rocm_launch_group_requantize<IType, RETURN_DEQUANTIZED>(
    +              input, output, dequantized, static_cast<int>(first_logical_dim),
    +              static_cast<int>(last_logical_dim), stream);););  // NOLINT(*)
    +#else

    [agent reply]

    Not required for correctness, possibly worth it for performance, so I'd track it as a follow-up rather than IFU work.
    This is the kernel dev already ships (rocm_fused_group_requantize.cuh, now behind the GroupedTensor API): a shared-memory tile transpose with 16-byte vector loads, no TMA/TDM, and no arch-specific path.
    On gfx1250 a TDM version is the obvious optimization. It would also be the natural place to fuse the GEMM scale swizzle gfx1250 needs, which is the other thing ROCm rejects here today.
    I have not measured this kernel, so I can't yet say whether it matters for MoE token dispatch.
    I'll list TDM, swizzled output and varying last dims together in the PR's deferral list.

    wangye805 wangye805 commented on code on Nov 17, 2026 22:43 UTC
    Code Review
    transformer_engine/common/cast/mxfp8/rocm_quantize_mxfp8_body.inc:1

    [agent reply]

    Yes. All 27 added and 6 removed lines (from 164c10b) are #3743's quantize_mxfp8.cuh changes, applied to ROCm's copy of that kernel:

  • the per-block amax is seeded with NaN (__int_as_float(0x7FC00000)) instead of 0 at all three seed sites, so it stays NaN only when every element is NaN and the block gets scale 0xFF;

  • out-of-bounds elements count as 0 (fmaxf(amax, 0.0f)), as TMA zero-fill already makes them on CUDA;

  • __builtin_assume(amax >= 0) becomes !(amax < 0), since amax may now be NaN.
  • The comments use upstream's wording. #3743's half-precision amax path (nan_itype) and 2D amax_2d reduction have no counterpart here, because the ROCm kernel has neither.
    The subwarp reduction needs no change: rocm_op::max is fmaxf (rocm_device_utils.cuh:141), which treats NaN the same way as upstream's warp_reduce_max_broadcast.
    The same seed change in the ROCm branch of fused_mla_kv_rope_mxfp8.cu is in 371b15d (stage 2).

    Reviewers
    Assignees
    wangye805 wangye805
    Labels
    risk: low confidence: 68.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 85.5% (HIGH) · Higher = larger blast radius
    85.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 68.3% · Lower = rushed or shallow review
    68.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.1% · Safe to merge
    27.1%