Skip to content

[Bugfix][Build] host code compiles as C++20 on torch 2.14, C++17 before (needed by RFC #420 final_distributed_h3_run) - #734

Merged
Flink-ddd merged 6 commits into
RL-Align:test-h3from
fusheng-ji:build/cxx20-torch214
Nov 23, 2026
Merged

Flink-ddd merged 6 commits into
RL-Align:test-h3from
fusheng-ji:build/cxx20-torch214

Conversation

@fusheng-ji

@fusheng-ji fusheng-ji commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What

The CUDA / ROCm extension stops at its first host file on torch 2.14. torch 2.14's headers require C++20:

#error "C++20 or later compatible compiler is required to use PyTorch."

They also use std::strong_ordering and requires-clauses. build_tools/extensions.py passes -std=c++17 to the host compiler.

This PR picks the host standard from the installed torch: C++20 from 2.14 on, C++17 before. Builds against older torch keep the same flags. PyTorch already sets nvcc's own -std, so only the host flags change here; the MUSA and Ascend compilers keep their flags.

This is independent of H3. RFC #420's final_distributed_h3_run needs it because its rollout stack (vLLM 0.33, vLLM-Omni, verl-omni) requires torch 2.14. The rollout binding's measurements (#735) were built with the fix commit 7cae99bd.

Prior art & reuse decision

Option What it does Decision
Let PyTorch choose: drop our -std BuildExtension appends -std=c++20 when the host flags carry none (append_std17_if_no_std_present, in both torch 2.13 and 2.14). It already passes nvcc -std=c++20 on both, so the 15 .cu files compile as C++20 on torch 2.13 today; our flag decides only the one host file, csrc/bindings/ops.cpp not taken here: on torch 2.13 it would move ops.cpp from C++17 to C++20. That is a small change, but this fix does not need it, and it is untested on ROCm, MUSA and Ascend. Easy to switch to if preferred
Our flag follows torch's version _host_cxx_standard(): C++20 from 2.14 (what the headers require and what PyTorch itself passes), C++17 before taken: torch < 2.14 builds keep the same flags; on 2.14 the flags are the ones PyTorch would choose

Results

On one B200 at dcc8535a, CUDA 13.0, a clean setup.py build_ext --inplace for each torch (the flags counted from the verbose build log):

torch -std in the build Build _C imports from the checkout pytest tests/build
2.13.0+cu130 (repo environment) c++ (ops.cpp): -std=c++17; nvcc (15 .cu): -std=c++20 (PyTorch's) ok yes, 70 ops 152 passed
2.14.0+cu130 (the final run's environment) c++ (ops.cpp): -std=c++20; nvcc (15 .cu): -std=c++20 ok yes, 70 ops 152 passed

Status

  • Current head dcc8535a, on test-h3 12e81c36. Two commits, both signed off: the fix and its test.
  • Help wanted: none.

Tests

Where What Result
CPU tests/build/test_build_platform_collectives.py (11 new cases: version parsing, and exactly one -std in the CUDA and ROCm configs for 2.13 and 2.14) 139 passed (128 before)
1 x B200, torch 2.13 and torch 2.14 pytest tests/build after a clean build of each 152 passed on each
lint black, isort, flake8 with the repo's pre-commit settings clean

Scope

  • Changes only the host compiler's -std, only for torch >= 2.14.
  • No source changes: the extension's code builds as C++20 as it is.
  • Not tested here: ROCm, MUSA and Ascend on torch 2.14. ROCm takes the same host flag; MUSA and Ascend keep their own flags.

Summary by CodeRabbit

  • Build Compatibility
    • CUDA and ROCm extensions now use C++20 with PyTorch 2.14 or later, while earlier versions continue to use C++17.

torch 2.14's headers require C++20 (#error 'C++20 or later compatible
compiler is required', std::strong_ordering, requires-clauses); the
CUDA/ROCm extension passed -std=c++17 to the host compiler and stopped
there. Pick the host standard from torch's version: C++20 from 2.14,
C++17 before, so builds against older torch are unchanged. PyTorch
already chooses nvcc's -std itself; the MUSA and Ascend compilers keep
their flags.

Signed-off-by: Wenbo Ji <[email protected]>
Covers _host_cxx_standard on version strings (numeric minor compare,
local and pre-release suffixes) and checks that the CUDA and ROCm
extension configs carry exactly one -std, C++17 for torch 2.13 and
C++20 for torch 2.14.

Signed-off-by: Wenbo Ji <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between dcc8535 and 44ce922.

Files selected for processing: 2

  • build_tools/extensions.py
  • tests/build/test_build_platform_collectives.py

No actionable comments were generated in the recent review.

Walkthrough

The CUDA/ROCm extension now selects C++17 for PyTorch versions before 2.14 and C++20 for version 2.14 or later. Tests cover version parsing and the resulting compile flags.

Changes: Host C++ Standard Selection

Layer / File(s) Summary
Select and apply the host C++ standard
build_tools/extensions.py, tests/build/test_build_platform_collectives.py
A helper selects the host C++ standard from the PyTorch version. CUDA/ROCm host flags use the selected standard. Tests cover version strings and verify that the flags contain exactly one -std= option.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · previous review dcc85

The change selects C++17 or C++20 for the CUDA/ROCm host build based on the installed PyTorch version. It is small, tested, and low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the host C++ standard is selected from the installed torch version, C++20 for torch 2.14 and later and C++17 before. It also carries a [Bugfix][Build] tag and a refere…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: the host C++ standard is selected from the installed torch version, C++20 for torch 2.14 and later and C++17 before. It also carries a [Bugfix][Build] tag and a reference to RFC #420. The title is specific and matches the summary and objectives. The length (117 characters) is long, and the RFC reference is a detail that does not describe the code change, but neither makes the title unrelated or vague.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 12e81c3 and dcc8535.

Files selected for processing: 2

  • build_tools/extensions.py
  • tests/build/test_build_platform_collectives.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • 📋 Routed to summary by policy: 1 comment(s)

⚠️ 1 warning(s) occurred during review.


bug · medium

📄 build_tools/extensions.py (L529-L529)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

The C++20 bump is applied only to the main rl_engine._C extension. Two other extensions in this same function also compile host TUs that include torch/extension.h and would hit the same "C++20 or later compatible compiler is required" failure on torch >= 2.14:

  • The _H3_C extension (extra_compile_args={"cxx": ["-O3"], ...} around line 598) passes no -std at all, so the host compiler keeps its default standard (gnu++17, no -std injected by torch for host .cpp files). Trigger: torch 2.14 + RL_KERNEL_H3_STRICT=1 → csrc/bindings/h3_ops.cpp fails to build.
  • The MUSA extension (lines ~380-381) hardcodes -std=c++17 in both cxx and mcc, so a torch_musa build against torch >= 2.14 keeps the old standard.

Please reuse _host_cxx_standard() for these flag lists as well (and keep c++17 only for torch < 2.14) so the whole build is consistent.


⚠️ Warnings:

  • build_tools/extensions.py,tests/build/test_build_platform_collectives.py (review_limit_reached): reached the aggregate token budget before finishing; the grace round completed the task

Comment thread build_tools/extensions.py

platform_define = "-DKERNEL_ALIGN_WITH_ROCM" if is_rocm else "-DKERNEL_ALIGN_WITH_CUDA"
cxx_flags = ["-O3", "-std=c++17", platform_define]
cxx_flags = ["-O3", f"-std={_host_cxx_standard()}", platform_define]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · high
The new host standard only reaches the main _C extension. The separate _H3_C DSO built later in this function under RL_KERNEL_H3_STRICT still passes "cxx": ["-O3"] while compiling csrc/bindings/h3_ops.cpp against the same torch headers, so on torch >= 2.14 it inherits torch's/compiler's default C++17 and hits exactly the "C++20 or later compatible compiler is required" error this change is fixing for _C. Apply f"-std={_host_cxx_standard()}" to that extension too (the new build test only inspects ext_modules[0], so this gap is not covered). The MUSA branch above also hardcodes "cxx": ["-O3", "-std=c++17", ...] for its host compiler and will fail the same way once torch_musa is based on torch >= 2.14.

Suggestion:

Suggested change
cxx_flags = ["-O3", f"-std={_host_cxx_standard()}", platform_define]
cxx_flags = ["-O3", f"-std={_host_cxx_standard()}", platform_define]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed: _H3_C passes no -std, so PyTorch's BuildExtension appends -std=c++20 itself (cpp_extension.py:866-873, append_std17_if_no_std_present). Only _C hard-coded -std=c++17, which this PR fixes. MUSA's hard-coded C++17 (extensions.py:380) is deliberately unchanged; its compiler keeps its own flags.

@github-actions

Copy link
Copy Markdown

@fusheng-ji The automated OCR review has completed.

Please review and address all automated review bot findings, then push your updates. Maintainers will begin manual review after the bot findings have been addressed.

@maxiaosong1124
maxiaosong1124 self-requested a review November 23, 2026 01:37

@maxiaosong1124 maxiaosong1124 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@Flink-ddd
Flink-ddd merged commit 483c8a8 into RL-Align:test-h3 Nov 23, 2026
6 checks passed
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 28, 2026
… feat/h3-omni-rollout-model at 8ecfed9; TP4 runs at 463d719 + RL-Align#734)

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 29, 2026
… feat/h3-omni-rollout-model at 8ecfed9; TP4 runs at 463d719 + RL-Align#734)

Signed-off-by: Wenbo Ji <[email protected]>
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