Skip to content

[https://nvbugs/6079901][fix] Avoid divide-by-zero in KVCacheTransfer…#13618

Merged
farazkh80 merged 1 commit into
NVIDIA:mainfrom
farazkh80:fix/nvbugs-6079901-kv-cache-transfer-divide-by-zero
May 24, 2026
Merged

[https://nvbugs/6079901][fix] Avoid divide-by-zero in KVCacheTransfer…#13618
farazkh80 merged 1 commit into
NVIDIA:mainfrom
farazkh80:fix/nvbugs-6079901-kv-cache-transfer-divide-by-zero

Conversation

@farazkh80
Copy link
Copy Markdown
Collaborator

@farazkh80 farazkh80 commented Apr 29, 2026

…Manager::computeBlockTransferBytes for empty pools

The recent kv-cache statistics monitoring commit (580c7a6, "[TRTLLM-11421][feat] Support better kv cache statistics monitoring") derives bytesPerElement as getSizeInBytes()/getSize() inside KVCacheTransferManager::computeBlockTransferBytes. Pools whose primaryPtr is non-null but has zero elements (e.g. layers that contribute no KV cache in NAS-style heterogeneous models such as Llama-3_3-Nemotron-Super-49B-v1) trigger a SIGFPE / integer divide-by-zero on the first onboard transfer that touches such a pool.

Skip pools with zero elements: they legitimately contribute zero transfer bytes, so the stats are unchanged and the divide-by-zero is avoided.

Repro before fix: post-merge L0 stage RTXPro6000D-PyTorch-Post-Merge-1 (test_e2e.py::test_ptp_quickstart_advanced[Nemotron-Super-49B-v1-FP8-...]) crashes with "Floating point exception (8) / Integer divide-by-zero (1)" inside computeBlockTransferBytes during KVCacheManager::addSequenceBatch. After fix the test passes locally on RTX Pro 6000 (SM120) in 73s.

Summary by CodeRabbit

  • Bug Fixes
    • Resolved a crash risk in KV cache transfer operations when encountering empty cache pools, enhancing system reliability and preventing unexpected failures during batch processing.

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)

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

@farazkh80 farazkh80 requested a review from a team as a code owner April 29, 2026 18:57
@farazkh80 farazkh80 changed the title [nvbugs/6079901][fix] Avoid divide-by-zero in KVCacheTransfer… [https://nvbugs/6079901][fix] Avoid divide-by-zero in KVCacheTransfer… Apr 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 29, 2026

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: 1d33ead3-302f-437f-949c-b386a51ee822

📥 Commits

Reviewing files that changed from the base of the PR and between 3b7af1c and b948b0e.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/batch_manager/kvCacheTransferManager.cpp

📝 Walkthrough

Walkthrough

The computeBlockTransferBytes function now includes a guard against empty KV cache pools by checking pool size before computing bytes per element, preventing division-by-zero errors when processing cache transfer operations.

Changes

Cohort / File(s) Summary
KV Cache Division-by-Zero Guard
cpp/tensorrt_llm/batch_manager/kvCacheTransferManager.cpp
Added null-check guard in computeBlockTransferBytes to skip processing when KV cache pool size is zero, preventing divide-by-zero in bytesPerElement calculation while preserving existing partial-vs-full copy byte accounting logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the NVBugs ticket, the fix type, and the specific issue being addressed (divide-by-zero in KVCacheTransfer), directly matching the changeset.
Description check ✅ Passed The PR description thoroughly explains the issue (divide-by-zero crash in heterogeneous models), the solution (skip zero-element pools), includes reproduction details, and confirms the fix was tested. However, the Description and Test Coverage sections of the template remain unfilled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

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

@farazkh80
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #46207 [ run ] triggered by Bot. Commit: b948b0e Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

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

@farazkh80
Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions
Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@farazkh80
Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #47012 [ run ] triggered by Bot. Commit: b948b0e Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

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

@farazkh80 farazkh80 force-pushed the fix/nvbugs-6079901-kv-cache-transfer-divide-by-zero branch from b948b0e to a40cfce Compare May 13, 2026 15:53
@farazkh80
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #48210 [ run ] triggered by Bot. Commit: a40cfce Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

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

@farazkh80 farazkh80 force-pushed the fix/nvbugs-6079901-kv-cache-transfer-divide-by-zero branch from a40cfce to 3dc73e4 Compare May 20, 2026 15:07
…Manager::computeBlockTransferBytes for empty pools

The recent kv-cache statistics monitoring commit (580c7a6,
"[TRTLLM-11421][feat] Support better kv cache statistics monitoring")
derives bytesPerElement as getSizeInBytes()/getSize() inside
KVCacheTransferManager::computeBlockTransferBytes. Pools whose
primaryPtr is non-null but has zero elements (e.g. layers that
contribute no KV cache in NAS-style heterogeneous models such as
Llama-3_3-Nemotron-Super-49B-v1) trigger a SIGFPE / integer
divide-by-zero on the first onboard transfer that touches such a pool.

Skip pools with zero elements: they legitimately contribute zero
transfer bytes, so the stats are unchanged and the divide-by-zero is
avoided.

Repro before fix: post-merge L0 stage RTXPro6000D-PyTorch-Post-Merge-1
(test_e2e.py::test_ptp_quickstart_advanced[Nemotron-Super-49B-v1-FP8-...])
crashes with "Floating point exception (8) / Integer divide-by-zero (1)"
inside computeBlockTransferBytes during KVCacheManager::addSequenceBatch.
After fix the test passes locally on RTX Pro 6000 (SM120) in 73s.

Signed-off-by: Faraz Khoubsirat <[email protected]>
@farazkh80 farazkh80 force-pushed the fix/nvbugs-6079901-kv-cache-transfer-divide-by-zero branch from 3dc73e4 to 48a9ea9 Compare May 23, 2026 19:37
@farazkh80
Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #50065 [ run ] triggered by Bot. Commit: 48a9ea9 Link to invocation

@tensorrt-cicd
Copy link
Copy Markdown
Collaborator

PR_Github #50065 [ run ] completed with state SUCCESS. Commit: 48a9ea9
/LLM/main/L0_MergeRequest_PR pipeline #39621 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@farazkh80 farazkh80 merged commit c02475e into NVIDIA:main May 24, 2026
7 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.

3 participants