-
-
Notifications
You must be signed in to change notification settings - Fork 161
add custom loss, optim, metrics for model_sweep #587
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
base: main
Are you sure you want to change the base?
add custom loss, optim, metrics for model_sweep #587
Conversation
for more information, see https://pre-commit.ci
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.
Pull Request Overview
This PR adds support for custom loss functions, metrics, and optimizers to the model_sweep function, making it consistent with the TabularModel.fit() API.
Key Changes
- Added
custom_fit_paramsparameter tomodel_sweepfunction that accepts custom loss, metrics, and optimizer specifications - Updated validation logic to ensure rank_metric is "loss" when custom metrics are provided
- Enhanced test coverage with a new test case (
test_model_compare_custom) demonstrating custom fit parameters
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/pytorch_tabular/tabular_model_sweep.py |
Added custom_fit_params parameter to model_sweep and _validate_args, with validation logic and documentation; unpacks params when calling prepare_model |
tests/test_common.py |
Updated _run_model_compare to accept and forward custom_fit_params; added new test case with custom loss, metrics, and optimizer |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| suppress_lightning_logger (bool, optional): If True, will suppress the lightning logger. Defaults to True. | ||
| custom_fit_params (dict, optional): A dict specifying custom loss, metrics and optimizer. | ||
| The behviour of these custom parameters is similar to those passed through the `fit` method |
Copilot
AI
Nov 13, 2025
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.
Typo in documentation: "behviour" should be "behaviour".
| The behviour of these custom parameters is similar to those passed through the `fit` method | |
| The behaviour of these custom parameters is similar to those passed through the `fit` method |
| assert len(comp_df) == 3 | ||
| else: | ||
| assert len(comp_df) == len(model_list) | ||
| if custom_fit_params.get("metric", None) == fake_metric: |
Copilot
AI
Nov 13, 2025
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.
Bug in test assertion: should check "metrics" (plural) instead of "metric" (singular). The custom_fit_params dictionary uses the key "metrics" (line 1277), so this condition will never be true, making this assertion ineffective.
| if custom_fit_params.get("metric", None) == fake_metric: | |
| if fake_metric in custom_fit_params.get("metrics", []): |
| else: | ||
| assert len(comp_df) == len(model_list) | ||
| if custom_fit_params.get("metric", None) == fake_metric: | ||
| assert "test_fake_metric" in comp_df.columns() |
Copilot
AI
Nov 13, 2025
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.
Bug: columns() is being called as a method, but pandas DataFrame's columns is a property, not a method. This should be comp_df.columns instead of comp_df.columns().
| assert "test_fake_metric" in comp_df.columns() | |
| assert "test_fake_metric" in comp_df.columns |
Add support for custom loss and metrics in
model_sweepFixes #544
model_sweepin the same way astabular_model.fit()throughcustom_fit_params.custom_fit_paramsexpects a dictionary specifying the custom loss, metrics, or optimizer.Example usage
📚 Documentation preview 📚: https://pytorch-tabular--587.org.readthedocs.build/en/587/