Skip to content
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

Improve validation frame distribution in tasks with honeypots #8776

Merged
merged 11 commits into from
Dec 12, 2024

Conversation

zhiltsov-max
Copy link
Contributor

@zhiltsov-max zhiltsov-max commented Dec 4, 2024

Motivation and context

  • Changed honeypot selection algorithm in task creation to be more uniform
  • Changed random honeypot reroll algorithm to produce/maintain a uniform distribution of validation frames in the task

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced uniformity in validation frame distribution for honeypot tasks.
    • Improved selection process for validation frames, ensuring fair allocation across jobs.
  • Bug Fixes

    • Refined error handling for validation frame selection and task configurations.
  • Tests

    • Added new tests for validation frames and honeypot management.
    • Updated existing tests to improve robustness and error handling related to task annotations.

@zhiltsov-max zhiltsov-max marked this pull request as draft December 4, 2024 17:42
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request focus on enhancing the management of validation frames within honeypot tasks in the CVAT application. Key updates include the introduction of a more uniform selection process for validation frames, improvements in the handling of honeypot frames, and refinements to the validation logic in various serializers and task management functions. Additionally, the test suite has been expanded and updated to ensure robust coverage of these changes, particularly concerning the interaction between validation frames and task annotations.

Changes

File Path Change Summary
changelog.d/20241205_161129_mzhiltso_update_honeypot_selection.md Enhanced uniformity of validation frames distribution and improved random honeypot rerolls.
cvat/apps/engine/serializers.py Updated JobValidationLayoutWriteSerializer and TaskValidationLayoutWriteSerializer for better validation frame management. Added logic for uniform frame selection and updated update method signatures.
cvat/apps/engine/task.py Modified _create_thread function for uniform selection of validation frames and improved error handling in frame count validation. Added _pool_generator for frame selection.
tests/python/rest_api/test_tasks.py Added new tests for validation frames, enhanced existing tests, improved error handling, and refactored code for clarity. New methods added for testing honeypot frames and task annotations.

Poem

In fields of code where frames do play,
A rabbit hops, brightening the day.
With honeypots now in perfect line,
Validation's dance is simply divine!
So let us cheer for frames so fair,
In every task, joy fills the air! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zhiltsov-max zhiltsov-max marked this pull request as ready for review December 5, 2024 14:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
cvat/apps/engine/serializers.py (1)

1356-1358: Simplify the assignment of validation_layout

The assignment of validation_layout can be simplified by removing unnecessary parentheses.

Apply this diff to improve readability:

-            validation_layout: Optional[models.ValidationLayout] = (
-                getattr(instance.data, 'validation_layout', None)
-            )
+            validation_layout: Optional[models.ValidationLayout] = getattr(instance.data, 'validation_layout', None)
tests/python/rest_api/test_tasks.py (2)

2268-2276: Refactor duplicated validation distribution test into a helper function

The code for testing the uniform distribution of validation frames is duplicated. To improve maintainability and reduce redundancy, consider extracting this logic into a helper function.

Apply this diff to replace the duplicated code with a helper function call:

-                assert max(validation_frame_counts.values()) <= 1 + min(
-                    validation_frame_counts.values()
-                )
+                assert_uniform_distribution(validation_frame_counts)

Define the helper function outside the test methods:

def assert_uniform_distribution(counts):
    assert max(counts.values()) <= 1 + min(counts.values())

4480-4488: Refactor duplicated validation distribution test using the helper function

The code for testing the uniform distribution of validation frames is duplicated here. Use the helper function to improve code maintainability.

Apply this diff to replace the duplicated code:

-                    assert max(validation_frame_counts.values()) <= 1 + min(
-                        validation_frame_counts.values()
-                    )
+                    assert_uniform_distribution(validation_frame_counts)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d86c816 and 1b71f6a.

📒 Files selected for processing (4)
  • changelog.d/20241205_161129_mzhiltso_update_honeypot_selection.md (1 hunks)
  • cvat/apps/engine/serializers.py (5 hunks)
  • cvat/apps/engine/task.py (2 hunks)
  • tests/python/rest_api/test_tasks.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • changelog.d/20241205_161129_mzhiltso_update_honeypot_selection.md
🔇 Additional comments (2)
cvat/apps/engine/task.py (1)

1282-1283: Validation frames allocation logic is correct

The implementation for assigning validation frames to jobs using itertools.islice and adding them to job_frames ensures a uniform distribution of validation frames across jobs, as intended.

cvat/apps/engine/serializers.py (1)

1417-1418: Verify that assigning -1 to db_image.real_frame is acceptable

Setting db_image.real_frame to -1 may cause issues if negative values are not handled appropriately elsewhere in the codebase. Please verify that this assignment is intended and that all dependent code can handle real_frame being -1.

cvat/apps/engine/task.py Show resolved Hide resolved
cvat/apps/engine/serializers.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 67.50000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 73.89%. Comparing base (f098ee5) to head (970d2da).
Report is 26 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8776      +/-   ##
===========================================
- Coverage    73.96%   73.89%   -0.07%     
===========================================
  Files          409      409              
  Lines        43942    43930      -12     
  Branches      3985     3986       +1     
===========================================
- Hits         32500    32464      -36     
- Misses       11442    11466      +24     
Components Coverage Δ
cvat-ui 78.35% <ø> (+0.01%) ⬆️
cvat-server 70.07% <67.50%> (-0.14%) ⬇️

@Marishka17 Marishka17 self-assigned this Dec 9, 2024
cvat/apps/engine/serializers.py Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a name related to honeypots, since we already have a quality control app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't suppose this file to contain only honeypot-related logic. Ideally, I'd extract some common bits from regular gt job logic handling as well.

@@ -1354,6 +1360,8 @@ def update(self, instance: models.Task, validated_data: dict[str, Any]) -> model
gt_job_meta_serializer.is_valid(raise_exception=True)
gt_job_meta_serializer.save()

validation_layout.refresh_from_db()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please clarify why we need to make one more request to the database if we can use the data already returned after the update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I got the idea. gt_job_meta_serializer can change task validation layout. How do you suggest to update the validation_layout variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. this way should work:

gt_job = gt_job_meta_serializer.save()
instance = gt_job.segment.task
validation_layout = instance.data.validation_layout

I guess we need to follow the approach: serializer changes data and returns actual object -> use them without making requests to refresh data from a database.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but why a GT job meta serializer should be expected to return some deeply nested object in the actual state? I'd understand if it was just the returned value or it's direct member field, but in this case it's 4 levels deep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. you used the same approach when handling GET/PATH /api/tasks/id/validation_layout
image
Probably need to check if there is an example in the django rest framework related to such nested object updates.

Copy link
Contributor Author

@zhiltsov-max zhiltsov-max Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but here it at least mentioned in the serializer name. Actually, the argument can probably be changed to be validation layout.

Copy link
Contributor

@Marishka17 Marishka17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check these 3 comments:
#8776 (comment)
#8776 (comment)
#8776 (comment)
Otherwise LGTM


if not rng:
# Use a known uniform distribution
rng = np.random.Generator(np.random.MT19937())

Check notice

Code scanning / SonarCloud

Results that depend on random number generation should be reproducible Low

Provide a seed for this random generator. See more on SonarQube Cloud
@zhiltsov-max zhiltsov-max merged commit 289ad43 into develop Dec 12, 2024
35 checks passed
@zhiltsov-max zhiltsov-max deleted the zm/update-honeypot-selection branch December 12, 2024 17:25
@cvat-bot cvat-bot bot mentioned this pull request Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants