Skip to content

MLPRegression: hyperparameters suggested by the optimizer never reach training #842

Description

@Maarmapa

MLPRegression.__init__ stores its whole configuration in a dict:

# DashAI/back/models/scikit_learn/mlp_regression.py:400
self.params = kwargs

and train() reads every hyperparameter back out of that dict:

# same file, lines 452-463
hidden_size=self.params.get("hidden_size", 100),
activation_name=self.params.get("activation", "relu"),
optimizer = torch.optim.Adam(self.model.parameters(), lr=self.params.get("learning_rate", 0.001))
total_epochs = self.params.get("epochs", 3)

But the optimizer applies suggested values as instance attributes:

# DashAI/back/optimizers/optuna_optimizer.py:277
setattr(obj, key, value)

self.params never sees them, so during HPO every trial trains an identical
model and the study optimizes noise. setattr never fails, so nothing
surfaces it.

Verified by execution on develop @ b3b7296: after
setattr(mdl, "learning_rate", 0.9), the instance attribute is 0.9 while
self.params["learning_rate"] is still 0.001 — and train() reads the
latter. The same applies to optuna_optimizer.py:315, where the winning
parameters are written back after the study.

This is the only model in the repo with this pattern. Its siblings assign to
instance attributes and read them directly — mlp_image_classifier.py:430-431
sets self.epochs / self.learning_rate and train() reads self.epochs at
line 541, so setattr reaches training as intended.

A related detail found on the way: train() falls back to
hidden_size=100 (line 452) while load() rebuilds the network with
hidden_size=5. A checkpoint saved without that key cannot be loaded back —
the state dict shapes will not match.

Suggested fix: read hyperparameters from instance attributes like the
sibling models do, or mirror kwargs onto attributes in __init__ so both
access paths agree. Happy to send a PR with tests either way — just say which
shape you prefer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions