Skip to content

[None][perf] Avoid implicit device-scalar syncs in DeepSeek-V4 ctx sparse metadata#16734

Merged
qiaoxj07 merged 1 commit into
NVIDIA:mainfrom
qiaoxj07:perf/dsv4-ctx-host-scalar-metadata
Jul 24, 2026
Merged

[None][perf] Avoid implicit device-scalar syncs in DeepSeek-V4 ctx sparse metadata#16734
qiaoxj07 merged 1 commit into
NVIDIA:mainfrom
qiaoxj07:perf/dsv4-ctx-host-scalar-metadata

Conversation

@qiaoxj07

@qiaoxj07 qiaoxj07 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Background

On a DeepSeek-V4-Pro disaggregated context worker (GB300, dep8, MTP3, overlap scheduler, 16384-token prefill chunks), nsys shows _prepare_inputs taking 268 ms/step, 92% of which is a single cudaStreamSynchronize. The sync is triggered by implicit device-scalar reads in the DSV4 sparse-attention metadata path:

_compute_ctx_compressed_position_ids sizes a torch.arange and bounds a slice with a 0-dim CUDA tensor (cu_new_comp[num_contexts]). Each such read is a 4-byte D2H copy + cudaStreamSynchronize; with the overlap scheduler the first read per step drains the entire compute-stream queue (~250 ms of queued forward work). The path executes:

  • once per step from prepare() (2 reads x 3 compress ratios = 6 syncs), and
  • twice more per step via on_update_kv_lens()model_engine._preprocess_inputs calls it unconditionally for every batch, and the spec-decode+overlap branch calls it again — adding 12 more syncs,

for 18 device-scalar reads per step. The executor thread holds the GIL for up to ~290 ms per step while blocked, delaying KV-transfer/response threads.

Changes

  • prepare() already computes the per-ratio ctx compressed-token counts on host tensors. Thread them through prepare_compressed_kv_metadata() into _compute_ctx_compressed_position_ids as Python ints (ctx_output_sizes), mirroring the existing gen-path gen_output_offsets precedent ("avoid tensor-scalar slice").
  • Cache ctx_output_sizes on the metadata so on_update_kv_lens() reuses it when no device-side mutation can have changed ctx-row kv_lens (num_chunked_ctx_requests == 0). Only the agg extend_ctx path adjusts ctx rows on device (previous_kv_lens_offsets); it falls back to the original device-scalar path.
  • Unit test: host-int path is element-wise identical to the device-scalar fallback across ratios {1,4,128}, including empty-output (ratio-128, short ctx) and long-context chunked-prefill boundaries. Also verified sync-free with torch.cuda.set_sync_debug_mode("error") on GB300.

Validation (nsys A/B on the same benchmark config, ctx iters 210-230)

Metric Baseline This PR
Whole-trace cudaStreamSynchronize 360 calls / 4721.7 ms 0 / 0 ms
4-byte D2H readbacks (steady state) 360 0
_prepare_inputs avg 268.3 ms 19.96 ms
Steady-state GPU idle (19 steps) 282.2 ms 48.3 ms
Longest executor-thread GIL hold 292.7 ms 19.78 ms
GPU busy 99.1% 99.8%

The full agentx e2e benchmark (990K ISL conversation traces, conc 144) runs to completion with the patch (hot-patched via bind-mount before this PR); position-id outputs are bit-identical by construction and by test.

Impact assessment

  • This ctx workload is GPU-bound, so end-to-end throughput is expected to be neutral here; the win is freeing the executor thread/GIL (~250 ms/step), lower jitter, and removing the same exposed sync in agg mixed ctx+gen batches.
  • The device-scalar fallback is preserved for the agg extend_ctx case (num_chunked_ctx_requests > 0) and for any caller that does not pass ctx_output_sizes, so behavior there is unchanged.
  • No API changes; DSV4 sparse-attention internal metadata only.

Dev Engineer Review

  • Updated DeepSeek-V4 sparse-attention metadata to avoid implicit device-scalar synchronization by optionally using host-computed per-context compressed-token counts (ctx_output_sizes) when context row lengths are known to be unchanged.
  • Added an internal cache (_ctx_output_sizes) populated during prepare() (when num_contexts > 0) and reused in on_update_kv_lens() only for the safe eligibility case (num_chunked_ctx_requests == 0); otherwise it preserves the existing device-scalar fallback by passing None.
  • Extended internal method signatures (prepare_compressed_kv_metadata(..., ctx_output_sizes=...) and _compute_ctx_compressed_position_ids(..., ctx_output_sizes=...)) to drive context-only compressed position-id sizing from host values while retaining the original fallback behavior for aggregate extend-context cases and callers without host counts.
  • Added unit coverage to ensure the host-size path produces element-wise identical compressed context position-id tensors to the device-scalar fallback (including the unchanged padding tail), across compression ratios and edge conditions relevant to the context portion.
  • No configuration files were modified.

QA Engineer Review

  • Added test: test_ctx_position_ids_host_sizes_match_device_scalar_fallback in tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py.
  • Test coverage mapping: not confirmed in tests/integration/test_lists/, tests/qa/, or tests/waives.txt from the available repository inspection.
  • Verdict: needs follow-up

@qiaoxj07
qiaoxj07 requested a review from a team as a code owner July 22, 2026 13:33
@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f8ace635-fe7c-418f-b4c3-2d6f9a9478a9

📥 Commits

Reviewing files that changed from the base of the PR and between 59ab788 and bfe0e36.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py

Walkthrough

DeepSeek-V4 sparse attention computes and caches host-side context compressed-token totals, reuses them during eligible KV-lens updates, and retains a device-scalar fallback. A parametrized test verifies identical compressed context position IDs across both paths.

Changes

DeepSeek-V4 context compressed-token sizing

Layer / File(s) Summary
Host context-size propagation
tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py
Metadata computes and caches per-compression-ratio context totals, then passes them through compressed KV metadata preparation to position-ID sizing with a device fallback.
KV-lens reuse and validation
tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py, tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py
KV-lens updates reuse cached totals when no chunked context requests exist, and tests compare host-provided results with device-scalar fallback results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DeepseekV4Metadata
  participant prepare_compressed_kv_metadata
  participant PositionIDBuilder
  DeepseekV4Metadata->>prepare_compressed_kv_metadata: pass host context totals
  prepare_compressed_kv_metadata->>PositionIDBuilder: forward ctx_output_sizes
  PositionIDBuilder-->>prepare_compressed_kv_metadata: compute compressed position IDs
  DeepseekV4Metadata->>prepare_compressed_kv_metadata: reuse cached totals for eligible KV-lens updates
Loading

Suggested reviewers: kris1025, pengbowang-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the PR's main performance change.
Description check ✅ Passed The description covers background, changes, validation, and impact, matching the template well.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py (1)

277-277: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use complete Python 3.10+ annotations.

Use built-in generics and | None, and add explicit return annotations to the altered production methods and added test helpers.

  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py#L277-L277: use dict[int, int] | None.
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py#L745-L745: use dict[int, int] | None.
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py#L792-L797: use native annotations and add -> None.
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py#L1035-L1042: use native annotations and add -> None.
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py#L461-L463: annotate parameters and -> None.
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py#L479-L479: annotate the helper parameter and -> torch.Tensor.

As per coding guidelines, “Annotate every function” and “prefer built-in generic types and |.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py` at
line 277, Use complete Python 3.10+ annotations throughout the listed sites: in
deepseek_v4.py lines 277 and 745, replace Optional/typing generics with
dict[int, int] | None; annotate the altered methods at lines 792-797 and
1035-1042 with native parameter types and -> None. In
tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py
lines 461-463, annotate helper parameters and return -> None, and at lines 479
annotate the helper parameter and return -> torch.Tensor.

Source: Coding guidelines

tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py (1)

491-493: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Cover the cached-size update path.

This test validates the static helper only; it never exercises prepare() caching at deepseek_v4.py Lines 772-774 or the reuse/fallback gate at Lines 882-885. Add a metadata-level test for both num_chunked_ctx_requests == 0 (cached host size) and > 0 (device fallback).

Test coverage summary: the new test covers host/device position-ID equivalence, empty output, and compression boundaries. CI/QA test-list membership is not verifiable from the supplied files. Verdict: needs follow-up. As per path instructions, changed test functions require coverage and test-list assessment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py`
around lines 491 - 493, Extend the test near the existing golden/fast comparison
to exercise the metadata flow through prepare() and the reuse/fallback gate in
deepseek_v4.py. Add cases for num_chunked_ctx_requests == 0, verifying cached
host-size position IDs, and greater than 0, verifying device fallback; cover
host/device position-ID equivalence, empty output, and compression-boundary
behavior while preserving the existing static-helper assertion.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py`:
- Around line 805-813: Update the documentation for ctx_output_sizes in
on_update_kv_lens() to state that cached host sizes are passed when no chunked
context requests exist, while the device-scalar fallback remains active only
when those cached sizes are unavailable.

---

Nitpick comments:
In `@tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py`:
- Line 277: Use complete Python 3.10+ annotations throughout the listed sites:
in deepseek_v4.py lines 277 and 745, replace Optional/typing generics with
dict[int, int] | None; annotate the altered methods at lines 792-797 and
1035-1042 with native parameter types and -> None. In
tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py
lines 461-463, annotate helper parameters and return -> None, and at lines 479
annotate the helper parameter and return -> torch.Tensor.

In
`@tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py`:
- Around line 491-493: Extend the test near the existing golden/fast comparison
to exercise the metadata flow through prepare() and the reuse/fallback gate in
deepseek_v4.py. Add cases for num_chunked_ctx_requests == 0, verifying cached
host-size position IDs, and greater than 0, verifying device fallback; cover
host/device position-ID equivalence, empty output, and compression-boundary
behavior while preserving the existing static-helper assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e40e98d2-8e38-46b6-96a4-46880c2a5759

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd6a49 and be52123.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py
  • tests/unittest/_torch/attention/sparse/deepseek_v4/test_compressor_module.py

Comment thread tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/deepseek_v4.py Outdated
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60983 [ run ] triggered by Bot. Commit: be52123 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60983 [ run ] completed with state FAILURE. Commit: be52123
/LLM/main/L0_MergeRequest_PR pipeline #49243 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@qiaoxj07
qiaoxj07 force-pushed the perf/dsv4-ctx-host-scalar-metadata branch from be52123 to 23ea630 Compare July 22, 2026 16:46
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61031 [ run ] triggered by Bot. Commit: 23ea630 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61031 [ run ] completed with state FAILURE. Commit: 23ea630
/LLM/main/L0_MergeRequest_PR pipeline #49288 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61047 [ run ] triggered by Bot. Commit: 23ea630 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61047 [ run ] completed with state FAILURE. Commit: 23ea630
/LLM/main/L0_MergeRequest_PR pipeline #49302 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61089 [ run ] triggered by Bot. Commit: 23ea630 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61089 [ run ] completed with state SUCCESS. Commit: 23ea630
/LLM/main/L0_MergeRequest_PR pipeline #49343 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

CI status note (for reviewers): pipeline #49343 is green everywhere (both builds, SBSA single-GPU) except one test — unittest/executor/test_proxy_fast_death.py on A10 — which the CI failure analysis marks as unrelated to this PR (three consecutive analyses conclude "PR likely to blame? No"; the DeepSeek-V4 sparse-attention test area passes).

Supporting evidence that this is a main-side flake:

Re-running CI.

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61114 [ run ] triggered by Bot. Commit: 23ea630 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61114 [ run ] completed with state SUCCESS. Commit: 23ea630
/LLM/main/L0_MergeRequest_PR pipeline #49368 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@qiaoxj07
qiaoxj07 force-pushed the perf/dsv4-ctx-host-scalar-metadata branch from 23ea630 to 59ab788 Compare July 23, 2026 00:45
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61136 [ run ] triggered by Bot. Commit: 59ab788 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61136 [ run ] completed with state FAILURE. Commit: 59ab788
/LLM/main/L0_MergeRequest_PR pipeline #49388 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61142 [ run ] triggered by Bot. Commit: 59ab788 Link to invocation

@lancelly lancelly 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.

Overall LGTM.
Nit: The comments are a bit verbose. Maybe we can simply them.

@lancelly
lancelly requested a review from lfr-0531 July 23, 2026 05:39
…arse metadata

DeepseekV4TrtllmAttentionMetadata._compute_ctx_compressed_position_ids
sized a torch.arange and bounded a slice with a 0-dim CUDA tensor
(cu_new_comp[num_contexts]). Each such implicit read is a 4-byte D2H copy
plus a cudaStreamSynchronize, and with the overlap scheduler the first
read per step drains the entire compute-stream queue (~250 ms of queued
forward work on a GB300 disagg ctx worker). The path runs once from
prepare() and twice more per step via on_update_kv_lens()
(model_engine._preprocess_inputs calls it unconditionally), for 18
device-scalar reads per step in total.

prepare() already computes the per-ratio ctx compressed-token counts on
host tensors. Thread them through prepare_compressed_kv_metadata() into
_compute_ctx_compressed_position_ids as Python ints (mirroring the
gen-path gen_output_offsets precedent), and cache them on the metadata so
on_update_kv_lens() can reuse them when no device-side mutation can have
changed ctx-row kv_lens (num_chunked_ctx_requests == 0; only the agg
extend_ctx path adjusts ctx rows on device). The device-scalar fallback
is kept for that case.

Validated on a DeepSeek-V4-Pro agentx disagg ctx-only GB300 benchmark
(dep8, MTP3, 16384-token prefill chunks, nsys on ctx iters 210-230):
whole-trace cudaStreamSynchronize count drops 360 -> 0, _prepare_inputs
falls 268.3 -> 20.0 ms/step, steady-state GPU idle 282 -> 48 ms, and the
executor thread's longest GIL hold shrinks 292.7 -> 19.8 ms. Position-id
outputs are element-wise identical to the fallback path (unit test
included; also verified sync-free under torch.cuda.set_sync_debug_mode).

Signed-off-by: Xianjie <5410381+qiaoxj07@users.noreply.github.com>
@qiaoxj07
qiaoxj07 force-pushed the perf/dsv4-ctx-host-scalar-metadata branch from 59ab788 to bfe0e36 Compare July 23, 2026 06:19
@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61210 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61142 [ run ] completed with state ABORTED. Commit: 59ab788

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61210 [ run ] completed with state FAILURE. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49453 completed with status: 'ABORTED'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61218 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61218 [ run ] completed with state FAILURE. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49458 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

Recurring CI infrastructure failure (for CI/infra visibility): this PR has now hit the same Kubernetes/JNLP agent-launch failure three times — pipelines #49288, #49388, and #49458 — all on Jenkins-Sub-3:

java.net.UnknownHostException: prod.blsm.nvidia.com
ERROR: Failed to launch cpu---tensorrt-github3-...
java.lang.IllegalStateException: Node was deleted, computer is null

Each occurrence kills the Build-SBSA pod before any compilation starts and fail-fast aborts the rest. The official failure analyses for all three classify it as Infrastructure/Transient with "PR likely to blame? No", and recommend escalating to CI infrastructure on recurrence — flagging it here since it has now recurred twice.

No code-level blockers remain on this PR (base includes #16724 and #16761; two approvals). Re-running.

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61230 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61230 [ run ] completed with state FAILURE. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49468 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61256 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61256 [ run ] completed with state FAILURE. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49492 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61263 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61263 [ run ] completed with state FAILURE. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49499 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@qiaoxj07

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61295 [ run ] triggered by Bot. Commit: bfe0e36 Link to invocation

hyukn added a commit to hyukn/TensorRT-LLM that referenced this pull request Jul 23, 2026
…ng on the host

`request.get_tokens(0)` marshals the whole C++ VecTokens (entire sequence) into a
fresh Python list of boxed ints -- O(seq_len) host work that grows linearly with
ISL. Three call sites in `_prepare_tp_inputs` / `cuda_graph_runner` pay this only
to read a length or a small slice, and re-pay it every iteration. In chunked
prefill the context loop re-marshals the full prompt for every chunk -> O(L^2/chunk)
per request over the prefill. Normal decode is already immune (get_last_tokens(0),
O(1)); the waste is in the prefill/context and MTP first-draft paths.

Changes:
- New nanobind binding `LlmRequest.get_tokens_range(beam, begin, end)` that copies
  only [begin, end) (O(chunk)) instead of the whole VecTokens.
- context loop and first_draft loop: use get_tokens_range for the chunk and
  get_num_tokens(0) (O(1)) for lengths, instead of get_tokens(0) + slice.
- cuda_graph_runner first-draft branch: len(get_tokens(0)) -> get_num_tokens(0).

Output is bit-identical (get_tokens_range returns the same subrange). Measured on a
DSv4-Pro disagg CTX worker (c3120, non-overlap, CTX nsys): _prepare_inputs p50
27.53 ms -> 15.10 ms (-45%), p90 43.29 -> 20.43 ms; 100% request success. Complements
NVIDIA#16734 (which removes the overlap device-scalar sync, 268 -> 19.96 ms); together they
target the two independent costs in _prepare_inputs.

Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61295 [ run ] completed with state SUCCESS. Commit: bfe0e36
/LLM/main/L0_MergeRequest_PR pipeline #49528 completed with status: 'SUCCESS'

CI Report

Link to invocation

chungen28 added a commit to deepinfra/TensorRT-LLM that referenced this pull request Jul 24, 2026
…ta (upstream PR NVIDIA#16734)

Squash of upstream PR NVIDIA#16734 (fixes issue NVIDIA#15684): the DSv4
sparse-attention ctx metadata prep sized a torch.arange and bounded a slice with a
0-dim CUDA tensor (cu_new_comp[num_contexts]) in _compute_ctx_compressed_position_ids,
forcing an implicit D2H read + cudaStreamSynchronize. Under the overlap scheduler the
first such read drains the whole compute-stream queue, which manifests as a hard
deadlock (GPU 0%, iters frozen) whenever a context/prefill request is admitted into a
full gen batch (MAX_UTILIZATION oversubscription); spec-algorithm-independent (MTP and
DSpark both hang).

Pre-extract per-ratio ctx compressed-token counts as host Python ints in prepare()
and thread them (ctx_output_sizes) into prepare_compressed_kv_metadata ->
_compute_ctx_compressed_position_ids so the arange size / slice bound stay off-device.
on_update_kv_lens() reuses the cached host sizes EXCEPT when num_chunked_ctx_requests
> 0 (the extend_ctx path may have mutated ctx-row kv_lens on device), where it falls
back to the device read for correctness. Includes the upstream unit test asserting the
host-int path reproduces the device-scalar fallback exactly.

Supersedes the earlier local re-derivation; this is the upstream version, which adds
the chunked-context staleness guard the local patch lacked.

Signed-off-by: chungen28 <chung-en@deepinfra.com>

@pengbowang-nv pengbowang-nv 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, approve as this is targeted disagg pure ctx server.

@qiaoxj07
qiaoxj07 merged commit 2991994 into NVIDIA:main Jul 24, 2026
10 checks passed
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.

5 participants