Skip to content

Register cp-atten-allgather buffers with symm memory#17756

Merged
ShangmingCai merged 19 commits intosgl-project:mainfrom
wangfakang:nccl_symm
Feb 11, 2026
Merged

Register cp-atten-allgather buffers with symm memory#17756
ShangmingCai merged 19 commits intosgl-project:mainfrom
wangfakang:nccl_symm

Conversation

@wangfakang
Copy link
Copy Markdown
Contributor

@wangfakang wangfakang commented Jan 26, 2026

Motivation

To enhance the communication performance of cp-attention-allgather by adding symmetric memory (symm) support. Benchmark results for the 16K input scenario show that enabling symmetric memory reduces allgather communication latency by 50%.

CC @merrymercy @Fridge003 @nvcastet

Before optimization allgather took 27.584μs

image

After optimization allgather took 13.696μs
image

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

Signed-off-by: wangfakang <fakangwang@gmail.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @wangfakang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces symmetric memory allocation for buffers involved in cp-attention-allgather operations. By wrapping tensor creation calls with a use_symmetric_memory context manager, the change aims to optimize memory usage and potentially improve performance in distributed attention mechanisms, ensuring memory is allocated efficiently across devices when symmetric allocation is enabled.

Highlights

  • Symmetric Memory Integration: The pull request integrates symmetric memory allocation for cp-attention-allgather buffers, specifically for input_tensor_all and output_tensor.
  • Context Manager Application: Memory allocations for key tensors within cp_attn_tp_all_gather_reorganazied_into_tensor and cp_all_gather_rerange_output functions are now managed using the use_symmetric_memory context manager.
  • Conditional Allocation: The symmetric memory allocation is applied conditionally, based on the result of the is_allocation_symmetric() check, allowing for flexible memory management.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables symmetric memory for cp-attention-allgather operations by wrapping buffer allocations in a use_symmetric_memory context. The changes look good in principle.

However, I've identified a potential issue in both modified functions (cp_attn_tp_all_gather_reorganazied_into_tensor and cp_all_gather_rerange_output). When symmetric memory is enabled, the input tensors for the all-gather operations are not consistently allocated in symmetric memory. This could lead to errors or performance degradation if the underlying communication library expects registered buffers. I've left specific comments with suggestions on how to address this. Please take a look.

Comment thread python/sglang/srt/layers/attention/nsa/utils.py
Comment thread python/sglang/srt/layers/attention/nsa/utils.py
@wangfakang
Copy link
Copy Markdown
Contributor Author

wangfakang commented Jan 27, 2026

Friendly ping @merrymercy @Fridge003 Could you help me review this? Thanks!

Copy link
Copy Markdown
Collaborator

@nvcastet nvcastet left a comment

Choose a reason for hiding this comment

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

Minor comments, otherwise looks good to me! Thanks!

Comment thread python/sglang/srt/layers/attention/nsa/utils.py
Comment thread python/sglang/srt/layers/attention/nsa/utils.py
Signed-off-by: wangfakang <fakangwang@gmail.com>
@nvcastet
Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@wangfakang
Copy link
Copy Markdown
Contributor Author

wangfakang commented Jan 30, 2026

After reviewing the failed CI logs, most errors appear to be related to missing python3 command, which doesn't seem to be caused by this PR. How should we proceed with this? cc @nvcastet @ishandhanani @merrymercy @Fridge003

+ echo CUDA_VISIBLE_DEVICES=
CUDA_VISIBLE_DEVICES=
+ python3 -c 'import os, shutil, tempfile, getpass; cache_dir = os.environ.get("TORCHINDUCTOR_CACHE_DIR") or os.path.join(tempfile.gettempdir(), "torchinductor_" + getpass.getuser()); shutil.rmtree(cache_dir, ignore_errors=True)'
scripts/ci/cuda/ci_install_dependency.sh: line 27: python3: command not found
Error: Process completed with exit code 127.

@nvcastet
Copy link
Copy Markdown
Collaborator

nvcastet commented Feb 2, 2026

@ishandhanani @Fridge003 I agree with @wangfakang, the CI failures are unrelated to this PR.

@nvcastet
Copy link
Copy Markdown
Collaborator

nvcastet commented Feb 2, 2026

@wangfakang In fact, can you add back disabled=not is_allocation_symmetric() to the context manager as a safety net in your PR?
We have seen other places that did not have it fail with misalignement.

@nvcastet
Copy link
Copy Markdown
Collaborator

nvcastet commented Feb 6, 2026

/tag-and-rerun-ci

@wangfakang
Copy link
Copy Markdown
Contributor Author

wangfakang commented Feb 7, 2026

@nvcastet @merrymercy @Fridge003 @ShangmingCai
After reviewing some of the failed CI runs, the failures appear to be caused by flaky test cases. Moreover, the same test cases are also failing in PR#18408 that have already merged into the main branch, such as stage-b-test-small-1-gpu-amd (linux-mi325-gpu-1, 10).

Copy link
Copy Markdown
Collaborator

@ShangmingCai ShangmingCai left a comment

Choose a reason for hiding this comment

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

CC: @xu-yfei

@xu-yfei
Copy link
Copy Markdown
Contributor

xu-yfei commented Feb 9, 2026

CC: @xu-yfei

LGTM

@ShangmingCai
Copy link
Copy Markdown
Collaborator

/rerun-stage stage-c-test-8-gpu-h200

@github-actions
Copy link
Copy Markdown
Contributor

✅ Triggered stage-c-test-8-gpu-h200 to run independently (skipping dependencies).

@github-actions
Copy link
Copy Markdown
Contributor

🔗 View workflow run

@ShangmingCai
Copy link
Copy Markdown
Collaborator

/rerun-stage stage-c-test-8-gpu-h20

@github-actions
Copy link
Copy Markdown
Contributor

✅ Triggered stage-c-test-8-gpu-h20 to run independently (skipping dependencies).

@github-actions
Copy link
Copy Markdown
Contributor

🔗 View workflow run

@ShangmingCai
Copy link
Copy Markdown
Collaborator

/rerun-stage unit-test-backend-4-gpu-b200

@github-actions
Copy link
Copy Markdown
Contributor

✅ Triggered unit-test-backend-4-gpu-b200 to run independently (skipping dependencies).

@github-actions
Copy link
Copy Markdown
Contributor

🔗 View workflow run

@ShangmingCai
Copy link
Copy Markdown
Collaborator

/rerun-stage stage-c-test-4-gpu-b200

@github-actions
Copy link
Copy Markdown
Contributor

✅ Triggered stage-c-test-4-gpu-b200 to run independently (skipping dependencies).

@github-actions
Copy link
Copy Markdown
Contributor

🔗 View workflow run

@ShangmingCai
Copy link
Copy Markdown
Collaborator

/rerun-stage stage-c-test-4-gpu-gb200

@github-actions
Copy link
Copy Markdown
Contributor

✅ Triggered stage-c-test-4-gpu-gb200 to run independently (skipping dependencies).

@github-actions
Copy link
Copy Markdown
Contributor

🔗 View workflow run

@ShangmingCai
Copy link
Copy Markdown
Collaborator

Since our CI is flaky currently, I think we can bypass CI and merge this PR. If any bug has been reported, please ping me to fix or revert.

@ShangmingCai ShangmingCai merged commit 72c1526 into sgl-project:main Feb 11, 2026
262 of 287 checks passed
@sgl-project sgl-project deleted a comment from github-actions Bot Feb 11, 2026
alphabetc1 pushed a commit to alphabetc1/sglang that referenced this pull request Feb 11, 2026
Signed-off-by: wangfakang <fakangwang@gmail.com>
Johnsonms pushed a commit to Johnsonms/sglang that referenced this pull request Feb 14, 2026
Signed-off-by: wangfakang <fakangwang@gmail.com>
magicYang1573 pushed a commit to magicYang1573/sglang that referenced this pull request Mar 9, 2026
Signed-off-by: wangfakang <fakangwang@gmail.com>
Wangzheee pushed a commit to Wangzheee/sglang that referenced this pull request Mar 21, 2026
Signed-off-by: wangfakang <fakangwang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants