-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Sequence Classification class in GPTNeo #11906
Merged
LysandreJik
merged 2 commits into
huggingface:master
from
bhadreshpsavani:enable-seq-class
May 28, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule datasets
added at
d95b95
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
GPT2Tokenizer, | ||
GPTNeoConfig, | ||
GPTNeoForCausalLM, | ||
GPTNeoForSequenceClassification, | ||
GPTNeoModel, | ||
) | ||
from transformers.models.gpt_neo.modeling_gpt_neo import GPTNeoAttentionMixin | ||
|
@@ -238,6 +239,16 @@ def create_and_check_lm_head_model(self, config, input_ids, input_mask, head_mas | |
self.parent.assertEqual(result.loss.shape, ()) | ||
self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)) | ||
|
||
def create_and_check_gpt_neo_for_sequence_classification( | ||
self, config, input_ids, input_mask, head_mask, token_type_ids, mc_token_ids, sequence_labels, *args | ||
): | ||
config.num_labels = self.num_labels | ||
model = GPTNeoForSequenceClassification(config) | ||
model.to(torch_device) | ||
model.eval() | ||
result = model(input_ids, attention_mask=input_mask, token_type_ids=token_type_ids, labels=sequence_labels) | ||
self.parent.assertEqual(result.logits.shape, (self.batch_size, self.num_labels)) | ||
|
||
def create_and_check_forward_and_backwards(self, config, input_ids, input_mask, head_mask, token_type_ids, *args): | ||
model = GPTNeoForCausalLM(config) | ||
model.to(torch_device) | ||
|
@@ -274,7 +285,9 @@ def prepare_config_and_inputs_for_common(self): | |
@require_torch | ||
class GPTNeoModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): | ||
|
||
all_model_classes = (GPTNeoModel, GPTNeoForCausalLM) if is_torch_available() else () | ||
all_model_classes = ( | ||
(GPTNeoModel, GPTNeoForCausalLM, GPTNeoForSequenceClassification) if is_torch_available() else () | ||
) | ||
all_generative_model_classes = (GPTNeoForCausalLM,) if is_torch_available() else () | ||
fx_ready_model_classes = all_model_classes | ||
test_missing_keys = False | ||
|
@@ -305,6 +318,10 @@ def test_gpt_neo_lm_head_model(self): | |
config_and_inputs = self.model_tester.prepare_config_and_inputs() | ||
self.model_tester.create_and_check_lm_head_model(*config_and_inputs) | ||
|
||
def test_gpt_neo_sequence_classification_model(self): | ||
config_and_inputs = self.model_tester.prepare_config_and_inputs() | ||
self.model_tester.create_and_check_gpt_neo_for_sequence_classification(*config_and_inputs) | ||
Comment on lines
+321
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
|
||
def test_gpt_neo_gradient_checkpointing(self): | ||
config_and_inputs = self.model_tester.prepare_config_and_inputs(gradient_checkpointing=True) | ||
self.model_tester.create_and_check_forward_and_backwards(*config_and_inputs) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to add a test for this in
GPTNeoModelTest
class, otherwise, it won't run.see the GPT2 test
transformers/tests/test_modeling_gpt2.py
Lines 460 to 463 in afe479a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!
I will fix it.