Skip to content

fix(models): respect enable_model_summary in fit - #486

Merged
mkumar73 merged 3 commits into
mainfrom
fix/model-summary-flag
Nov 28, 2026
Merged

mkumar73 merged 3 commits into
mainfrom
fix/model-summary-flag

Conversation

@ChrisW09

@ChrisW09 ChrisW09 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #485

Problem

fit(..., enable_model_summary=False) did not disable the model summary, for regressors, classifiers and LSS models alike. Passing a custom ModelSummary through callbacks= gave the trainer two summary callbacks, and two tables were printed.

Root cause

Both _FitMixin.fit and SklearnBaseLSS.fit built callbacks=[early_stop, checkpoint, ModelSummary(max_depth=2), *user_callbacks] unconditionally. Lightning's enable_model_summary only controls whether Lightning adds its default summary callback, so an explicitly added callback always runs.

Fix

A new helper _build_trainer_callbacks in deeptab/models/_mixins/fit.py merges the built-in callbacks with the caller's callbacks=. It accepts a list or a single Callback, as before. The built-in ModelSummary(max_depth=2) is added only when enable_model_summary is not falsy and the caller did not pass a summary callback of their own (ModelSummary, which includes RichModelSummary).

Both fit paths use the helper, so the LSS path, which duplicated the same callback-merging code, now shares it. Default behaviour is unchanged: without the flag and without a user summary, the same ModelSummary(max_depth=2) is added.

Tests

New TestModelSummaryFollowsTrainerFlag in tests/integration/test_fit_lifecycle.py, run for MLPRegressor and MLPLSS:

  • by default exactly one summary callback with max_depth=2 is present, and the summary table is logged;
  • enable_model_summary=False leaves no summary callback and logs no summary table;
  • a user ModelSummary(max_depth=1) replaces the built-in one.

The table is checked with a handler on Lightning's lightning.pytorch.callbacks.model_summary logger, which prints it; that logger doesn't propagate to captured stdout. The 4 new flag and override cases fail on main; all 11 tests in the file pass with this change.

Docs

No docs change is needed. The docs already pass enable_model_summary=False as a Lightning passthrough, and it now behaves as documented. The helper has a docstring.

Checks

  • just test: 3242 passed, 46 skipped, 28 xfailed; coverage 91.31%
  • just docs: build succeeded (warnings treated as errors)
  • just check: all hooks passed (ruff, prettier, pyright)

fit() always added ModelSummary(max_depth=2) to the trainer callbacks,
but Lightning's enable_model_summary flag only suppresses Lightning's
own default summary, so the flag had no effect and a user-supplied
summary callback printed a second table. Build the callback list in one
helper shared by the base and LSS fit: the built-in summary is skipped
when enable_model_summary is False or the caller passes a ModelSummary.

Fixes #485
ChrisW09 added a commit that referenced this pull request Oct 21, 2026
Keeps them apart from the callback tests appended to test_fit_lifecycle.py by #486.

Refs #541
ChrisW09 and others added 2 commits October 21, 2026 23:47
Lightning logs the table through the lightning.pytorch.callbacks
.model_summary logger, which does not propagate to captured stdout, so
the capsys assertion could never fail. The default case now also
checks that the handler sees the table.

Refs #485
@mkumar73
mkumar73 merged commit a9ec111 into main Nov 28, 2026
35 checks passed
@mkumar73
mkumar73 deleted the fix/model-summary-flag branch November 28, 2026 18:09
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] fit(enable_model_summary=False) is ignored because a ModelSummary callback is always added

2 participants