-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Add head_mask/decoder_head_mask for BART #9404
Changes from 13 commits
afb08e7
0b61dc0
77b6ded
6293562
3ff4428
dbf9845
7b2b892
fb610e7
1a3dcba
ccffa78
e98b531
6a8b8ea
634a313
ba64b95
b661c9b
7ff0dec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,12 @@ def test_forward_signature(self): | |
"decoder_attention_mask", | ||
"encoder_outputs", | ||
] | ||
self.assertListEqual(arg_names[:5], expected_arg_names) | ||
if model.config.model_type in ["bart", "mbart", "marian", "blenderbot", "blenderbot-small", "pegasus"]: | ||
expected_arg_names.insert(2, "head_mask") | ||
expected_arg_names.insert(5, "decoder_head_mask") | ||
self.assertListEqual(arg_names[:7], expected_arg_names) | ||
else: | ||
self.assertListEqual(arg_names[:5], expected_arg_names) | ||
else: | ||
expected_arg_names = ["input_ids"] | ||
self.assertListEqual(arg_names[:1], expected_arg_names) | ||
|
@@ -395,10 +400,31 @@ def _create_and_check_torchscript(self, config, inputs_dict): | |
attention_mask = inputs["attention_mask"] | ||
decoder_input_ids = inputs["decoder_input_ids"] | ||
decoder_attention_mask = inputs["decoder_attention_mask"] | ||
|
||
traced_model = torch.jit.trace( | ||
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. Let's try to not change this test. However, we don't really like these |
||
model, (input_ids, attention_mask, decoder_input_ids, decoder_attention_mask) | ||
) | ||
if model.config.model_type not in [ | ||
"bart", | ||
"mbart", | ||
"marian", | ||
"blenderbot", | ||
"blenderbot-small", | ||
"pegasus", | ||
]: | ||
traced_model = torch.jit.trace( | ||
model, (input_ids, attention_mask, decoder_input_ids, decoder_attention_mask) | ||
) | ||
else: | ||
head_mask = inputs["head_mask"] | ||
decoder_head_mask = inputs["decoder_head_mask"] | ||
traced_model = torch.jit.trace( | ||
model, | ||
( | ||
input_ids, | ||
attention_mask, | ||
head_mask, | ||
decoder_input_ids, | ||
decoder_attention_mask, | ||
decoder_head_mask, | ||
), | ||
) | ||
else: | ||
input_ids = inputs["input_ids"] | ||
traced_model = torch.jit.trace(model, input_ids) | ||
|
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.
The order of the signature arguments IMO should be as follows:
The reason is that
decoder_input_ids
is more important thanhead_mask
for torchscript.We models like Bart we would still like to be able to use torchscript as follows:
instead of having to do
where as
head_mask
would have to be a tensor of all 1's since in 99% of the times it's not used for torchscript.So it'd be great if we can slightly change the order in all
...Model
and all...ForConditionalGeneration
models so that we have:head_mask
is just used to little for torchscript so that we have to break the (first all encoder inputs, then all decoder inputs) logic here.We can adapt the test as follows: