Repository navigation
fix(models): respect enable_model_summary in fit - #486
Merged
Merged
Conversation
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
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
approved these changes
Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #485
Problem
fit(..., enable_model_summary=False)did not disable the model summary, for regressors, classifiers and LSS models alike. Passing a customModelSummarythroughcallbacks=gave the trainer two summary callbacks, and two tables were printed.Root cause
Both
_FitMixin.fitandSklearnBaseLSS.fitbuiltcallbacks=[early_stop, checkpoint, ModelSummary(max_depth=2), *user_callbacks]unconditionally. Lightning'senable_model_summaryonly controls whether Lightning adds its default summary callback, so an explicitly added callback always runs.Fix
A new helper
_build_trainer_callbacksindeeptab/models/_mixins/fit.pymerges the built-in callbacks with the caller'scallbacks=. It accepts a list or a singleCallback, as before. The built-inModelSummary(max_depth=2)is added only whenenable_model_summaryis not falsy and the caller did not pass a summary callback of their own (ModelSummary, which includesRichModelSummary).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
TestModelSummaryFollowsTrainerFlagintests/integration/test_fit_lifecycle.py, run forMLPRegressorandMLPLSS:max_depth=2is present, and the summary table is logged;enable_model_summary=Falseleaves no summary callback and logs no summary table;ModelSummary(max_depth=1)replaces the built-in one.The table is checked with a handler on Lightning's
lightning.pytorch.callbacks.model_summarylogger, which prints it; that logger doesn't propagate to captured stdout. The 4 new flag and override cases fail onmain; all 11 tests in the file pass with this change.Docs
No docs change is needed. The docs already pass
enable_model_summary=Falseas 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)