-
Notifications
You must be signed in to change notification settings - Fork 296
Allow flexible positions in Gemma #2389
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
base: master
Are you sure you want to change the base?
Changes from all commits
2afaadd
01dcfea
208dc7f
36c82d4
8b84c99
5f5c167
23e1109
edc3ec0
3cbeb8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -720,6 +720,47 @@ def compare(actual, expected): | |
output = ops.argmax(output, axis=-1) | ||
self.assertAllEqual(output, expected_labels) | ||
|
||
def run_positions_test( | ||
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. do we think this is generic and will extend beyond gemma? if so ok to leave here. if not I might park this directly in the gemma tests. 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. Yeah, we should do this for all |
||
self, | ||
cls, | ||
init_kwargs, | ||
vocabulary_size, | ||
): | ||
"""Tests that conventional and flexible positions give same output.""" | ||
model = cls(**init_kwargs) | ||
|
||
rng = np.random.default_rng(seed=42) | ||
x1 = { | ||
"token_ids": rng.integers(low=1, high=vocabulary_size, size=(2, 5)), | ||
"padding_mask": np.array( | ||
[ | ||
[True] * 3 + [False] * 2, | ||
[True] * 2 + [False] * 3, | ||
] | ||
), | ||
} | ||
# Convert token_ids to list for easier manipulation. | ||
token_ids_lst = x1["token_ids"].tolist() | ||
x2 = { | ||
"token_ids": np.array( | ||
[ | ||
[0] + token_ids_lst[0][:3] + [0], | ||
[0] * 2 + token_ids_lst[1][:2] + [0], | ||
] | ||
), | ||
"padding_mask": np.array( | ||
[ | ||
[False] + [True] * 3 + [False], | ||
[False] * 2 + [True] * 2 + [False], | ||
] | ||
), | ||
} | ||
|
||
output_1 = model.predict(x1) | ||
output_2 = model.predict(x2) | ||
self.assertAllClose(output_1[0][:3], output_2[0][1:4]) | ||
self.assertAllClose(output_1[1][:2], output_2[1][2:4]) | ||
|
||
def get_test_data_dir(self): | ||
return str(pathlib.Path(__file__).parent / "test_data") | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.