From 5e1e8fafe79551e372c04d82d77c25f410847dc3 Mon Sep 17 00:00:00 2001 From: JiwenJ <3522936020@qq.com> Date: Sun, 20 Apr 2025 07:49:55 +0000 Subject: [PATCH] add model markdown doc --- docs/source/en/model_doc/plm.md | 54 +++++++++++++++++++++++++++ tests/models/plm/test_modeling_plm.py | 34 +++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 docs/source/en/model_doc/plm.md diff --git a/docs/source/en/model_doc/plm.md b/docs/source/en/model_doc/plm.md new file mode 100644 index 00000000000..1245a05bdd9 --- /dev/null +++ b/docs/source/en/model_doc/plm.md @@ -0,0 +1,54 @@ + + +# PLM + +## Overview + +To be released with the official model launch. + +### Model Details + +To be released with the official model launch. + + +## Usage tips + +To be released with the official model launch. + +## PLMConfig + +[[autodoc]] PLMConfig + +## PLMModel + +[[autodoc]] PLMModel + - forward + +## PLMForCausalLM + +[[autodoc]] PLMForCausalLM + - forward + +## PLMForSequenceClassification + +[[autodoc]] PLMForSequenceClassification + - forward + +## PLMForTokenClassification + +[[autodoc]] PLMForTokenClassification + - forward \ No newline at end of file diff --git a/tests/models/plm/test_modeling_plm.py b/tests/models/plm/test_modeling_plm.py index 81bc567c115..397c7e1c546 100644 --- a/tests/models/plm/test_modeling_plm.py +++ b/tests/models/plm/test_modeling_plm.py @@ -40,6 +40,8 @@ if is_torch_available(): from transformers import ( PLMForCausalLM, PLMModel, + PLMForSequenceClassification, + PLMForTokenClassification, ) # from transformers.models.plm.modeling_plm import ( @@ -319,6 +321,8 @@ class PLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, ( PLMModel, PLMForCausalLM, + PLMForSequenceClassification, + PLMForTokenClassification, ) if is_torch_available() else () @@ -327,7 +331,10 @@ class PLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, pipeline_model_mapping = ( { "feature-extraction": PLMModel, + "text-classification": PLMForSequenceClassification, + "token-classification": PLMForTokenClassification, "text-generation": PLMForCausalLM, + "zero-shot": PLMForSequenceClassification, } if is_torch_available() else {} @@ -423,6 +430,33 @@ class PLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, def test_config(self): self.config_tester.run_common_tests() + def test_PLM_token_classification_model(self): + config, input_dict = self.model_tester.prepare_config_and_inputs_for_common() + config.num_labels = 3 + input_ids = input_dict["input_ids"] + attention_mask = input_ids.ne(1).to(torch_device) + token_labels = ids_tensor([self.model_tester.batch_size, self.model_tester.seq_length], config.num_labels) + model = PLMForTokenClassification(config=config) + model.to(torch_device) + model.eval() + result = model(input_ids, attention_mask=attention_mask, labels=token_labels) + self.assertEqual( + result.logits.shape, + (self.model_tester.batch_size, self.model_tester.seq_length, self.model_tester.num_labels), + ) + + def test_Qwen2_sequence_classification_model(self): + config, input_dict = self.model_tester.prepare_config_and_inputs_for_common() + config.num_labels = 3 + input_ids = input_dict["input_ids"] + attention_mask = input_ids.ne(1).to(torch_device) + sequence_labels = ids_tensor([self.model_tester.batch_size], self.model_tester.type_sequence_label_size) + model = PLMForSequenceClassification(config) + model.to(torch_device) + model.eval() + result = model(input_ids, attention_mask=attention_mask, labels=sequence_labels) + self.assertEqual(result.logits.shape, (self.model_tester.batch_size, self.model_tester.num_labels)) + # def test_model(self): # config_and_inputs = self.model_tester.prepare_config_and_inputs() # self.model_tester.create_and_check_model(*config_and_inputs)