Skip to content

[None][perf] Add DeepSeek V4 block table custom op#15821

Merged
liji-nv merged 1 commit into
NVIDIA:feat/deepseek_v4from
liji-nv:feat/deepseek-v4-block-table-custom-op
Jul 3, 2026
Merged

[None][perf] Add DeepSeek V4 block table custom op#15821
liji-nv merged 1 commit into
NVIDIA:feat/deepseek_v4from
liji-nv:feat/deepseek-v4-block-table-custom-op

Conversation

@liji-nv

@liji-nv liji-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Add CUDA custom ops for DeepSeek V4 sliding block table generation so the sparse cache manager no longer relies on the torch.compile block-table implementations that caused large host-memory pressure during compile.

Changes:

  • Add no-scratch and scratch CUDA kernels plus thop bindings for trtllm::deepseek_v4_compute_sliding_block_tables and trtllm::deepseek_v4_compute_sliding_block_tables_with_scratch.

  • Use a tiled no-scratch row kernel with int4 vectorization when maxBlocksPerSeq is 4-aligned and scalar handling otherwise, so the no-scratch path always uses the new kernel.

  • Replace the DeepSeek V4 cache-manager torch.compile block-table functions with direct torch.ops.trtllm custom-op calls.

  • Add CUDA unit tests that compare both custom ops against the removed torch reference implementation for scalar and vectorized max-block sizes.

  • Add a standalone microbenchmark script for comparing custom-op latency against eager or torch.compile references across no-scratch and scratch cases.

Validation:

  • python3 -m py_compile tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py tests/unittest/_torch/custom_ops/test_deepseek_v4_block_table.py

  • git diff --cached --check

  • CMH build_sqsh job 778723: COMPLETED exit=0.

  • CMH GPU unit test job 781707: 4 passed in 4.78s.

  • CMH no-scratch perf sweep job 780480: comparable production-ish cases averaged +0.15% latency delta versus the previous 2D tiled build, with 16/17 cases within +/-5%.

@coderabbitai summary

Description

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@liji-nv
liji-nv requested a review from a team as a code owner July 1, 2026 07:16
@liji-nv
liji-nv requested review from yuxianq and removed request for a team July 1, 2026 07:16
@liji-nv

liji-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56957 [ run ] triggered by Bot. Commit: b8a085c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56957 [ run ] completed with state SUCCESS. Commit: b8a085c
/LLM/main/L0_MergeRequest_PR pipeline #45760 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

Add CUDA custom ops for DeepSeek V4 sliding block table generation so the sparse cache manager no longer relies on the torch.compile block-table implementations that caused large host-memory pressure during compile.

Changes:

- Add no-scratch and scratch CUDA kernels plus thop bindings for trtllm::deepseek_v4_compute_sliding_block_tables and trtllm::deepseek_v4_compute_sliding_block_tables_with_scratch.

- Use a tiled no-scratch row kernel with int4 vectorization when maxBlocksPerSeq is 4-aligned and scalar handling otherwise, so the no-scratch path always uses the new kernel.

- Replace the DeepSeek V4 cache-manager torch.compile block-table functions with direct torch.ops.trtllm custom-op calls.

- Add CUDA unit tests that compare both custom ops against the removed torch reference implementation for scalar and vectorized max-block sizes.

- Add a standalone microbenchmark script for comparing custom-op latency against eager or torch.compile references across no-scratch and scratch cases.

Validation:

- python3 -m py_compile tensorrt_llm/_torch/attention_backend/sparse/deepseek_v4/cache_manager.py tests/unittest/_torch/custom_ops/test_deepseek_v4_block_table.py

- git diff --cached --check

- CMH build_sqsh job 778723: COMPLETED exit=0.

- CMH GPU unit test job 781707: 4 passed in 4.78s.

- CMH no-scratch perf sweep job 780480: comparable production-ish cases averaged +0.15% latency delta versus the previous 2D tiled build, with 16/17 cases within +/-5%.

Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
@tburt-nv
tburt-nv force-pushed the feat/deepseek-v4-block-table-custom-op branch from b8a085c to 45fbc25 Compare July 1, 2026 18:15
@tburt-nv

tburt-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Rebased to pick up #15713

@tburt-nv

tburt-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Oh sorry, I see this is the feature branch. I think we need to cherry-pick #15713 into the feature branch first.

@tburt-nv

tburt-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Looks like it has already been cherry-picked here, so the existing rebase should resolve the issue: #15818

@tburt-nv

tburt-nv commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

/bot run

1 similar comment
@liji-nv

liji-nv commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57083 [ run ] triggered by Bot. Commit: 45fbc25 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57083 [ run ] completed with state FAILURE. Commit: 45fbc25
/LLM/main/L0_MergeRequest_PR pipeline #45873 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

@liji-nv

liji-nv commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57131 [ run ] triggered by Bot. Commit: 45fbc25 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57131 [ run ] completed with state SUCCESS. Commit: 45fbc25
/LLM/main/L0_MergeRequest_PR pipeline #45916 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

@liji-nv

liji-nv commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57380 [ run ] triggered by Bot. Commit: 45fbc25 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57380 [ run ] completed with state SUCCESS. Commit: 45fbc25
/LLM/main/L0_MergeRequest_PR pipeline #46129 completed with status: 'SUCCESS'

CI Report

Link to invocation

@liji-nv
liji-nv merged commit b7a8a8f into NVIDIA:feat/deepseek_v4 Jul 3, 2026
7 of 8 checks passed
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jul 7, 2026
Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jul 7, 2026
Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
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.

4 participants