From 924484ee4a6ebc79426d27eef31a1ee7d13cbb9a Mon Sep 17 00:00:00 2001 From: Michael Chung <6252325+ArEnSc@users.noreply.github.com> Date: Tue, 12 Apr 2022 06:11:03 -0400 Subject: [PATCH] Add Doc Test GPT-2 (#16439) * First Pass All Tests Pass * WIP * Adding file to documentation tests * Change the base model for the example in the doc test. * Fix Code Styling by running make fixup * Called Style * Reverted to gpt2 model rather than distill gpt2 Then used a token classification model over a sequence model for an example. * Fix Styling Issue * Hopefully ignores the formatting issue. Co-authored-by: ArEnSc --- src/transformers/models/gpt2/modeling_gpt2.py | 14 +++++++++----- utils/documentation_tests.txt | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/transformers/models/gpt2/modeling_gpt2.py b/src/transformers/models/gpt2/modeling_gpt2.py index b0755b804b..94c844f593 100644 --- a/src/transformers/models/gpt2/modeling_gpt2.py +++ b/src/transformers/models/gpt2/modeling_gpt2.py @@ -1231,10 +1231,8 @@ class GPT2DoubleHeadsModel(GPT2PreTrainedModel): >>> # Add a [CLS] to the vocabulary (we should train it also!) >>> num_added_tokens = tokenizer.add_special_tokens({"cls_token": "[CLS]"}) - - >>> embedding_layer = model.resize_token_embeddings( - ... len(tokenizer) - >>> ) # Update the model embeddings with the new vocabulary size + >>> # Update the model embeddings with the new vocabulary size + >>> embedding_layer = model.resize_token_embeddings(len(tokenizer)) >>> choices = ["Hello, my dog is cute [CLS]", "Hello, my cat is cute [CLS]"] >>> encoded_choices = [tokenizer.encode(s) for s in choices] @@ -1350,6 +1348,8 @@ class GPT2ForSequenceClassification(GPT2PreTrainedModel): checkpoint="microsoft/DialogRPT-updown", output_type=SequenceClassifierOutputWithPast, config_class=_CONFIG_FOR_DOC, + expected_output="'LABEL_0'", + expected_loss=5.28, ) def forward( self, @@ -1477,12 +1477,16 @@ class GPT2ForTokenClassification(GPT2PreTrainedModel): self.post_init() @add_start_docstrings_to_model_forward(GPT2_INPUTS_DOCSTRING) + # fmt: off @add_code_sample_docstrings( processor_class=_TOKENIZER_FOR_DOC, - checkpoint="microsoft/DialogRPT-updown", + checkpoint="brad1141/gpt2-finetuned-comp2", output_type=TokenClassifierOutput, config_class=_CONFIG_FOR_DOC, + expected_loss=0.25, + expected_output=["Lead", "Lead", "Lead", "Position", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead", "Lead"], ) + # fmt: on def forward( self, input_ids=None, diff --git a/utils/documentation_tests.txt b/utils/documentation_tests.txt index 5c76137dde..3b45ce5a7f 100644 --- a/utils/documentation_tests.txt +++ b/utils/documentation_tests.txt @@ -15,6 +15,7 @@ src/transformers/models/data2vec/modeling_data2vec_audio.py src/transformers/models/deit/modeling_deit.py src/transformers/models/dpt/modeling_dpt.py src/transformers/models/glpn/modeling_glpn.py +src/transformers/models/gpt2/modeling_gpt2.py src/transformers/models/hubert/modeling_hubert.py src/transformers/models/marian/modeling_marian.py src/transformers/models/mbart/modeling_mbart.py