add model markdown doc

This commit is contained in:
JiwenJ 2025-04-20 07:49:55 +00:00
parent 90ce1658c3
commit 5e1e8fafe7
2 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,54 @@
<!--Copyright 2024 The PLM Team and The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# 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

View File

@ -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)