-
Notifications
You must be signed in to change notification settings - Fork 286
implement of leftpadding #2242
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
implement of leftpadding #2242
Conversation
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! couple comments
@mattdangerw |
@sachinprasadhs It seems that this error has nothing to do with me. But it's worth raising a new issue to fix it. |
@mattdangerw Could you please check if we meet the criteria for merging now? |
expected_output = [[3, 3, 1, 5, 6, 7, 2], [3, 1, 8, 9, 10, 11, 2]] | ||
self.assertAllEqual(output, expected_output) | ||
|
||
def test_truncation_side_flips(self): |
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.
I'm not sure we need all of these. We might just need test_truncation
and test_truncation_without_end_value
for these next three tests.
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.
I'm not sure we need all of these. We might just need and for these next three tests.
test_truncation``test_truncation_without_end_value
I did both left and right scenarios in all the tests. I think it's still necessary.
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.
Let's at least remove the "side_flips" from the name. I don't think any reader would understand what that means. test_truncation
and test_truncation_without_endvalue
@@ -139,6 +142,20 @@ def check_special_value_type(value, value_name): | |||
|
|||
self.pad_value = pad_value | |||
self.return_padding_mask = return_padding_mask | |||
self.padding_side = padding_side | |||
|
|||
def pad(self, x, shape, pad_value): |
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.
Pull this into a util in tensor_utils.py
or something like that. We will also need it for the multi segment packer.
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.
Pull this into a util in or something like that. We will also need it for the multi segment packer.
tensor_utils.py
I don't think this is necessary. Only Bert-like models are using multi-segment packers. For Bert-like models, there is no essential difference between left padding and right padding.
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 want it first and foremost for uniformity of the API. But also, this is not just for BERT-like. Gemma3 and PaliGemma use it, for example.
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 want it first and foremost for uniformity of the API. But also, this is not just for BERT-like. Gemma3 and PaliGemma use it, for example.
OK, I have fulfilled this requirement. Please check
@@ -147,3 +288,39 @@ def test_get_config(self): | |||
} | |||
|
|||
self.assertEqual(config, {**config, **expected_config_subset}) | |||
|
|||
def test_return_padding_mask_right_padding(self): |
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.
In keeping with the other tests, just leave these in the same test with a # right padding
and # left padding
comment.
expected_output = [[3, 3, 1, 5, 6, 7, 2], [3, 1, 8, 9, 10, 11, 2]] | ||
self.assertAllEqual(output, expected_output) | ||
|
||
def test_truncation_side_flips(self): |
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.
Let's at least remove the "side_flips" from the name. I don't think any reader would understand what that means. test_truncation
and test_truncation_without_endvalue
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! Just last couple minor comments. This looks good.
@@ -124,6 +125,7 @@ def __init__( | |||
sep_value=None, | |||
pad_value=None, | |||
truncate="round_robin", | |||
padding_side="right", |
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.
please add a docstring
@@ -163,6 +165,8 @@ def check_special_value_type(value, value_name): | |||
|
|||
self.pad_value = pad_value | |||
|
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.
nit: remove this empty line
@mattdangerw Can my implementation be merged? |
from #2237