-
-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1143,7 +1143,16 @@ def test_tta_regression( | |||||
|
|
||||||
|
|
||||||
| def _run_model_compare( | ||||||
| task, model_list, data_config, trainer_config, optimizer_config, train, test, metric, rank_metric | ||||||
| task, | ||||||
| model_list, | ||||||
| data_config, | ||||||
| trainer_config, | ||||||
| optimizer_config, | ||||||
| train, | ||||||
| test, | ||||||
| metric, | ||||||
| rank_metric, | ||||||
| custom_fit_params={}, | ||||||
| ): | ||||||
| model_list = copy.deepcopy(model_list) | ||||||
| if isinstance(model_list, list): | ||||||
|
|
@@ -1161,6 +1170,7 @@ def _run_model_compare( | |||||
| metrics_params=metric[1], | ||||||
| metrics_prob_input=metric[2], | ||||||
| rank_metric=rank_metric, | ||||||
| custom_fit_params=custom_fit_params, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -1249,6 +1259,66 @@ def test_model_compare_regression(regression_data, model_list, continuous_cols, | |||||
| # assert best_model.model._get_name() in best_models | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.parametrize("model_list", ["lite", MODEL_CONFIG_MODEL_SWEEP_TEST]) | ||||||
| @pytest.mark.parametrize("continuous_cols", [list(DATASET_CONTINUOUS_COLUMNS)]) | ||||||
| @pytest.mark.parametrize("categorical_cols", [["HouseAgeBin"]]) | ||||||
| @pytest.mark.parametrize( | ||||||
| "metric", | ||||||
| [ | ||||||
| (["mean_squared_error"], [{}], [False]), | ||||||
| ], | ||||||
| ) | ||||||
| @pytest.mark.parametrize("rank_metric", [("loss", "lower_is_better")]) | ||||||
| @pytest.mark.parametrize( | ||||||
| "custom_fit_params", | ||||||
| [ | ||||||
| { | ||||||
| "loss": torch.nn.L1Loss(), | ||||||
| "metrics": [fake_metric], | ||||||
| "metrics_prob_inputs": [True], | ||||||
| "optimizer": torch.optim.Adagrad, | ||||||
| }, | ||||||
| ], | ||||||
| ) | ||||||
| def test_model_compare_custom( | ||||||
| regression_data, model_list, continuous_cols, categorical_cols, metric, rank_metric, custom_fit_params | ||||||
| ): | ||||||
| (train, test, target) = regression_data | ||||||
| data_config = DataConfig( | ||||||
| target=target, | ||||||
| continuous_cols=continuous_cols, | ||||||
| categorical_cols=categorical_cols, | ||||||
| handle_missing_values=True, | ||||||
| handle_unknown_categories=True, | ||||||
| ) | ||||||
| trainer_config = TrainerConfig( | ||||||
| max_epochs=3, | ||||||
| checkpoints=None, | ||||||
| early_stopping=None, | ||||||
| accelerator="cpu", | ||||||
| fast_dev_run=True, | ||||||
| ) | ||||||
| optimizer_config = OptimizerConfig() | ||||||
| comp_df, best_model = _run_model_compare( | ||||||
| "regression", | ||||||
| model_list, | ||||||
| data_config, | ||||||
| trainer_config, | ||||||
| optimizer_config, | ||||||
| train, | ||||||
| test, | ||||||
| metric, | ||||||
| rank_metric, | ||||||
| custom_fit_params=custom_fit_params, | ||||||
| ) | ||||||
| if model_list == "lite": | ||||||
| assert len(comp_df) == 3 | ||||||
| else: | ||||||
| assert len(comp_df) == len(model_list) | ||||||
| if custom_fit_params.get("metric", None) == fake_metric: | ||||||
|
||||||
| if custom_fit_params.get("metric", None) == fake_metric: | |
| if fake_metric in custom_fit_params.get("metrics", []): |
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 |
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".