-
Notifications
You must be signed in to change notification settings - Fork 6.6k
refactor namespaces in criterion interface #1729
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
refactor namespaces in criterion interface #1729
Conversation
…s as an attribute.
…new criterion interface.
facebook-github-bot
left a comment
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.
@myleott has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
I'm almost done with this one, hoping to merge later today :) I had to make some changes to support backwards compatibility, since there's a lot of internal criterions that still use the old API. |
|
Sorry for all the extra work, but I'm excited about these changes. Wiring up hydra should be a breeze after this. |
|
Sorry for the delay, still iterating on this. Will be merged soon... |
facebook-github-bot
left a comment
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.
@myleott is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes #1672 in part (part 1: [context](#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: #1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
|
Woo! Glad to see this land -- thanks, @myleott. I see that this was a lot of work -- if there's anything you want to push back to me for the other components, please don't hesitate. |
|
Yeah thanks for all your work getting this started! The first one took a bit longer because it required some discussion and figuring out the right way to maintain backward compatibility. The key is providing a Legacy version of the base classes, for example the LegacyFairseqCriterion. It’d be super helpful if you can add some of those for the other PRs, but in general I hope the next few of these should be easier to merge. |
|
Awesome. Happy to do that - looks like a light lift after the hard decision making was made up front. 😄 Should I also make PRs to pytorch/translate in tandem (like the associated commit w/ this PR)? I was given the impression that translate and fairseq were going to merge eventually, but I don't suspect that changes the need to keep them in lock step. |
|
Hi, what is the purpose for this change which might cause all the user defined criterion broken? |
|
The purpose of this change is to divorce components in fairseq from argparsing. If you want to use some model/criterion/task/etc. outside of fairseq, you basically cannot. We have retained a |
|
I don't understand. |
|
The original criterion design stored an |
|
Not sure what do you mean by "you need one to create a criterion which is inconvenient. " |
|
Basically: The above code is very nasty and makes the code very hard to test, very hard to use in production situations, and very brittle. |
|
Ok.. If it is the case, everything needs to be changed in fairseq... |
|
These changes are not as dramatic as they appear. Basically it's standardizing the code toward best practices which has a lot of benefit downstream in testing and consuming. |
|
I think using "args" makes it much easier to pass arguments which might be defined outside of criterions. |
|
Why can't you pass it to the constructor directly? |
|
Also, if a function requires 10+ more arguments as inputs to "init", it will also be very difficult to read and work with. |
|
Difficult to read: maybe. Consider abstracting something. |
|
Anyway, I still don't think it is a good idea to remove all "args" to build the current model/criterion/etc. |
|
To make this exceeding clear: if someone develops an interesting optimizer in fairseq that I want to use in my pytorch code, there's currently no way to do that unless I mock argument parsing. Optimizers should not care about argument parsing much like models, lr schedulers, tokenizers, byte-pair encoders, loss functions, or just about any other component in software (outside of a main function) should not. |
|
..but this PR is about "loss functions". |
|
Yes, I understand. |
|
Sorry just catching up on this. @MultiPath, I shared some context/motivation in the other PR (#1743), but I agree that we need to be careful here for several reasons:
|
Hmm, seems this is a github bug. Please ignore the "Files Changed" shown in this PR. The actual commit is 46b773a, which is different from what's shown in this PR. Notably, we didn't end up adding |
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch#1672 in part (part 1: [context](facebookresearch#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch/fairseq#1672 in part (part 1: [context](facebookresearch/fairseq#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch/fairseq#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch/fairseq#1672 in part (part 1: [context](facebookresearch/fairseq#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch/fairseq#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch/fairseq#1672 in part (part 1: [context](facebookresearch/fairseq#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch/fairseq#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch/fairseq#1672 in part (part 1: [context](facebookresearch/fairseq#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch/fairseq#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Summary: # Before submitting - [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements) - [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)? - [x] Did you make sure to update the docs? - [x] Did you write any new necessary tests? ## What does this PR do? Fixes facebookresearch/fairseq#1672 in part (part 1: [context](facebookresearch/fairseq#1714 (comment))) ## PR review Anyone in the community is free to review the PR once the tests have passed. If we didn't discuss your PR in Github issues there's a high chance it will not be merged. ## Did you have fun? Make sure you had fun coding � Pull Request resolved: facebookresearch/fairseq#1729 Differential Revision: D20049353 Pulled By: myleott fbshipit-source-id: 732077a1cc339c9f7ebe26dae42a7e8d7b5a07b4
Before submitting
What does this PR do?
Fixes #1672 in part (part 1: context)
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃