Skip to content

Commit

Permalink
Generate: Add GPTNeoX integration test (huggingface#22346)
Browse files Browse the repository at this point in the history
  • Loading branch information
gante authored Mar 24, 2023
1 parent b796076 commit 0fa4652
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tests/models/gpt_neox/test_modeling_gpt_neox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import unittest

from transformers import GPTNeoXConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device
from transformers import AutoTokenizer, GPTNeoXConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
Expand Down Expand Up @@ -232,3 +232,28 @@ def test_model_for_causal_lm(self):
@unittest.skip(reason="Feed forward chunking is not implemented")
def test_feed_forward_chunking(self):
pass


@require_torch
class GPTNeoXLanguageGenerationTest(unittest.TestCase):
@slow
def test_lm_generate_codegen(self):
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/pythia-410m-deduped")
for checkpointing in [True, False]:
model = GPTNeoXForCausalLM.from_pretrained("EleutherAI/pythia-410m-deduped")

if checkpointing:
model.gradient_checkpointing_enable()
else:
model.gradient_checkpointing_disable()
model.to(torch_device)

inputs = tokenizer("My favorite food is", return_tensors="pt").to(torch_device)
expected_output = (
"My favorite food is the chicken and rice.\n\nI love to cook and bake. I love to cook and bake"
)

output_ids = model.generate(**inputs, do_sample=False, max_new_tokens=20)
output_str = tokenizer.batch_decode(output_ids)[0]

self.assertEqual(output_str, expected_output)

0 comments on commit 0fa4652

Please sign in to comment.