Repository: huggingface/transformers
Pull request: add DeepseekV3ForTokenClassification

# What does this PR do?

Add DeepseekV3ForTokenClassificaiton for using as a value model.

Fixes #40639 


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?
@ArthurZucker

Changed files:
filename: docs/source/en/model_doc/deepseek_v3.md
patch: @@ -188,3 +188,8 @@ error, it means NCCL was probably not loaded.
 
 [[autodoc]] DeepseekV3ForSequenceClassification
     - forward
+
+## DeepseekV3ForTokenClassification
+
+[[autodoc]] DeepseekV3ForTokenClassification
+    - forward
\ No newline at end of file

filename: src/transformers/models/auto/modeling_auto.py
patch: @@ -1412,6 +1412,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
         ("data2vec-text", "Data2VecTextForTokenClassification"),
         ("deberta", "DebertaForTokenClassification"),
         ("deberta-v2", "DebertaV2ForTokenClassification"),
+        ("deepseek_v3", "DeepseekV3ForTokenClassification"),
         ("diffllama", "DiffLlamaForTokenClassification"),
         ("distilbert", "DistilBertForTokenClassification"),
         ("electra", "ElectraForTokenClassification"),

filename: src/transformers/models/deepseek_v3/modeling_deepseek_v3.py
patch: @@ -17,7 +17,11 @@
 from ...integrations import use_kernel_forward_from_hub
 from ...masking_utils import create_causal_mask
 from ...modeling_flash_attention_utils import FlashAttentionKwargs
-from ...modeling_layers import GenericForSequenceClassification, GradientCheckpointingLayer
+from ...modeling_layers import (
+    GenericForSequenceClassification,
+    GenericForTokenClassification,
+    GradientCheckpointingLayer,
+)
 from ...modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
 from ...modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
 from ...modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
@@ -676,9 +680,14 @@ class DeepseekV3ForSequenceClassification(GenericForSequenceClassification, Deep
     pass
 
 
+class DeepseekV3ForTokenClassification(GenericForTokenClassification, DeepseekV3PreTrainedModel):
+    pass
+
+
 __all__ = [
     "DeepseekV3PreTrainedModel",
     "DeepseekV3Model",
     "DeepseekV3ForCausalLM",
     "DeepseekV3ForSequenceClassification",
+    "DeepseekV3ForTokenClassification",
 ]

filename: src/transformers/models/deepseek_v3/modular_deepseek_v3.py
patch: @@ -9,7 +9,7 @@
 from ...activations import ACT2FN
 from ...cache_utils import Cache
 from ...modeling_flash_attention_utils import FlashAttentionKwargs
-from ...modeling_layers import GenericForSequenceClassification
+from ...modeling_layers import GenericForSequenceClassification, GenericForTokenClassification
 from ...modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
 from ...processing_utils import Unpack
 from ...utils import logging
@@ -361,9 +361,14 @@ class DeepseekV3ForSequenceClassification(GenericForSequenceClassification, Deep
     pass
 
 
+class DeepseekV3ForTokenClassification(GenericForTokenClassification, DeepseekV3PreTrainedModel):
+    pass
+
+
 __all__ = [
     "DeepseekV3PreTrainedModel",
     "DeepseekV3Model",
     "DeepseekV3ForCausalLM",
     "DeepseekV3ForSequenceClassification",
+    "DeepseekV3ForTokenClassification",
 ]

filename: tests/models/deepseek_v3/test_modeling_deepseek_v3.py
patch: @@ -43,6 +43,7 @@
     from transformers import (
         DeepseekV3ForCausalLM,
         DeepseekV3ForSequenceClassification,
+        DeepseekV3ForTokenClassification,
         DeepseekV3Model,
     )
     from transformers.models.deepseek_v3.modeling_deepseek_v3 import (
@@ -217,6 +218,7 @@ class DeepseekV3ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTeste
             DeepseekV3Model,
             DeepseekV3ForCausalLM,
             DeepseekV3ForSequenceClassification,
+            DeepseekV3ForTokenClassification,
         )
         if is_torch_available()
         else ()
@@ -226,6 +228,7 @@ class DeepseekV3ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTeste
         {
             "feature-extraction": DeepseekV3Model,
             "text-classification": DeepseekV3ForSequenceClassification,
+            "token-classification": DeepseekV3ForTokenClassification,
             "text-generation": DeepseekV3ForCausalLM,
             "zero-shot": DeepseekV3ForSequenceClassification,
         }