-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
cleanup tf unittests: part 2 #6260
Conversation
Hmm, looks like
and flake complains:
if I add the desired by How do I resolve such conflict? edit: found a workaround, by removing the trailing comma:
|
99% of this PR has been facilitated by running:
|
Codecov Report
@@ Coverage Diff @@
## master #6260 +/- ##
=======================================
Coverage 80.08% 80.08%
=======================================
Files 153 153
Lines 27984 27984
=======================================
Hits 22412 22412
Misses 5572 5572
Continue to review full report at Codecov.
|
Hi @stas00. I'm in the process of changing all model outputs of TF models to the same as PyTorch and updated all the tests. This is in #6247 that I expect to merge today (once merge conflicts are handled and I've added the templates). Could you wait a tiny bit and then apply the same PERL commands you did in #6196 ? |
Oh, that's even better - yes, of course, I will wait, @sgugger! If you remember please ping me when this is done. Thank you! Could you also check on this one? |
For the slow test, we can use |
Part of this rewrite was replacing |
The outputs PR has been merged, so pinging you @stas00 |
I will rework this PR to match @sgugger changes. |
@sgugger, after your merge, these 3 tf tests are still using the old style it seems:
I reverted to the |
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 taking care of the merge conflicts. I guess we can deal with the 4 remaining tests (one PT, 3 TF) in a separate PR.
Yes. Could you please instruct me on how to proceed with those or will you take care of them? |
I think just using the result1/result2 in the assers instead of grouping everything in a dict should be fine. |
tests/test_modeling_tf_transfo_xl.py
Outdated
self.parent.assertEqual(result["hidden_states_2"].shape, (self.batch_size, self.seq_length, self.hidden_size)) | ||
hidden_states_1 = hidden_states_1.numpy() | ||
hidden_states_2 = hidden_states_2.numpy() | ||
mems_1 = [mem.numpy() for mem in mems_1] |
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 don't think all the calls to numpy are necessary. Do the tests pass without them?
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.
It's not needed, indeed. removed and pushed.
please re-run CI - unrelated failure - thank you. |
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 @stas00 , there are a few .numpy left that we can clean up and this will be good to merge. Pinging @sshleifer or @LysandreJik for a second review.
tests/test_modeling_tf_transfo_xl.py
Outdated
@@ -92,30 +92,21 @@ def create_and_check_transfo_xl_model(self, config, input_ids_1, input_ids_2, lm | |||
model = TFTransfoXLModel(config) | |||
|
|||
hidden_states_1, mems_1 = model(input_ids_1).to_tuple() | |||
mems_1 = [mem.numpy() for mem in mems_1] |
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.
Same for those here, I don't think you need that line and the equivalent for mems2
tests/test_modeling_tf_xlnet.py
Outdated
"mems_2": [mem.numpy() for mem in mems_2], | ||
"all_logits_2": all_logits_2.numpy(), | ||
} | ||
mems_1 = [mem.numpy() for mem in mems_1] |
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.
Same remark for the .numpy in this file.
tests/test_modeling_xlnet.py
Outdated
[[self.seq_length, self.batch_size, self.hidden_size]] * self.num_hidden_layers, | ||
) | ||
|
||
self.parent.assertEqual(result2.loss.shape, ()) | ||
self.parent.assertEqual(result2.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)) | ||
self.parent.assertListEqual( | ||
list(list(mem.size()) for mem in result2["mems"]), | ||
list(list(mem.size()) for mem in result2.mems), |
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.
can this be
self.assertListEqual([mem.size() for mem in result2.mems], [(self.seq_length, self.batch_size, self.hidden_size)]*self.num_hidden_layers)
somewhat cleaner IMO but no big deal.
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.
plus .size()
=> .shape
- will do. thank you.
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.
So changing:
- list(list(mem.shape) for mem in mems_1),
- [[self.mem_len, self.batch_size, self.hidden_size]] * self.num_hidden_layers,
+ [mem.shape for mem in mems_1],
+ [(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers,
Perl:
perl -0777 -pi -e 's#self.parent.assertListEqual\(
[\s\n]*
list \( list \( mem.(?:shape|size\(\))\)\sfor\smem\s(.*?) \),
[\s\n]*
\[\[ (.*?) \]\]\s\*\sself.num_hidden_layers,
#self.parent.assertListEqual(
[mem.shape for mem $1],
[($2)] * self.num_hidden_layers,#xmsg' tests/test*py
edit: pushed
If there is any more cleanup you'd like to see send me the before and after code snippets. |
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.
LGTM, thanks @stas00!
This reverts commit 61131c6.
This is part 2 of #6196 and the original issue #5973. This PR brings the tf and pt tests and templates to an almost identical template.
edit: as other parts of code have evolved, the part of this comment below this line is no longer relevant - see the development of this PR in the subsequent comments
As discussed at #5973 (comment), a wrapper was needed to turn plain
results
dicts into object-like dicts, so that theresults.key
works the same whether it's returned by a class or it was just a local dict. I'm not sureDictAttr
is the best name, but I had to start somewhere - it'll be an easy thing to rename it once you help me to find a better name. I did look for a pre-existing library to facilitate this, but didn't find anything that doesn't require installing another package.To remind - the key change in part1 and in this clean up is to replace:
with:
like it was done in part 1, except part 1 didn't need the wrapper -
results
were bona fide objects there.there is also one torch test in this batch that required the wrapper too:
test_modeling_transfo_xl.py
@sshleifer