Fix/dsv4 native transformers warmup - #4878
Open
grimoire wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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_ratesand 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 newtopk_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 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
self-requested a review
August 20, 2026 02:57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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