Repository navigation
Conversation
…en max_depth != 1 Signed-off-by: Parth Vadera <parthvadera@gmail.com>
deep1blue
requested review from
ethanwharris,
justusschock and
tchaton
as code owners
October 22, 2026 23:44
This branch has not been deployed
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.
What does this PR do?
When
ModelSummary(orDeepSpeedSummary, which inheritstotal_layer_params) is initialized withmax_depth > 1ormax_depth == -1,self._layer_summarycontains both top-level child modules (e.g.net) and their nested submodules (e.g.net.0,net.1).Because each
LayerSummary.num_parameterscallsself._module.parameters()recursively, a parent module'snum_parametersalready includes all parameters of its nested submodules. Summingself.param_numsacross all entries inself._layer_summaryinModelSummary.total_layer_paramstherefore double/triple-counts nested submodule parameters whenevermax_depth > 1ormax_depth == -1. As a consequence:summary.total_layer_paramsexceedssummary.total_parameterson any nested model withmax_depth != 1._get_summary_data(),total_leftover_params = self.total_parameters - self.total_layer_paramsbecomes<= 0, silently dropping the"other params"(LEFTOVER_PARAMS_NAME) row for directnn.Parameterattributes on theLightningModulewhenevermax_depth > 1ormax_depth == -1.Changes
ModelSummary.total_layer_paramsby summinglayer.num_parametersonly across top-level child modules ("." not in name) inself._layer_summary.test_summary_data_with_non_layer_paramsintests/tests_pytorch/utilities/test_model_summary.pyovermax_depthin[-1, 1, 2]with a nested submodule (nn.Sequential(nn.Linear(2, 2))) to verify thattotal_layer_paramsand the"other params"row remain accurate at all depths.Acknowledgments
Credit to @awaelchli, @Borda, @carmocca, @SkafteNicki, and @GdoongMathew for their work on
ModelSummaryandDeepSpeedSummary.