Add strategy to store results in evaluation loop#30267
Merged
amyeroberts merged 7 commits intohuggingface:mainfrom Apr 17, 2024
Merged
Add strategy to store results in evaluation loop#30267amyeroberts merged 7 commits intohuggingface:mainfrom
amyeroberts merged 7 commits intohuggingface:mainfrom
Conversation
amyeroberts
approved these changes
Apr 16, 2024
Contributor
amyeroberts
left a comment
There was a problem hiding this comment.
Beautiful - the simplification in the trainer code speaks for itself. Thanks for adding this and making our trainer more flexible for different datasets!
All looks good to me, but let's get another approval from @muellerzr or @pacman100 to confirm this change to trainer is OK before merging
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
muellerzr
approved these changes
Apr 16, 2024
Contributor
Author
|
All tests are green, all comments addressed 🙂 |
5 tasks
ydshieh
pushed a commit
that referenced
this pull request
Apr 23, 2024
* Add evaluation loop container for interm. results * Add tests for EvalLoopContainer * Formatting * Fix padding_index in test and typo * Move EvalLoopContainer to pr_utils to avoid additional imports * Fix `eval_do_concat_batches` arg description * Fix EvalLoopContainer import
Merged
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
In certain scenarios, the evaluation loop concatenates tensors, making them unusable. For instance, in the object detection evaluation loop, the label structure is as follows:
Each dictionary represents one image, with all its bounding boxes.
The problem arises when the trainer runs the evaluation loop and must concatenate each result. It concatenates the labels of every evaluation batch, using the internal nested_concat.
The result of the nested concatenation of these labels will look like this:
[ { 'size': tensor([ 771, 1333, 1333, 763]), 'image_id': tensor([1592, 44]), 'class_labels': tensor([0, 0, 1]), 'boxes': tensor([[0.2268, 0.6586, 0.1567, 0.1480], [0.4216, 0.4584, 0.3794, 0.1979], [0.4216, 0.4584, 0.3794, 0.1979]]), 'area': tensor([23827.1230, 76371.3984, 76371.3984]), 'iscrowd': tensor([0, 0]), 'orig_size': tensor([561, 970, 926, 530]) }, ... ]This results in the concatenation of all boxes, making it impossible to distinguish which boxes belong to each image.
This PR introduces an additional strategy for storing batches. By setting
eval_do_concat_batches=Falsein the training arguments, batches will be stored as separate list items rather than being concatenated.Fixes # (issue)
#25939
https://discuss.huggingface.co/t/possible-fix-for-trainer-evaluation-with-object-detection/72307
https://discuss.huggingface.co/t/add-metrics-to-object-detection-example/31213/12
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@muellerzr and @pacman100
@amyeroberts