Skip to content

[Models] Support DeepSeek-V4 GGUF weights mapping and architecture fa… - #126

Open
DjoserKhemSimeu wants to merge 1 commit into
vllm-project:mainfrom
DjoserKhemSimeu:feat/deepseek-v4-support
Open

[Models] Support DeepSeek-V4 GGUF weights mapping and architecture fa…#126
DjoserKhemSimeu wants to merge 1 commit into
vllm-project:mainfrom
DjoserKhemSimeu:feat/deepseek-v4-support

Conversation

@DjoserKhemSimeu

Copy link
Copy Markdown

Summary

This PR adds GGUF weight mapping and configuration parsing support for DeepSeek-V4 architectures (such as DeepSeek-V4-Flash checkpoints).

Motivation & Problem

When serving a DeepSeek-V4 GGUF checkpoint (e.g., bartowski/DeepSeek-V4-Flash-0731-GGUF), model initialization fails during weight name resolution with the following error:

RuntimeError: Unknown gguf model_type: deepseek_v4

Root Causes

  1. Model Type Resolution: In transformers.py, only deepseek_v2 and deepseek_v3 were mapped to the internal deepseek2 GGUF architecture mapping. deepseek_v4 was unhandled, causing a lookup failure in gguf.MODEL_ARCH_NAMES.
  2. Config Parser Architecture Lookup: In config_parser.py, if config.model_type was not yet registered inside transformers' MODEL_FOR_CAUSAL_LM_MAPPING_NAMES and no custom adapter override was set, the parser failed with RuntimeError: Can't get gguf config for {config.model_type} instead of inspecting config.architectures already declared in the Hugging Face config.

Technical Changes

  • GGUF Weights Adapter (vllm_gguf_plugin/weights_adapter/transformers.py):

  • Included "deepseek_v4" alongside "deepseek_v3" and "deepseek_v2" to map to the "deepseek2" GGUF architecture.

  • Set up MoE expert slicing (gate_proj, up_proj, down_proj, and e_score_correction_bias).

  • Config Parser Fallback (vllm_gguf_plugin/config_parser.py):

  • Added graceful fallback to config.architectures[0] when get_adapter_architecture(config) and MODEL_FOR_CAUSAL_LM_MAPPING_NAMES do not have an explicit entry for new or custom causal LM model types.

  • Tests (tests/test_plugin.py):

  • Added unit test test_gguf_config_parser_fallback_to_config_architectures to verify config parser fallback behavior for newly introduced model types with custom architectures.

Verification & Testing

  • Verified tensor name mappings for DeepSeek-V4 MoE layer patterns (blk.{idx}.exp_probs_b.bias, blk.{idx}.ffn_{gate,up,down}_exps.weight).
  • Verified GGUFConfigParser test suite passes and handles both canonical and custom architecture configs.

Signed-off-by: DjoserKhemSimeu [djoser.simeu@gmail.com](mailto:djoser.simeu@gmail.com)

…llback

- Map deepseek_v4 model_type to deepseek2 GGUF architecture name map in TransformersGGUFWeightsAdapter.
- Support fallback to config.architectures in GGUFConfigParser when model_type is not directly in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES.
- Add unit test verifying GGUFConfigParser architecture fallback.

Signed-off-by: DjoserKhemSimeu <djoser.simeu@gmail.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.

1 participant