Skip to content

fix: 168 bug device placement does not work with torchmetric#169

Merged
begumcig merged 4 commits intomainfrom
fix/168-bug-device-placement-does-not-work-with-torchmetric
Jun 11, 2025
Merged

fix: 168 bug device placement does not work with torchmetric#169
begumcig merged 4 commits intomainfrom
fix/168-bug-device-placement-does-not-work-with-torchmetric

Conversation

@davidberenstein1957
Copy link
Copy Markdown
Member

Description

There was a tiny error with pro-active device assignment in case of TorchMetric classes.

Related Issue

Fixes #168

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

@davidberenstein1957 davidberenstein1957 linked an issue Jun 3, 2025 that may be closed by this pull request
@davidberenstein1957 davidberenstein1957 marked this pull request as ready for review June 3, 2025 17:47
Copy link
Copy Markdown
Member

@begumcig begumcig left a comment

Choose a reason for hiding this comment

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

Thank you so much for fixing this super fast!! Suggested a change to possibly make the device casting more agnostic for all torchmetrics, looks really good overall! Love the Task test!

Copy link
Copy Markdown
Member

@begumcig begumcig left a comment

Choose a reason for hiding this comment

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

One tiny change on filtering :) Almost there!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also add a check for if the function has *args with VAR_POSITIONAL for when we need to pass positional arguments?

@johnrachwan123 johnrachwan123 removed their request for review June 11, 2025 13:01
@begumcig begumcig force-pushed the fix/168-bug-device-placement-does-not-work-with-torchmetric branch from 5ea8388 to 276dbf0 Compare June 11, 2025 16:07
- Removed unnecessary device parameter popping in TorchMetricWrapper for clip_score.
- Enhanced device assignment logic in TorchMetricWrapper for perplexity metric.
- Updated MetricRegistry to handle TorchMetricWrapper correctly, ensuring proper metric instantiation with device compatibility.
- Introduced a new test file `test_task.py` to validate the initialization of metrics in the Task class.
- Implemented a fixture to mock TorchMetrics for accuracy, precision, and recall during testing.
- Utilized parameterized tests to ensure comprehensive coverage of metric names from the MetricRegistry.
- Improved device assignment logic in TorchMetricWrapper by ensuring that the metric is moved to the specified device only if it supports the operation, preventing potential errors.
- Streamlined the initialization process for metrics, enhancing compatibility across different metric types.
- Updated the filter_load_kwargs function to only filter keyword arguments if the target function does not accept arbitrary keyword arguments, improving its efficiency and clarity.
- Added comprehensive unit tests for filter_load_kwargs to validate its behavior with various function signatures and keyword argument scenarios, ensuring robust functionality.
@begumcig begumcig force-pushed the fix/168-bug-device-placement-does-not-work-with-torchmetric branch from 276dbf0 to adad05c Compare June 11, 2025 16:15
@begumcig begumcig merged commit 8fbd425 into main Jun 11, 2025
6 checks passed
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.

[BUG] device placement does not work with TorchMetric

3 participants