Skip to content

[bugfix] Fix CUDA_ERROR_INVALID_DEVICE in trtllm allreduce backend for multi-node setups#2686

Closed
esmeetu wants to merge 1 commit into
flashinfer-ai:mainfrom
esmeetu:fix-workspace
Closed

[bugfix] Fix CUDA_ERROR_INVALID_DEVICE in trtllm allreduce backend for multi-node setups#2686
esmeetu wants to merge 1 commit into
flashinfer-ai:mainfrom
esmeetu:fix-workspace

Conversation

@esmeetu
Copy link
Copy Markdown
Contributor

@esmeetu esmeetu commented Mar 4, 2026

📌 Description

🔍 Related Issues

🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.

✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

If you are unsure about how to set up pre-commit, see the pre-commit documentation.

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

Summary by CodeRabbit

  • Chores
    • Updated GPU device selection logic for multi-GPU all-reduce operations to use the current device context instead of per-rank device indices, improving consistency in symmetric device memory allocation.

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

Summary of Changes

Hello, 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 resolves a critical bug in the trtllm allreduce communication backend that caused CUDA_ERROR_INVALID_DEVICE errors in multi-node environments. The fix ensures that the IPC workspace for all-reduce fusion correctly identifies and utilizes the current CUDA device, preventing device mismatch issues during distributed operations.

Highlights

  • Bugfix for CUDA_ERROR_INVALID_DEVICE: Addressed an issue in the trtllm allreduce backend where an incorrect CUDA device index was used during IPC workspace creation, specifically impacting multi-node setups.
  • Device Index Correction: Modified the trtllm_create_ipc_workspace_for_all_reduce_fusion function to use torch.cuda.current_device() instead of torch.device("cuda", tp_rank).index to ensure the correct local CUDA device is referenced.

🧠 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.

Changelog
  • flashinfer/comm/trtllm_ar.py
    • Fixed CUDA_ERROR_INVALID_DEVICE by using torch.cuda.current_device() for IPC workspace creation in trtllm_create_ipc_workspace_for_all_reduce_fusion.
    • Reordered import statements for better code organization.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded yet for this pull request.
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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 4, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d5932187-e22a-48e2-820b-c7355d3de4fa

📥 Commits

Reviewing files that changed from the base of the PR and between 635505f and 45cee58.

📒 Files selected for processing (1)
  • flashinfer/comm/trtllm_ar.py

📝 Walkthrough

Walkthrough

The pull request modifies device handling logic in the TensorRT-LLM all-reduce functionality. Import statements are reorganized, and the device selection mechanism for symmetric device memory allocation changes from using per-rank CUDA device indexing to using the current device.

Changes

Cohort / File(s) Summary
Device selection refactoring
flashinfer/comm/trtllm_ar.py
Import reordering and device selection mechanism changes in trtllm_create_ipc_workspace_for_all_reduce and trtllm_create_ipc_workspace_for_all_reduce_fusion from torch.device("cuda", tp_rank).index to torch.cuda.current_device() for symmetric device memory allocation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 From rank-bound devices we take flight,
Toward current CUDA in the light,
Memory allocation dances free,
Symmetric buffers wild with glee,
Through IPC channels, swift and bright,
Device selection feels so right! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@esmeetu esmeetu closed this Mar 4, 2026
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 addresses a CUDA_ERROR_INVALID_DEVICE bug in the trtllm all-reduce backend for multi-node configurations. The fix involves replacing torch.device("cuda", tp_rank).index with torch.cuda.current_device() when creating a SymmDeviceMemory instance. This is the correct approach, as tp_rank can represent a global rank that is invalid as a local device index in a multi-node setting, while torch.cuda.current_device() correctly provides the local device index. The change is accurate and effectively resolves the issue.

@esmeetu
Copy link
Copy Markdown
Contributor Author

esmeetu commented Mar 4, 2026

resolved in #2662

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.

1 participant