-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Fix dpr<>bart config for RAG #8808
Merged
patrickvonplaten
merged 5 commits into
huggingface:master
from
patrickvonplaten:fix_dpr_bart_config
Nov 27, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c333ff
correct dpr test and bert pos fault
patrickvonplaten 9a44d2f
fix dpr bert config problem
patrickvonplaten 2e61f17
fix merge
patrickvonplaten 9da52fb
fix layoutlm
patrickvonplaten 0c03ab1
add config to dpr as well
patrickvonplaten 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
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 |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
if is_torch_available(): | ||
import torch | ||
|
||
from transformers import BertConfig, DPRConfig, DPRContextEncoder, DPRQuestionEncoder, DPRReader | ||
from transformers import DPRConfig, DPRContextEncoder, DPRQuestionEncoder, DPRReader | ||
from transformers.models.dpr.modeling_dpr import ( | ||
DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST, | ||
DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST, | ||
|
@@ -104,7 +104,8 @@ def prepare_config_and_inputs(self): | |
token_labels = ids_tensor([self.batch_size, self.seq_length], self.num_labels) | ||
choice_labels = ids_tensor([self.batch_size], self.num_choices) | ||
|
||
config = BertConfig( | ||
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. This is dangerous when new params are added to Bert, it'll lead to silent errors 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 catch |
||
config = DPRConfig( | ||
projection_dim=self.projection_dim, | ||
vocab_size=self.vocab_size, | ||
hidden_size=self.hidden_size, | ||
num_hidden_layers=self.num_hidden_layers, | ||
|
@@ -115,14 +116,12 @@ def prepare_config_and_inputs(self): | |
attention_probs_dropout_prob=self.attention_probs_dropout_prob, | ||
max_position_embeddings=self.max_position_embeddings, | ||
type_vocab_size=self.type_vocab_size, | ||
is_decoder=False, | ||
initializer_range=self.initializer_range, | ||
) | ||
config = DPRConfig(projection_dim=self.projection_dim, **config.to_dict()) | ||
|
||
return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels | ||
|
||
def create_and_check_dpr_context_encoder( | ||
def create_and_check_context_encoder( | ||
self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels | ||
): | ||
model = DPRContextEncoder(config=config) | ||
|
@@ -133,7 +132,7 @@ def create_and_check_dpr_context_encoder( | |
result = model(input_ids) | ||
self.parent.assertEqual(result.pooler_output.shape, (self.batch_size, self.projection_dim or self.hidden_size)) | ||
|
||
def create_and_check_dpr_question_encoder( | ||
def create_and_check_question_encoder( | ||
self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels | ||
): | ||
model = DPRQuestionEncoder(config=config) | ||
|
@@ -144,7 +143,7 @@ def create_and_check_dpr_question_encoder( | |
result = model(input_ids) | ||
self.parent.assertEqual(result.pooler_output.shape, (self.batch_size, self.projection_dim or self.hidden_size)) | ||
|
||
def create_and_check_dpr_reader( | ||
def create_and_check_reader( | ||
self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels | ||
): | ||
model = DPRReader(config=config) | ||
|
@@ -199,17 +198,17 @@ def setUp(self): | |
def test_config(self): | ||
self.config_tester.run_common_tests() | ||
|
||
def test_dpr_context_encoder_model(self): | ||
def test_context_encoder_model(self): | ||
config_and_inputs = self.model_tester.prepare_config_and_inputs() | ||
self.model_tester.create_and_check_dpr_context_encoder(*config_and_inputs) | ||
self.model_tester.create_and_check_context_encoder(*config_and_inputs) | ||
|
||
def test_dpr_question_encoder_model(self): | ||
def test_question_encoder_model(self): | ||
config_and_inputs = self.model_tester.prepare_config_and_inputs() | ||
self.model_tester.create_and_check_dpr_question_encoder(*config_and_inputs) | ||
self.model_tester.create_and_check_question_encoder(*config_and_inputs) | ||
|
||
def test_dpr_reader_model(self): | ||
def test_reader_model(self): | ||
config_and_inputs = self.model_tester.prepare_config_and_inputs() | ||
self.model_tester.create_and_check_dpr_reader(*config_and_inputs) | ||
self.model_tester.create_and_check_reader(*config_and_inputs) | ||
|
||
@slow | ||
def test_model_from_pretrained(self): | ||
|
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.
maybe add a comment that mentions backward compatibility ?