Skip to content

Fix/dsv4 native transformers warmup - #4878

Open
grimoire wants to merge 4 commits into
InternLM:mainfrom
grimoire:fix/dsv4-native-transformers-warmup
Open

Fix/dsv4 native transformers warmup#4878
grimoire wants to merge 4 commits into
InternLM:mainfrom
grimoire:fix/dsv4-native-transformers-warmup

Conversation

@grimoire

Copy link
Copy Markdown
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

Copilot AI lite review requested due to automatic review settings August 18, 2026 09:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates LMDeploy’s DeepSeek-V4 integration to align with native Transformers config/schema and improves the CUDA V4 indexer warmup and metadata handling, while removing LMDeploy’s custom HF config registration paths.

Changes:

  • Switch DeepSeek-V4 compression config handling to native layer_types/compress_rates and force V4 cache block sizing to a fixed 256.
  • Extend the V4 indexer backend interface to include num_heads/head_dim, and fix DeepGEMM warmup + empty-sequence handling via new topk_seqlens.
  • Remove LMDeploy custom DeepSeek (v4/v32) HF config classes and manual config registration/export hooks.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/pytorch/config/test_model_config.py Updates tests to reflect native V4 layer schema and fixed block sizing expectations.
lmdeploy/pytorch/transformers/configuration_deepseek_v4.py Removes re-export shim for the custom DeepSeek-V4 HF config.
lmdeploy/pytorch/transformers/configuration_deepseek_v32.py Removes re-export shim for the custom DeepSeek-V32 HF config.
lmdeploy/pytorch/transformers/init.py Drops register_config from the public pytorch transformers helper exports.
lmdeploy/pytorch/nn/v4_indexer.py Updates V4 indexer wrapper to pass num_heads/head_dim into backend builder.
lmdeploy/pytorch/models/deepseek_v4.py Adapts DeepSeek-V4 model wiring to native config fields and new compression-ratio translation.
lmdeploy/pytorch/configurations/deepseek_v4.py Adds native layer schema translation, forces V4_BLOCK_SIZE=256, updates cache config finalization.
lmdeploy/pytorch/backends/indexer.py Extends BaseV4IndexerBuilder.build() signature to include num_heads/head_dim.
lmdeploy/pytorch/backends/cuda/v4_indexer.py Fixes DeepGEMM warmup shapes/keys and requires topk_seqlens for packed scoring path.
lmdeploy/pytorch/backends/cuda/attention/v4.py Adds topk_seqlens to index-score metadata and clamps scheduler inputs safely for empty rows.
lmdeploy/hf_configs/configuration_deepseek_v4.py Deletes LMDeploy’s custom DeepSeek-V4 PretrainedConfig implementation.
lmdeploy/hf_configs/configuration_deepseek_v32.py Deletes LMDeploy’s custom DeepSeek-V32 PretrainedConfig implementation.
lmdeploy/hf_configs/init.py Simplifies config loading to a direct AutoConfig.from_pretrained() call.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lmdeploy/hf_configs/__init__.py Outdated
Comment on lines +2 to +6
from transformers import AutoConfig

from lmdeploy.utils import get_logger

logger = get_logger('lmdeploy')


@lru_cache
def register_config(model_type: str):
if model_type == 'deepseek_v32':
from .configuration_deepseek_v32 import DeepseekV32Config
AutoConfig.register(DeepseekV32Config.model_type, DeepseekV32Config)
elif model_type == 'deepseek_v4':
from .configuration_deepseek_v4 import DeepseekV4Config
AutoConfig.register(DeepseekV4Config.model_type, DeepseekV4Config)
else:
logger.debug(f'Can not register config for model_type: {model_type}')


def config_from_pretrained(pretrained_model_name_or_path: str, **kwargs):
try:
return AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
except Exception as e:
logger.debug(f'AutoConfig.from_pretrained failed: {e}, try register config manually.')
# some models do not provide auto map for config
from transformers import PretrainedConfig
trust_remote_code = kwargs.pop('trust_remote_code', None)
config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
model_type = config_dict.get('model_type', None)
if trust_remote_code is not None:
kwargs['trust_remote_code'] = trust_remote_code
register_config(model_type)
try:
return AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
except Exception as e:
return PretrainedConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
return AutoConfig.from_pretrained(pretrained_model_name_or_path, **kwargs)
Comment on lines +42 to +51
compress_rates = hf_config.compress_rates
compressed_layer_types = set(layer_types).difference({'sliding_attention'})
missing_rates = sorted(compressed_layer_types.difference(compress_rates))
if missing_rates:
raise ValueError(f'DeepSeek-V4 compress_rates is missing layer types: {missing_rates}.')

compress_ratios = [
0 if layer_type == 'sliding_attention' else compress_rates[layer_type]
for layer_type in layer_types
]
@lvhan028
lvhan028 self-requested a review August 20, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants