Skip to content

Fix missing dp_max_padding argument in set_dp_buffer_len#12812

Merged
ispobock merged 1 commit intosgl-project:mainfrom
Chen-0210:fix_missing_augument_in_piece_cuda_graph
Nov 7, 2025
Merged

Fix missing dp_max_padding argument in set_dp_buffer_len#12812
ispobock merged 1 commit intosgl-project:mainfrom
Chen-0210:fix_missing_augument_in_piece_cuda_graph

Conversation

@Chen-0210
Copy link
Copy Markdown
Contributor

@Chen-0210 Chen-0210 commented Nov 7, 2025

Motivation

PR #12572 added a new argument dp_max_padding to set_dp_buffer_len, which caused #12796 .
Fixes #12796.

Modifications

Pass the missing dp_max_padding argument to set_dp_buffer_len.

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Chen-0210, 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 stemming from a recent update that introduced a new argument, dp_max_padding, to the set_dp_buffer_len function. By correctly supplying this previously missing argument, the change ensures the proper operation of the deep attention padding mechanism, preventing potential issues and maintaining system stability.

Highlights

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 correctly fixes a crash by passing the missing dp_max_padding argument to set_dp_buffer_len. However, I've identified a related latent bug where global_dp_buffer_len is None, which would cause a TypeError when data parallelism is enabled. My suggested change addresses both the original issue and this latent bug by correctly calculating global_dp_buffer_len and also passing the global_num_tokens argument, which is necessary for data parallel attention.

def run_once():
# Clean intermediate result cache for DP attention
forward_batch.dp_local_start_pos = forward_batch.dp_local_num_tokens = None
set_dp_buffer_len(global_dp_buffer_len, num_tokens)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

While adding the dp_max_padding argument fixes the immediate TypeError, there's a latent bug here. The global_dp_buffer_len variable is initialized to None at line 331. When data parallelism is used (dp_size > 1), this None value will be passed to set_dp_buffer_len and eventually cause a TypeError inside get_global_dp_buffer when it's used to allocate a tensor.

To make this robust, we should calculate the correct global_dp_buffer_len here, which should be num_tokens * self.dp_size. Additionally, the global_num_tokens argument should be passed for data parallel attention to work correctly during graph capture.

Suggested change
set_dp_buffer_len(global_dp_buffer_len, num_tokens)
set_dp_buffer_len(
num_tokens * self.dp_size,
num_tokens,
forward_batch.dp_padding_mode.is_max_len(),
[num_tokens] * self.dp_size,
)

@b8zhong b8zhong added the run-ci label Nov 7, 2025
@ispobock ispobock merged commit c67fce1 into sgl-project:main Nov 7, 2025
73 of 79 checks passed
@Chen-0210 Chen-0210 deleted the fix_missing_augument_in_piece_cuda_graph branch November 7, 2025 13:46
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.

[Bug] Piecewise Cuda Graph Issue in v0.5.5

3 participants