-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: UTC-459: Handling breadth first with evaluation enabled #9076
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
Merged
+120
−29
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
11a59ba
Handling breadth first with evaluation enabled
mcanu 7e31ed6
Sync Follow Merge dependencies
mcanu f2ab943
Merge branch 'develop' into 'fb-utc-459'
mcanu 434be89
Updated task factory to use the correct overlap configured with the p…
mcanu 6f3654b
Remove old implementation
mcanu 7fab1a1
Added tests
mcanu bd5cd98
Merge branch 'develop' into 'fb-utc-459'
mcanu a201344
Added comment
mcanu c3e926b
Fix test
mcanu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| from core.utils.common import conditional_atomic, db_is_not_sqlite, load_func | ||
| from core.utils.db import fast_first | ||
| from django.conf import settings | ||
| from django.db.models import BooleanField, Case, Count, Exists, F, Max, OuterRef, Q, QuerySet, Value, When | ||
| from django.db.models import Case, Count, Exists, F, Max, OuterRef, Q, QuerySet, When | ||
| from django.db.models.fields import DecimalField | ||
| from projects.functions.stream_history import add_stream_history | ||
| from projects.models import Project | ||
|
|
@@ -75,37 +75,27 @@ def _try_tasks_with_overlap(tasks: QuerySet[Task]) -> Tuple[Union[Task, None], Q | |
| return None, tasks.filter(overlap=1) | ||
|
|
||
|
|
||
| def _try_breadth_first( | ||
| tasks: QuerySet[Task], user: User, project: Project, attempt_gt_first: bool = False | ||
| ) -> Union[Task, None]: | ||
| def _try_breadth_first(tasks: QuerySet[Task], user: User, project: Project) -> Union[Task, None]: | ||
| """Try to find tasks with maximum amount of annotations, since we are trying to label tasks as fast as possible""" | ||
|
|
||
| # Exclude ground truth annotations from the count when not in onboarding window | ||
| # to prevent GT tasks from being prioritized via breadth-first logic | ||
| annotation_filter = ~Q(annotations__completed_by=user) | ||
| if not attempt_gt_first: | ||
| annotation_filter &= ~Q(annotations__ground_truth=True) | ||
| if project.annotator_evaluation_enabled: | ||
| tasks = _annotate_has_ground_truths(tasks) | ||
| tasks = tasks.filter(has_ground_truths=False) | ||
|
|
||
| tasks = tasks.annotate(annotations_count=Count('annotations', filter=annotation_filter)) | ||
| tasks = tasks.annotate(annotations_count=Count('annotations', filter=~Q(annotations__completed_by=user))) | ||
| max_annotations_count = tasks.aggregate(Max('annotations_count'))['annotations_count__max'] | ||
| if max_annotations_count == 0: | ||
| # there is no any labeled tasks found | ||
| return | ||
|
|
||
| # find any task with maximal amount of created annotations | ||
| not_solved_tasks_labeling_started = tasks.annotate( | ||
| reach_max_annotations_count=Case( | ||
| When(annotations_count=max_annotations_count, then=Value(True)), | ||
| default=Value(False), | ||
| output_field=BooleanField(), | ||
| ) | ||
| ) | ||
| not_solved_tasks_labeling_with_max_annotations = not_solved_tasks_labeling_started.filter( | ||
| reach_max_annotations_count=True | ||
| ) | ||
| if not_solved_tasks_labeling_with_max_annotations.exists(): | ||
| # try to complete tasks that are already in progress | ||
| return _get_random_unlocked(not_solved_tasks_labeling_with_max_annotations, user) | ||
|
|
||
| if max_annotations_count == 0 or max_annotations_count is None: | ||
| # No tasks with annotations, let the next step in the pipeline handle it | ||
| return None | ||
|
|
||
| # Find tasks at the maximum amount of annotations | ||
| candidates = tasks.filter(annotations_count=max_annotations_count) | ||
|
Collaborator
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. good simplification :D |
||
| if candidates.exists(): | ||
| # Select randomly from candidates | ||
| result = _get_random_unlocked(candidates, user) | ||
| return result | ||
| return None | ||
|
|
||
|
|
||
| def _try_uncertainty_sampling( | ||
|
|
@@ -289,7 +279,7 @@ def get_next_task_without_dm_queue( | |
| if not next_task and project.maximum_annotations > 1: | ||
| # if there are already labeled tasks, but task.overlap still < project.maximum_annotations, randomly sampling from them | ||
| logger.debug(f'User={user} tries depth first from prepared tasks') | ||
| next_task = _try_breadth_first(not_solved_tasks, user, project, attempt_gt_first) | ||
| next_task = _try_breadth_first(not_solved_tasks, user, project) | ||
| if next_task: | ||
| queue_info += (' & ' if queue_info else '') + 'Breadth first queue' | ||
|
|
||
|
|
||
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
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
Oops, something went wrong.
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.
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.
Leave comment here explaining why we're doing this , how it applies to onboarding/ongoing etc