Skip to content

Guard DP local info when global token counts are missing - #1

Open
AndyLi429 wants to merge 1 commit into
qwen3_pcp_01from
codex/fix-typeerror-in-cumsum-function
Open

Guard DP local info when global token counts are missing#1
AndyLi429 wants to merge 1 commit into
qwen3_pcp_01from
codex/fix-typeerror-in-cumsum-function

Conversation

@AndyLi429

Copy link
Copy Markdown
Owner

Motivation

  • Prevent silent, incorrect fallbacks when DP attention is enabled but global_num_tokens_gpu is missing, which can cause multi-rank DP to proceed with invalid metadata.
  • Still allow single-rank (non-DP) runs to compute local start/length without requiring scheduler-prepared global tensors.

Description

  • In get_dp_local_info (python/sglang/srt/layers/dp_attention.py) require global_num_tokens_gpu when get_attention_dp_size() > 1 and raise a clear RuntimeError if it is missing.
  • For the dp_size == 1 case, compute and set dp_local_start_pos and dp_local_num_tokens directly from seq_lens_sum or batch_size and return without constructing global token tensors.
  • Leave the existing path that computes cumtokens and extracts per-rank start/length unchanged when global_num_tokens_gpu is present.

Testing

  • No automated tests were run for this change.

Codex Task

@coderabbitai

coderabbitai Bot commented Feb 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-typeerror-in-cumsum-function

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fe5f235769

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +424 to +428
if forward_batch.forward_mode.is_extend(
include_draft_extend_v2=True
):
local_num_tokens = forward_batch.seq_lens_sum
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use extend token count instead of seq_lens_sum

When global_num_tokens_gpu is missing and dp_size == 1, the fallback for extend modes uses seq_lens_sum. In extend batches with cached prefixes, seq_lens_sum counts the full fill_ids length (prefix + new tokens), while the local buffers only contain the new tokens (e.g., extend_num_tokens/out_cache_loc length). In that case local_num_tokens is larger than the local buffer, so the later memcpy_triton in DP gather/scatter can read/write past the local buffer. Consider deriving the count from extend_num_tokens or out_cache_loc.shape[0] for extend modes to match the actual local token buffer size.

Useful? React with 👍 / 👎.

AndyLi429 pushed a commit that referenced this pull request May 20, 2026
- hc_pre NPU branch: return 4-tuple (y, post, comb, norm_fused=False)
  to match caller's unpack. Was 3-tuple → ValueError on first non-empty
  forward. (P1, reviewer: AndyLi429 #1 + Codex)

- _apply_hadamard: scale by head_dim**-0.5 to match the CUDA
  rotate_activation reference; otherwise indexer dot products were
  scaled by sqrt(n) and top-k selection drifted from reference.
  (P1, reviewer: AndyLi429 #2 + Codex)

- DeepSeekV4TokenToKVPool: log per-req c4/c128 slab capacity at init
  so the average-allocator limitation is visible (low-concurrency
  long-context still needs a real allocator — followup). (P1,
  reviewer: AndyLi429 sgl-project#3)

- custom_ops ImportError: fail-fast with a clear message naming the
  required wheel / CANN image, instead of logging "fall back" when
  no fallback exists. (P2, reviewer: AndyLi429 sgl-project#4)

- _forward_compressed: raise on missing metadata/cmp_kv with
  layer_id / compress_ratio / available metadata keys, instead of
  silently returning zeros. (P2, reviewer: AndyLi429 sgl-project#5)

- DeepSeekV4SingleKVPool.create_buffer: gate the NPU PA_ND bf16
  layout on _is_npu, not on dtype alone. (P2, reviewer: AndyLi429 sgl-project#6 +
  zhuyijie88 inline)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

1 participant