Skip to content

Commit 06b4aac

Browse files
ArEnScmikechung
andauthored
Add Doc Test for GPT-J (#16507)
* Required the values GPTJ unfortunately cannot run the model =) * Added the file to the doc tests * Run Fixup and Style * Fixed with the test versions of gptj. Ran Style and Fixup. * Trigger ci * A Minor Change to License * Fixed spacing added to the benchmark_utils. Then refactored tests to const variables. * Removed strings that were included as default parameters anyways. Co-authored-by: ArEnSc <[email protected]>
1 parent 12bfa97 commit 06b4aac

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/transformers/models/gptj/modeling_gptj.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,19 @@
3636

3737
logger = logging.get_logger(__name__)
3838

39-
_CHECKPOINT_FOR_DOC = "EleutherAI/gpt-j-6B"
39+
_CHECKPOINT_FOR_DOC = "hf-internal-testing/tiny-random-gptj"
4040
_CONFIG_FOR_DOC = "GPTJConfig"
4141
_TOKENIZER_FOR_DOC = "GPT2Tokenizer"
4242

43+
_CHECKPOINT_FOR_QA = "ydshieh/tiny-random-gptj-for-question-answering"
44+
_QA_EXPECTED_OUTPUT = "' was Jim Henson?Jim Henson was a n'"
45+
_QA_EXPECTED_LOSS = 3.13
46+
47+
_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATION = "ydshieh/tiny-random-gptj-for-sequence-classification"
48+
_SEQ_CLASS_EXPECTED_OUTPUT = "'LABEL_0'"
49+
_SEQ_CLASS_EXPECTED_LOSS = 0.76
50+
51+
4352
GPTJ_PRETRAINED_MODEL_ARCHIVE_LIST = [
4453
"EleutherAI/gpt-j-6B",
4554
# See all GPT-J models at https://huggingface.co/models?filter=gptj
@@ -892,9 +901,11 @@ def __init__(self, config):
892901
@add_start_docstrings_to_model_forward(GPTJ_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
893902
@add_code_sample_docstrings(
894903
processor_class=_TOKENIZER_FOR_DOC,
895-
checkpoint=_CHECKPOINT_FOR_DOC,
904+
checkpoint=_CHECKPOINT_FOR_SEQUENCE_CLASSIFICATION,
896905
output_type=SequenceClassifierOutputWithPast,
897906
config_class=_CONFIG_FOR_DOC,
907+
expected_output=_SEQ_CLASS_EXPECTED_OUTPUT,
908+
expected_loss=_SEQ_CLASS_EXPECTED_LOSS,
898909
)
899910
def forward(
900911
self,
@@ -1017,9 +1028,11 @@ def __init__(self, config):
10171028
@add_start_docstrings_to_model_forward(GPTJ_INPUTS_DOCSTRING.format("batch_size, sequence_length"))
10181029
@add_code_sample_docstrings(
10191030
processor_class=_TOKENIZER_FOR_DOC,
1020-
checkpoint=_CHECKPOINT_FOR_DOC,
1031+
checkpoint=_CHECKPOINT_FOR_QA,
10211032
output_type=QuestionAnsweringModelOutput,
10221033
config_class=_CONFIG_FOR_DOC,
1034+
expected_output=_QA_EXPECTED_OUTPUT,
1035+
expected_loss=_QA_EXPECTED_LOSS,
10231036
)
10241037
def forward(
10251038
self,

utils/documentation_tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ src/transformers/models/deit/modeling_deit.py
1919
src/transformers/models/dpt/modeling_dpt.py
2020
src/transformers/models/glpn/modeling_glpn.py
2121
src/transformers/models/gpt2/modeling_gpt2.py
22+
src/transformers/models/gptj/modeling_gptj.py
2223
src/transformers/models/hubert/modeling_hubert.py
2324
src/transformers/models/marian/modeling_marian.py
2425
src/transformers/models/mbart/modeling_mbart.py

0 commit comments

Comments
 (0)