Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ def prepare_for_indexer_k_cache(self):
self.host_indexer_k_cache_block_offsets[: self.num_seqs],
non_blocking=True,
)
# Columns beyond each sequence's allocated indexer blocks contain BAD_PAGE_INDEX (-1).
# CUDA-graph padded token slots may still compute scatter addresses from those columns
# before being ignored, so map them to block 0, matching the base DSA metadata path.
self.indexer_k_cache_block_offsets.clamp_(min=0)
Comment thread
longlee0622 marked this conversation as resolved.
Comment thread
longlee0622 marked this conversation as resolved.

def prepare_for_block_tables(self):
"""Prepare block tables for sliding-window and compressed attention."""
Expand Down
27 changes: 24 additions & 3 deletions tensorrt_llm/_torch/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,14 @@ def update_sparse_attention_indexer_config(pretrained_config, kwargs):
pretrained_config, 'compress_ratios', None)
num_base_layers = pretrained_config.num_hidden_layers
spec_config = kwargs.get('spec_config', None)
if (spec_config is not None
and getattr(spec_config, 'num_nextn_predict_layers',
None) is None):
# ``num_nextn_predict_layers`` is MTP-specific (only read on
# the is_mtp_one_model path). Only set it on configs that
# actually declare the field; other DeepSeek-V4 spec modes
# (e.g. DSpark, which carries its own draft stage count) do
# not, and a blind setattr would fail pydantic validation.
if (spec_config is not None and 'num_nextn_predict_layers'
in type(spec_config).model_fields
and spec_config.num_nextn_predict_layers is None):
spec_config.num_nextn_predict_layers = getattr(
pretrained_config, 'num_nextn_predict_layers', 1)
mtp_enabled = (spec_config is not None and
Expand Down Expand Up @@ -990,6 +995,22 @@ def update_sparse_attention_indexer_config(pretrained_config, kwargs):
if window_size is None:
window_size = pretrained_config.sliding_window

# DeepSeek-V4 needs explicit per-layer compress ratios. They
# must come from the checkpoint config or a user override; we
# intentionally do not synthesize a default list (it would
# silently change sparse-attention semantics). Fail fast with
# an actionable message instead of letting the normalization
# below raise an opaque TypeError on None.
if compress_ratios is None:
raise ValueError(
"DeepSeek-V4 requires per-layer `compress_ratios`, "
"but none were found in the checkpoint config and "
"none were provided via `sparse_attention_config`. "
"Set `compress_ratios` in the model's config.json, or "
"pass `sparse_attention_config="
"DeepSeekV4SparseAttentionConfig(compress_ratios=[...])`"
" in --extra_llm_api_options.")

# Normalize checkpoint-facing ratio 0 (SWA-only/uncompressed)
# to 1 internally so cache allocation math works. The
# external config keeps the original semantics.
Expand Down
16 changes: 16 additions & 0 deletions tensorrt_llm/_torch/models/dspark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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.

"""DSpark draft-model components."""
Loading
Loading