Skip to content

[BUG] TrainerConfig.optimizer_kwargs are silently dropped #415

Description

@ChrisW09

Describe the bug
TrainerConfig.optimizer_kwargs — documented as "Extra keyword arguments forwarded to the optimizer constructor" — is silently discarded.

_FitMixin.fit passes it into TaskModel(optimizer_args=...) (deeptab/models/_mixins/fit.py:216), and TaskModel.__init__ routes it through normalize_optimizer_kwargs (deeptab/training/lightning_module.py:230), which keeps only keys prefixed optimizer_ (deeptab/training/optimizers.py:309-313):

return {key.removeprefix("optimizer_"): value
        for key, value in optimizer_args.items() if key.startswith("optimizer_")}

Modern, unprefixed kwargs like {"eps": 1e-1, "betas": (0.5, 0.6)} are all filtered out. No warning, no error — the optimizer trains with torch defaults.

To Reproduce

import numpy as np, pandas as pd
from deeptab.configs import TrainerConfig
from deeptab.models import MLPRegressor

X = pd.DataFrame({"a": np.random.randn(80)}); y = np.random.randn(80)
m = MLPRegressor(trainer_config=TrainerConfig(
    optimizer_type="AdamW", optimizer_kwargs={"eps": 1e-1, "betas": (0.5, 0.6)}))
m.fit(X, y, max_epochs=1, accelerator="cpu")
opt = m._task_model.trainer.optimizers[0]
print(opt.param_groups[0]["eps"], opt.param_groups[0]["betas"])
# 1e-08 (0.9, 0.999)  -- user kwargs silently dropped

Expected behavior
optimizer_kwargs entries should reach the optimizer constructor (the prefix-stripping filter should apply only to the legacy prefixed style, or accept both).

Screenshots
n/a

Desktop (please complete the following information):

  • OS: macOS (Darwin 25.5.0, arm64)
  • Python version: 3.11.15
  • deeptab Version: 2.0.0 (main @ 4e6a359)

Additional context
Related in the same file: the regression branch of TaskModel.__init__ unconditionally overwrites a user-supplied loss_fct with nn.MSELoss() (lightning_module.py:242-243), unlike the binary/multiclass branches which respect a custom loss — the docstring says "Custom loss function overriding the automatic selection".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions