- 
                Notifications
    You must be signed in to change notification settings 
- Fork 151
add deepseek v3 transformers integration #1445
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
          
     Draft
      
      
            echarlaix
  wants to merge
  8
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
deepseekv3
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0717b05
              
                add deepseek v3 transformers integration
              
              
                echarlaix cce99e3
              
                style
              
              
                echarlaix 6fb5d75
              
                merge main
              
              
                echarlaix d254284
              
                modify tests min transformers version
              
              
                echarlaix f959504
              
                add tiny model
              
              
                echarlaix 856128b
              
                add test sdpa
              
              
                echarlaix 185284a
              
                merge main in branch
              
              
                echarlaix 4bf1788
              
                was removed by accident
              
              
                echarlaix File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -93,9 +93,6 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
|  | ||
| if is_transformers_version(">=", "4.46.0"): | ||
| SUPPORTED_ARCHITECTURES += ("glm", "mistral-nemo", "minicpm3", "phi3-moe") | ||
| # openvino 2025.0 required for disabling check_trace | ||
| if is_openvino_version(">=", "2025.0"): | ||
| SUPPORTED_ARCHITECTURES += ("deepseek",) | ||
| 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. actually remote code deepseek_v3 : katuni4ka/tiny-random-deepseek-v3 | ||
|  | ||
| # gptq and awq install disabled for windows test environment | ||
| if platform.system() != "Windows": | ||
|  | @@ -109,7 +106,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
| SUPPORTED_ARCHITECTURES += ("gemma3_text",) | ||
|  | ||
| if is_transformers_version(">=", "4.51.0"): | ||
| SUPPORTED_ARCHITECTURES += ("qwen3", "qwen3_moe") | ||
| SUPPORTED_ARCHITECTURES += ("qwen3", "qwen3_moe", "deepseek_v3") | ||
|  | ||
| if is_transformers_version(">=", "4.51.3"): | ||
| SUPPORTED_ARCHITECTURES += ("glm4",) | ||
|  | @@ -120,6 +117,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
| if is_transformers_version(">=", "4.54.0"): | ||
| # remote code models differs after transformers v4.54 | ||
| SUPPORTED_ARCHITECTURES = tuple(set(SUPPORTED_ARCHITECTURES) - {"minicpm", "minicpm3", "arctic", "deepseek"}) | ||
| SUPPORTED_ARCHITECTURES += ("ernie4_5",) | ||
|  | ||
| if is_transformers_version(">=", "4.55.0"): | ||
| SUPPORTED_ARCHITECTURES += ("gpt_oss", "gpt_oss_mxfp4") | ||
|  | @@ -144,7 +142,6 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
| "exaone", | ||
| "decilm", | ||
| "minicpm3", | ||
| "deepseek", | ||
| ) | ||
|  | ||
| EXPECTED_NUM_SDPA = { | ||
|  | @@ -158,6 +155,8 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
| "chatglm": 2, | ||
| "codegen": 5, | ||
| "codegen2": 2, | ||
| "deepseek_v3": 2, | ||
| "ernie4_5": 4, | ||
| "gpt2": 5, | ||
| "gptj": 5, | ||
| "gpt_neo": 4, | ||
|  | @@ -202,7 +201,6 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): | |
| "mistral-nemo": 8, | ||
| "minicpm3": 6, | ||
| "phi3-moe": 2, | ||
| "deepseek": 2, | ||
| "opt_gptq": 12, | ||
| "mixtral_awq": 2, | ||
| "gemma3_text": 2, | ||
|  | @@ -324,10 +322,6 @@ def test_compare_to_transformers(self, model_arch): | |
|  | ||
| ov_outputs = ov_model.generate(**tokens, generation_config=gen_config) | ||
|  | ||
| # TODO: add back once https://huggingface.co/katuni4ka/tiny-random-minicpm3/discussions/1 merged (for all models) as current mdoeling incompatible with transformers >= v4.49 | ||
| if model_arch in {"deepseek"} and is_transformers_version(">=", "4.49"): | ||
| self.skipTest("Incompatible modeling code") | ||
|  | ||
| additional_inputs = {} | ||
| # gemma2 does not support dynamic cache, it is unfair to compare dynamic cache result vs hybrid cache, | ||
| # align cache representation in torch model | ||
|  | @@ -569,10 +563,6 @@ def test_beam_search(self, model_arch): | |
| if model_arch in ["qwen", "chatglm", "chatglm4"]: | ||
| return | ||
|  | ||
| # TODO: add back once https://huggingface.co/katuni4ka/tiny-random-minicpm3/discussions/1 merged (for all models) as current mdoeling incompatible with transformers >= v4.49 | ||
| if model_arch in {"deepseek"} and is_transformers_version(">=", "4.49"): | ||
| self.skipTest("Incompatible modeling code") | ||
|  | ||
| tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in self.REMOTE_CODE_MODELS) | ||
| if model_arch == "persimmon": | ||
| tokenizer.pad_token_id = tokenizer.bos_token_id | ||
|  | ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
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.
before we can merge : need to fix
rope_interleavefor export https://github.com/huggingface/transformers/blob/v4.55.4/src/transformers/models/deepseek_v3/modeling_deepseek_v3.py#L402