Skip to content

[https://nvbugs/6029882][fix] Fix attentionOp fp8 mla kvreuse workspace calculation - #14852

Merged
pengbowang-nv merged 2 commits into
NVIDIA:mainfrom
pengbowang-nv:dev-fix-dsr1-qseqlen-ima
Jun 15, 2026
Merged

[https://nvbugs/6029882][fix] Fix attentionOp fp8 mla kvreuse workspace calculation#14852
pengbowang-nv merged 2 commits into
NVIDIA:mainfrom
pengbowang-nv:dev-fix-dsr1-qseqlen-ima

Conversation

@pengbowang-nv

@pengbowang-nv pengbowang-nv commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

The attentionOp would use max_num_token to prepare for fp8 mla kvcache reuse workspace, but it would require total_kv_len when use, thus causing a potential OOB access to workspace. This has affected multiple CI tests.

In terms of memory overhead, under extreme border condition (max possible number of sentence and max possible kvcache reuse), the workspace requires prefill_batch_size×(max_num_token - 1)×hidden_size worth of space, where prefill_batch_size=min⁡(num_tokens,max_batch_size).

For the case of bs=1024 and max_num_token=8192, the DS model would require about 9 GB of space. However, in practice, when KV cache reuse is enabled, prefill_batch_size is usually in the range of 10 to 100. Under those conditions, the required space works out to only a few hundred MB, which is entirely acceptable.

Summary by CodeRabbit

  • Tests
    • Removed a test waiver entry, enabling an additional test variant to run in the test suite.

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.

@pengbowang-nv
pengbowang-nv marked this pull request as draft June 2, 2026 06:00
@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions

github-actions Bot commented Jun 2, 2026

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.

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A test waiver entry for a DeepSeek NVFP4 multi-GPU throughput test variant is removed from the skip list, allowing this previously skipped test case to run.

Changes

Test waiver removal

Layer / File(s) Summary
Remove DeepSeek NVFP4 throughput test waiver
tests/integration/test_lists/waives.txt
The waiver entry for TestDeepSeekR1::test_nvfp4_multi_gpus[throughput_mtp] is removed, removing this test variant from the skip list.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • crazydemo
  • jieli-matrix
  • LarryXFly
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title references a valid NVBugs ID and includes a clear fix type, but conflicts with the actual changeset which removes a test waiver rather than fixing attention op calculations. Update the title to accurately reflect that the change removes a test waiver (e.g., '[https://nvbugs/6029882][fix] Unwaive test_nvfp4_multi_gpus throughput_mtp test') rather than describing an attention op fix.
Description check ⚠️ Warning The PR description sections (Description and Test Coverage) are completely empty despite having a clear template structure that requires them to be filled out. Fill in the 'Description' section explaining the bug fix for the workspace OOB access issue and why the test waiver can be removed. Add 'Test Coverage' section listing the test(s) that are now passing (e.g., accuracy/test_llm_api_pytorch.py::TestDeepSeekR1::test_nvfp4_multi_gpus[throughput_mtp]).
✅ Passed checks (3 passed)
Check name Status Explanation
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.

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

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

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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-1,GB200-8_GPUs-2_Nodes-PyTorch-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51523 [ run ] triggered by Bot. Commit: 9e546b6 Link to invocation

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51548 [ run ] triggered by Bot. Commit: 9e546b6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51523 [ run ] completed with state ABORTED. Commit: 9e546b6
/LLM/main/L0_MergeRequest_PR pipeline #40921 (Partly Tested) 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51548 [ run ] completed with state SUCCESS. Commit: 9e546b6
/LLM/main/L0_MergeRequest_PR pipeline #40943 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2" --disable-reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51580 [ run ] triggered by Bot. Commit: 9e546b6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51580 [ run ] completed with state SUCCESS. Commit: 9e546b6
/LLM/main/L0_MergeRequest_PR pipeline #40969 (Partly Tested) 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2" --disable-reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51611 [ run ] triggered by Bot. Commit: 9e546b6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51611 [ run ] completed with state SUCCESS. Commit: 9e546b6
/LLM/main/L0_MergeRequest_PR pipeline #40994 (Partly Tested) 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2" --disable-reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51733 [ run ] triggered by Bot. Commit: 9e546b6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51733 [ run ] completed with state SUCCESS. Commit: 9e546b6
/LLM/main/L0_MergeRequest_PR pipeline #41107 (Partly Tested) 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2" --disable-reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51751 [ run ] triggered by Bot. Commit: ba23ebf Link to invocation

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2" --disable-reuse-test

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51751 [ run ] completed with state SUCCESS. Commit: ba23ebf
/LLM/main/L0_MergeRequest_PR pipeline #41124 (Partly Tested) 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51776 [ run ] triggered by Bot. Commit: 8b9465d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51776 [ run ] completed with state SUCCESS. Commit: 8b9465d
/LLM/main/L0_MergeRequest_PR pipeline #41142 (Partly Tested) 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

@pengbowang-nv
pengbowang-nv force-pushed the dev-fix-dsr1-qseqlen-ima branch from 8b9465d to 7779960 Compare June 10, 2026 09:30
@pengbowang-nv pengbowang-nv changed the title [https://nvbugs/6029882][fix] Unwaive related test [https://nvbugs/6029882][fix] Fix attentionOp fp8 mla kvreuse workspace calculation Jun 10, 2026
@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "GB200-8_GPUs-2_Nodes-PyTorch-1,GB200-8_GPUs-2_Nodes-PyTorch-2,GB200-8_GPUs-2_Nodes-PyTorch-3,GB200-8_GPUs-2_Nodes-PyTorch-4,DGX_B300-4_GPUs-PyTorch-Post-Merge-2,GB300-4_GPUs-PyTorch-Post-Merge-2 ,DGX_B200-8_GPUs-PyTorch-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53896 [ run ] completed with state FAILURE. Commit: 9275333
/LLM/main/L0_MergeRequest_PR pipeline #42995 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

Signed-off-by: Pengbo Wang <221450789+pengbowang-nv@users.noreply.github.com>
Signed-off-by: Pengbo Wang <221450789+pengbowang-nv@users.noreply.github.com>
@pengbowang-nv
pengbowang-nv force-pushed the dev-fix-dsr1-qseqlen-ima branch from 9275333 to 615aee7 Compare June 13, 2026 05:00
@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --add-multi-gpu-test --disable-fail-fast --extra-stage "DGX_B200-8_GPUs-PyTorch-1, DGX_B200-8_GPUs-PyTorch-3, GB200-8_GPUs-2_Nodes-PyTorch-1, GB200-8_GPUs-2_Nodes-PyTorch-2, DGX_B300-4_GPUs-PyTorch-Post-Merge-1, GB300-4_GPUs-PyTorch-Post-Merge-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54014 [ run ] triggered by Bot. Commit: 615aee7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54014 [ run ] completed with state SUCCESS. Commit: 615aee7
/LLM/main/L0_MergeRequest_PR pipeline #43097 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --add-multi-gpu-test --disable-fail-fast --extra-stage "DGX_B200-8_GPUs-PyTorch-1, DGX_B200-8_GPUs-PyTorch-3, GB200-8_GPUs-2_Nodes-PyTorch-1, GB200-8_GPUs-2_Nodes-PyTorch-2, DGX_B300-4_GPUs-PyTorch-Post-Merge-1, GB300-4_GPUs-PyTorch-Post-Merge-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54137 [ run ] triggered by Bot. Commit: 615aee7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54137 [ run ] completed with state SUCCESS. Commit: 615aee7
/LLM/main/L0_MergeRequest_PR pipeline #43220 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

@pengbowang-nv

Copy link
Copy Markdown
Collaborator Author

/bot run --add-multi-gpu-test --disable-fail-fast --extra-stage "DGX_B200-8_GPUs-PyTorch-1, DGX_B200-8_GPUs-PyTorch-3, GB200-8_GPUs-2_Nodes-PyTorch-1, GB200-8_GPUs-2_Nodes-PyTorch-2, DGX_B300-4_GPUs-PyTorch-Post-Merge-1, GB300-4_GPUs-PyTorch-Post-Merge-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54185 [ run ] triggered by Bot. Commit: 615aee7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54185 [ run ] completed with state SUCCESS. Commit: 615aee7
/LLM/main/L0_MergeRequest_PR pipeline #43265 completed with status: 'SUCCESS'

CI Report

Link to invocation

@pengbowang-nv
pengbowang-nv marked this pull request as ready for review June 15, 2026 03:28
@pengbowang-nv
pengbowang-nv merged commit 870f9b5 into NVIDIA:main Jun 15, 2026
19 of 20 checks passed
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 15, 2026
…pace in KV cache estimation

The fp8 context-MLA K/V dequant workspace scales with the summed attended KV
length (total_kv_len) of the context requests in a forward step. The KV-cache
memory estimator profiles with fresh-prefill dummy requests against an empty
cache, so total_kv_len there is pinned near max_num_tokens and this workspace
sits at its floor. With block reuse at serving time total_kv_len decouples from
max_num_tokens and the workspace can grow far past the profiled floor, but the
estimator has already handed that headroom to the KV pool, causing an OOM
mid-forward (TestKimiK2::test_nvfp4[4gpus], exposed once NVIDIA#14852 sized the
workspace correctly by total_kv_len).

Fix the estimation rather than the memory fraction (a user co-tenancy knob):
- Split the KV budget between the pool (k bytes/token, all layers) and the
  workspace (w bytes/token, one shared layer buffer) at a common token count, so
  max_tokens = budget / (k + w) and the reserved workspace covers exactly
  max_tokens tokens of attended KV.
- Enforce it at admission: the scheduler trims scheduled context requests so
  their summed attended KV length stays within the pool token capacity, always
  keeping at least one request as a forward-progress guard. No-op for
  non-fp8-MLA models.

The per-token workspace cost is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken), exposed via nanobind, so the
estimator's reserve can never drift from the runtime allocation.

Remove the waive for TestKimiK2::test_nvfp4[4gpus] (nvbugs/6368562) to re-enable
the test.

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 20, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). No-op for non-fp8-MLA
  models.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 20, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). No-op for non-fp8-MLA
  models.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 21, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Only reserve when block reuse is enabled and chunked prefill is disabled -- the
  sole conditions under which total_kv_len can exceed the profiled floor. Without
  reuse the workspace is bounded by max_num_tokens (already profiled); with
  chunked prefill each attention launch is independently bounded by its own chunk
  buffer. Reserving in those configs would double-count and needlessly shrink the
  KV pool (up to ~37% for Kimi-K2 attention-DP). No-op there and for non-fp8-MLA
  models.
- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). A carried cap of None
  (no reservation) applies no admission cap.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation. This accounts for the fp8 staging term
only; the separate BF16 full-gather buffers on the reuse path are a follow-up, so
the reserve bounds but does not by itself eliminate reuse-driven OOM.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 21, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Only reserve when block reuse is enabled and chunked prefill is disabled -- the
  sole conditions under which total_kv_len can exceed the profiled floor. Without
  reuse the workspace is bounded by max_num_tokens (already profiled); with
  chunked prefill each attention launch is independently bounded by its own chunk
  buffer. Reserving in those configs would double-count and needlessly shrink the
  KV pool (up to ~37% for Kimi-K2 attention-DP). No-op there and for non-fp8-MLA
  models.
- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). A carried cap of None
  (no reservation) applies no admission cap.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation. This accounts for the fp8 staging term
only; the separate BF16 full-gather buffers on the reuse path are a follow-up, so
the reserve bounds but does not by itself eliminate reuse-driven OOM.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 22, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Only reserve when block reuse is enabled and chunked prefill is disabled -- the
  sole conditions under which total_kv_len can exceed the profiled floor. Without
  reuse the workspace is bounded by max_num_tokens (already profiled); with
  chunked prefill each attention launch is independently bounded by its own chunk
  buffer. Reserving in those configs would double-count and needlessly shrink the
  KV pool (up to ~37% for Kimi-K2 attention-DP). No-op there and for non-fp8-MLA
  models.
- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). A carried cap of None
  (no reservation) applies no admission cap.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation. This accounts for the fp8 staging term
only; the separate BF16 full-gather buffers on the reuse path are a follow-up, so
the reserve bounds but does not by itself eliminate reuse-driven OOM.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.com>
eopXD added a commit to eopXD/TensorRT-LLM that referenced this pull request Jul 22, 2026
…pace in KV cache estimation

TestKimiK2::test_nvfp4[4gpus] (NVFP4, TP4 + attention-DP, block reuse) OOMs
mid-forward in the MLA context attention. The fp8 context-MLA K/V dequant
workspace is one buffer shared across attention layers whose size scales with the
summed attended KV length (total_kv_len) of the step's context requests. The
KV-cache estimator profiles fresh-prefill dummies against an empty cache, so
total_kv_len there sits near max_num_tokens and the workspace is at its floor;
with block reuse at serving time total_kv_len decouples from max_num_tokens and
the workspace grows past the floor, but the estimator has already handed that
headroom to the KV pool. The under-reservation was latent until NVIDIA#14852 sized the
workspace by total_kv_len.

Reserve for the workspace during estimation instead of lowering
free_gpu_memory_fraction (a user co-tenancy knob):

- Only reserve when block reuse is enabled and chunked prefill is disabled -- the
  sole conditions under which total_kv_len can exceed the profiled floor. Without
  reuse the workspace is bounded by max_num_tokens (already profiled); with
  chunked prefill each attention launch is independently bounded by its own chunk
  buffer. Reserving in those configs would double-count and needlessly shrink the
  KV pool (up to ~37% for Kimi-K2 attention-DP). No-op there and for non-fp8-MLA
  models.
- Reserve w * L_cap bytes, where w is the per-token workspace cost and L_cap is
  the never-stall worst-case summed attended KV per step,
  min(max_batch_size, max_num_tokens) * max_seq_len. Clamp the reserve to the
  per-token split budget * w / (k + w) so a memory-constrained node shares the
  budget at a common token count instead of starving the pool; equivalently the
  pool keeps max((budget - w*L_cap)/k, budget/(k + w)) tokens.
- The estimator carries the exact cap it reserved for (min(L_cap, budget/(k+w)))
  onto the KV manager; the scheduler reads it directly and trims context requests
  whose summed attended total_kv_len would exceed it, always keeping one request
  as a forward-progress guard. It does not re-derive the cap from pool layout,
  which KV-cache-manager V2 overstates (blocks_in_primary_pool forwards
  get_page_index_upper_bound, not the available-page count). A carried cap of None
  (no reservation) applies no admission cap.
- w counts the fp8 K/V dequant staging buffer. A sparse-MLA model normally stages
  nothing, but with the short-seq MHA fallback enabled
  (TRTLLM_MLA_SHORT_SEQ_MHA_THRESHOLD > 0) it routes short sequences through the
  dense context path that does stage the buffer, so reserve for that case too.
- KvCacheConfig.fp8_context_mla_kv_len_cap (prototype) overrides L_cap to trade
  reserved workspace for KV pool; the scheduler enforces it.

w is a single source of truth in C++
(AttentionOp::contextMlaWorkspaceBytesPerToken, guarded against
getWorkspaceSizeForContext by a TLLM_CHECK) exposed via nanobind, so the reserve
cannot drift from the runtime allocation. This accounts for the fp8 staging term
only; the separate BF16 full-gather buffers on the reuse path are a follow-up, so
the reserve bounds but does not by itself eliminate reuse-driven OOM.

Re-enable TestKimiK2::test_nvfp4[4gpus] (remove the nvbugs/6368562 waive).

Co-Authored-By: Yueh-Ting Chen <yueh.ting.chen@gmail.com>
Signed-off-by: Yueh-Ting Chen <yuehtingc@nvidia.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.

3 participants