-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: prepare DeepSeek-V4 draft sliding tables #17178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from tensorrt_llm._torch.attention_backend.sparse.deepseek_v4.deepseek_v4 import ( | ||
| DeepseekV4TrtllmAttentionMetadata, | ||
| ) | ||
| from tensorrt_llm._torch.attention_backend.trtllm import TrtllmAttentionMetadata | ||
|
|
||
|
|
||
| def test_prepare_computes_draft_sliding_block_tables_before_base_prepare(monkeypatch): | ||
| """DeepSeek-V4 MTP draft KV managers need their sliding tables prepared. | ||
|
|
||
| The base TRT-LLM metadata prepare path copies block offsets from both the | ||
| target and draft managers. DeepSeek-V4's copy path consumes precomputed | ||
| sliding-window tables, so the draft manager must compute them before the | ||
| base prepare reaches copy_batch_block_offsets(). | ||
| """ | ||
| metadata = object.__new__(DeepseekV4TrtllmAttentionMetadata) | ||
| metadata.kv_cache_manager = MagicMock() | ||
| metadata.draft_kv_cache_manager = MagicMock() | ||
| metadata.request_ids = [11, 12, 13] | ||
| metadata.num_contexts = 2 | ||
|
|
||
| def stop_at_base_prepare(self): | ||
| raise RuntimeError("base prepare reached") | ||
|
|
||
| monkeypatch.setattr(TrtllmAttentionMetadata, "prepare", stop_at_base_prepare) | ||
|
|
||
| with pytest.raises(RuntimeError, match="base prepare reached"): | ||
| DeepseekV4TrtllmAttentionMetadata.prepare(metadata) | ||
|
|
||
| metadata.kv_cache_manager.compute_sliding_block_tables.assert_called_once_with( | ||
| metadata.request_ids, | ||
| metadata.num_contexts, | ||
| ) | ||
| metadata.draft_kv_cache_manager.compute_sliding_block_tables.assert_called_once_with( | ||
| metadata.request_ids, | ||
| metadata.num_contexts, | ||
| ) | ||
|
Comment on lines
+26
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate candidate CI and QA test-list files.
fd -t f . tests/integration/test_lists | sort
# Check whether this test module or DeepSeek-V4 test group is registered.
rg -n -i -C 2 \
'test_deepseek_v4_metadata|deepseek_v4' \
tests/integration/test_lists || true
# Locate available CBTS scope evidence.
fd -t f 'cbts_touchmap.sqlite' . || true
fd -t f '*coverage*' . | rg -i 'cbts|touchmap' || trueRepository: NVIDIA/TensorRT-LLM Length of output: 12813 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- changed files ---'
git diff --name-status
printf '%s\n' '--- test file diff ---'
git diff -- tests/unittest/_torch/attention/sparse/deepseek_v4/test_deepseek_v4_metadata.py
printf '%s\n' '--- matching test-list entries ---'
rg -n -F \
'unittest/_torch/attention/sparse/deepseek_v4/test_deepseek_v4_metadata.py' \
tests/integration/test_lists || true
printf '%s\n' '--- DeepSeek-V4 test-list entries ---'
rg -n -i -C 1 \
'unittest/_torch/attention/sparse/deepseek_v4' \
tests/integration/test_lists || true
printf '%s\n' '--- CBTS artifacts tracked or present ---'
git ls-files | rg -i '(^|/)(cbts_touchmap\.sqlite|.*cbts.*coverage.*|.*coverage.*cbts.*)$' || true
find . -type f \( -name 'cbts_touchmap.sqlite' -o -iname '*cbts*coverage*' -o -iname '*coverage*cbts*' \) -printRepository: NVIDIA/TensorRT-LLM Length of output: 2077 Add the test module to 🤖 Prompt for AI AgentsSource: Path instructions |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 27204
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 26941
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 496
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 496
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 2045
🏁 Script executed:
Repository: NVIDIA/TensorRT-LLM
Length of output: 540
Annotate the new test functions and mark the local helper as non-public.
Annotate
test_prepare_computes_draft_sliding_block_tables_before_base_prepare()and_stop_at_base_prepare()withpytest.MonkeyPatch,TrtllmAttentionMetadata, andNoneas appropriate. Renamestop_at_base_prepareto_stop_at_base_prepare.Test coverage:
test_prepare_computes_draft_sliding_block_tables_before_base_prepare()was added and is covered byunittest/_torch/attentionintests/integration/test_lists/test-db/l0_b200.yml. Verdict: sufficient.🤖 Prompt for AI Agents
Source: Coding guidelines